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_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()
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 CMakeOBJCXXCompiler.cmake.
22unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
23
24# Try to identify the ABI and configure it into CMakeOBJCXXCompiler.cmake
25include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
26CMAKE_DETERMINE_COMPILER_ABI(OBJCXX ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompilerABI.mm)
27if(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")
31endif()
32
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.
38if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
39  PrintTestCompilerStatus("OBJCXX")
40  __TestCompiler_setTryCompileTargetType()
41  file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testOBJCXXCompiler.mm
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 ${CMAKE_BINARY_DIR}
53    ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testOBJCXXCompiler.mm
54    OUTPUT_VARIABLE __CMAKE_OBJCXX_COMPILER_OUTPUT)
55  # Move result from cache to normal variable.
56  set(CMAKE_OBJCXX_COMPILER_WORKS ${CMAKE_OBJCXX_COMPILER_WORKS})
57  unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
58  __TestCompiler_restoreTryCompileTargetType()
59  if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
60    PrintTestCompilerResult(CHECK_FAIL "broken")
61    file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
62      "Determining if the Objective-C++ compiler works failed with "
63      "the following output:\n${__CMAKE_OBJCXX_COMPILER_OUTPUT}\n\n")
64    string(REPLACE "\n" "\n  " _output "${__CMAKE_OBJCXX_COMPILER_OUTPUT}")
65    message(FATAL_ERROR "The Objective-C++ compiler\n  \"${CMAKE_OBJCXX_COMPILER}\"\n"
66      "is not able to compile a simple test program.\nIt fails "
67      "with the following output:\n  ${_output}\n\n"
68      "CMake will not be able to correctly generate this project.")
69  endif()
70  PrintTestCompilerResult(CHECK_PASS "works")
71  file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
72    "Determining if the Objective-C++ compiler works passed with "
73    "the following output:\n${__CMAKE_OBJCXX_COMPILER_OUTPUT}\n\n")
74endif()
75
76# Try to identify the compiler features
77include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
78CMAKE_DETERMINE_COMPILE_FEATURES(OBJCXX)
79
80# Re-configure to save learned information.
81configure_file(
82  ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompiler.cmake.in
83  ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake
84  @ONLY
85  )
86include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake)
87
88if(CMAKE_OBJCXX_SIZEOF_DATA_PTR)
89  foreach(f ${CMAKE_OBJCXX_ABI_FILES})
90    include(${f})
91  endforeach()
92  unset(CMAKE_OBJCXX_ABI_FILES)
93endif()
94
95set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
96unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
97unset(__CMAKE_OBJCXX_COMPILER_OUTPUT)
98