Merge branch 'release-4.0'
[kiteware-cmake.git] / Modules / CMakeTestOBJCXXCompiler.cmake
blob68b387189a702229bfabf8929faca57b0f8cfef7
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_OBJCXX_COMPILER_FORCED)
6   # The compiler configuration was forced by the user.
7   # Assume the user has configured all compiler information.
8   set(CMAKE_OBJCXX_COMPILER_WORKS TRUE)
9   return()
10 endif()
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})
18 endif()
20 # Remove any cached result from an older CMake version.
21 # We now store this in CMakeOBJCXXCompiler.cmake.
22 unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
24 # Try to identify the ABI and configure it into CMakeOBJCXXCompiler.cmake
25 include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
26 CMAKE_DETERMINE_COMPILER_ABI(OBJCXX ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompilerABI.mm)
27 if(CMAKE_OBJCXX_ABI_COMPILED)
28   # The compiler worked so skip dedicated test below.
29   set(CMAKE_OBJCXX_COMPILER_WORKS TRUE)
30   message(STATUS "Check for working OBJCXX compiler: ${CMAKE_OBJCXX_COMPILER} - skipped")
31 endif()
33 # This file is used by EnableLanguage in cmGlobalGenerator to
34 # determine that the 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_OBJCXX_COMPILER_WORKS)
39   PrintTestCompilerStatus("OBJCXX")
40   __TestCompiler_setTryCompileTargetType()
41   string(CONCAT __TestCompiler_testObjCXXCompilerSource
42     "#ifndef __cplusplus\n"
43     "# error \"The CMAKE_OBJCXX_COMPILER is set to a C compiler\"\n"
44     "#endif\n"
45     "#ifndef __OBJC__\n"
46     "# error \"The CMAKE_OBJCXX_COMPILER is not an Objective-C++ compiler\"\n"
47     "#endif\n"
48     "int main(){return 0;}\n")
49   # Clear result from normal variable.
50   unset(CMAKE_OBJCXX_COMPILER_WORKS)
51   # Puts test result in cache variable.
52   try_compile(CMAKE_OBJCXX_COMPILER_WORKS
53     SOURCE_FROM_VAR testObjCXXCompiler.mm __TestCompiler_testObjCXXCompilerSource
54     OUTPUT_VARIABLE __CMAKE_OBJCXX_COMPILER_OUTPUT)
55   unset(__TestCompiler_testObjCXXCompilerSource)
56   # Move result from cache to normal variable.
57   set(CMAKE_OBJCXX_COMPILER_WORKS ${CMAKE_OBJCXX_COMPILER_WORKS})
58   unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
59   __TestCompiler_restoreTryCompileTargetType()
60   if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
61     PrintTestCompilerResult(CHECK_FAIL "broken")
62     string(REPLACE "\n" "\n  " _output "${__CMAKE_OBJCXX_COMPILER_OUTPUT}")
63     message(FATAL_ERROR "The Objective-C++ compiler\n  \"${CMAKE_OBJCXX_COMPILER}\"\n"
64       "is not able to compile a simple test program.\nIt fails "
65       "with the following output:\n  ${_output}\n\n"
66       "CMake will not be able to correctly generate this project.")
67   endif()
68   PrintTestCompilerResult(CHECK_PASS "works")
69 endif()
71 # Try to identify the compiler features
72 include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerSupport.cmake)
73 CMAKE_DETERMINE_COMPILER_SUPPORT(OBJCXX)
75 # Re-configure to save learned information.
76 configure_file(
77   ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompiler.cmake.in
78   ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake
79   @ONLY
80   )
81 include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake)
83 if(CMAKE_OBJCXX_SIZEOF_DATA_PTR)
84   foreach(f ${CMAKE_OBJCXX_ABI_FILES})
85     include(${f})
86   endforeach()
87   unset(CMAKE_OBJCXX_ABI_FILES)
88 endif()
90 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
91 unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
92 unset(__CMAKE_OBJCXX_COMPILER_OUTPUT)