1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 if(CMAKE_OBJC_COMPILER_FORCED)
6 # The compiler configuration was forced by the user.
7 # Assume the user has configured all compiler information.
8 set(CMAKE_OBJC_COMPILER_WORKS TRUE)
12 include(CMakeTestCompilerCommon)
14 # work around enforced code signing and / or missing executable target type
15 set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
16 if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE)
17 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE})
20 # Remove any cached result from an older CMake version.
21 # We now store this in CMakeCCompiler.cmake.
22 unset(CMAKE_OBJC_COMPILER_WORKS CACHE)
24 # Try to identify the ABI and configure it into CMakeOBJCCompiler.cmake
25 include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
26 CMAKE_DETERMINE_COMPILER_ABI(OBJC ${CMAKE_ROOT}/Modules/CMakeOBJCCompilerABI.m)
27 if(CMAKE_OBJC_ABI_COMPILED)
28 # The compiler worked so skip dedicated test below.
29 set(CMAKE_OBJC_COMPILER_WORKS TRUE)
30 message(STATUS "Check for working OBJC compiler: ${CMAKE_OBJC_COMPILER} - skipped")
33 # This file is used by EnableLanguage in cmGlobalGenerator to
34 # determine that that selected Objective-C compiler can actually compile
35 # and link the most basic of programs. If not, a fatal error
36 # is set and cmake stops processing commands and will not generate
37 # any makefiles or projects.
38 if(NOT CMAKE_OBJC_COMPILER_WORKS)
39 PrintTestCompilerStatus("OBJC")
40 __TestCompiler_setTryCompileTargetType()
41 string(CONCAT __TestCompiler_testObjCCompilerSource
42 "#ifdef __cplusplus\n"
43 "# error \"The CMAKE_OBJC_COMPILER is set to a C++ compiler\"\n"
46 "# error \"The CMAKE_OBJC_COMPILER is not an Objective-C compiler\"\n"
48 "int main(int argc, char* argv[])\n"
49 "{ (void)argv; return argc-1;}\n")
50 # Clear result from normal variable.
51 unset(CMAKE_OBJC_COMPILER_WORKS)
52 # Puts test result in cache variable.
53 try_compile(CMAKE_OBJC_COMPILER_WORKS
54 SOURCE_FROM_VAR testObjCCompiler.m __TestCompiler_testObjCCompilerSource
55 OUTPUT_VARIABLE __CMAKE_OBJC_COMPILER_OUTPUT)
56 unset(__TestCompiler_testObjCCompilerSource)
57 # Move result from cache to normal variable.
58 set(CMAKE_OBJC_COMPILER_WORKS ${CMAKE_OBJC_COMPILER_WORKS})
59 unset(CMAKE_OBJC_COMPILER_WORKS CACHE)
60 __TestCompiler_restoreTryCompileTargetType()
61 if(NOT CMAKE_OBJC_COMPILER_WORKS)
62 PrintTestCompilerResult(CHECK_FAIL "broken")
63 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
64 "Determining if the Objective-C compiler works failed with "
65 "the following output:\n${__CMAKE_OBJC_COMPILER_OUTPUT}\n\n")
66 string(REPLACE "\n" "\n " _output "${__CMAKE_OBJC_COMPILER_OUTPUT}")
67 message(FATAL_ERROR "The Objective-C compiler\n \"${CMAKE_OBJC_COMPILER}\"\n"
68 "is not able to compile a simple test program.\nIt fails "
69 "with the following output:\n ${_output}\n\n"
70 "CMake will not be able to correctly generate this project.")
72 PrintTestCompilerResult(CHECK_PASS "works")
73 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
74 "Determining if the Objective-C compiler works passed with "
75 "the following output:\n${__CMAKE_OBJC_COMPILER_OUTPUT}\n\n")
78 # Try to identify the compiler features
79 include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
80 CMAKE_DETERMINE_COMPILE_FEATURES(OBJC)
82 # Re-configure to save learned information.
84 ${CMAKE_ROOT}/Modules/CMakeOBJCCompiler.cmake.in
85 ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake
88 include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake)
90 if(CMAKE_OBJC_SIZEOF_DATA_PTR)
91 foreach(f ${CMAKE_OBJC_ABI_FILES})
94 unset(CMAKE_OBJC_ABI_FILES)
97 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
98 unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
99 unset(__CMAKE_OBJC_COMPILER_OUTPUT)