1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4 5if(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) 9 return() 10endif() 11 12include(CMakeTestCompilerCommon) 13 14# work around enforced code signing and / or missing executable target type 15set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) 16if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE) 17 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE}) 18endif() 19 20# Remove any cached result from an older CMake version. 21# We now store this in CMakeCCompiler.cmake. 22unset(CMAKE_OBJC_COMPILER_WORKS CACHE) 23 24# Try to identify the ABI and configure it into CMakeOBJCCompiler.cmake 25include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) 26CMAKE_DETERMINE_COMPILER_ABI(OBJC ${CMAKE_ROOT}/Modules/CMakeOBJCCompilerABI.m) 27if(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") 31endif() 32 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. 38if(NOT CMAKE_OBJC_COMPILER_WORKS) 39 PrintTestCompilerStatus("OBJC") 40 __TestCompiler_setTryCompileTargetType() 41 file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testOBJCCompiler.m 42 "#ifdef __cplusplus\n" 43 "# error \"The CMAKE_OBJC_COMPILER is set to a C++ compiler\"\n" 44 "#endif\n" 45 "#ifndef __OBJC__\n" 46 "# error \"The CMAKE_OBJC_COMPILER is not an Objective-C compiler\"\n" 47 "#endif\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 ${CMAKE_BINARY_DIR} 54 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testOBJCCompiler.m 55 OUTPUT_VARIABLE __CMAKE_OBJC_COMPILER_OUTPUT) 56 # Move result from cache to normal variable. 57 set(CMAKE_OBJC_COMPILER_WORKS ${CMAKE_OBJC_COMPILER_WORKS}) 58 unset(CMAKE_OBJC_COMPILER_WORKS CACHE) 59 __TestCompiler_restoreTryCompileTargetType() 60 if(NOT CMAKE_OBJC_COMPILER_WORKS) 61 PrintTestCompilerResult(CHECK_FAIL "broken") 62 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 63 "Determining if the Objective-C compiler works failed with " 64 "the following output:\n${__CMAKE_OBJC_COMPILER_OUTPUT}\n\n") 65 string(REPLACE "\n" "\n " _output "${__CMAKE_OBJC_COMPILER_OUTPUT}") 66 message(FATAL_ERROR "The Objective-C compiler\n \"${CMAKE_OBJC_COMPILER}\"\n" 67 "is not able to compile a simple test program.\nIt fails " 68 "with the following output:\n ${_output}\n\n" 69 "CMake will not be able to correctly generate this project.") 70 endif() 71 PrintTestCompilerResult(CHECK_PASS "works") 72 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 73 "Determining if the Objective-C compiler works passed with " 74 "the following output:\n${__CMAKE_OBJC_COMPILER_OUTPUT}\n\n") 75endif() 76 77# Try to identify the compiler features 78include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) 79CMAKE_DETERMINE_COMPILE_FEATURES(OBJC) 80 81# Re-configure to save learned information. 82configure_file( 83 ${CMAKE_ROOT}/Modules/CMakeOBJCCompiler.cmake.in 84 ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake 85 @ONLY 86 ) 87include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCCompiler.cmake) 88 89if(CMAKE_OBJC_SIZEOF_DATA_PTR) 90 foreach(f ${CMAKE_OBJC_ABI_FILES}) 91 include(${f}) 92 endforeach() 93 unset(CMAKE_OBJC_ABI_FILES) 94endif() 95 96set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE}) 97unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE) 98unset(__CMAKE_OBJC_COMPILER_OUTPUT) 99