CMakeTestOBJCXXCompiler.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. if(CMAKE_OBJCXX_COMPILER_FORCED)
  4. # The compiler configuration was forced by the user.
  5. # Assume the user has configured all compiler information.
  6. set(CMAKE_OBJCXX_COMPILER_WORKS TRUE)
  7. return()
  8. endif()
  9. include(CMakeTestCompilerCommon)
  10. # work around enforced code signing and / or missing exectuable target type
  11. set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
  12. if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE)
  13. set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE})
  14. endif()
  15. # Remove any cached result from an older CMake version.
  16. # We now store this in CMakeOBJCXXCompiler.cmake.
  17. unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
  18. # This file is used by EnableLanguage in cmGlobalGenerator to
  19. # determine that the selected Objective-C++ compiler can actually compile
  20. # and link the most basic of programs. If not, a fatal error
  21. # is set and cmake stops processing commands and will not generate
  22. # any makefiles or projects.
  23. if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
  24. PrintTestCompilerStatus("OBJCXX" "")
  25. __TestCompiler_setTryCompileTargetType()
  26. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testOBJCXXCompiler.mm
  27. "#ifndef __cplusplus\n"
  28. "# error \"The CMAKE_OBJCXX_COMPILER is set to a C compiler\"\n"
  29. "#endif\n"
  30. "#ifndef __OBJC__\n"
  31. "# error \"The CMAKE_OBJCXX_COMPILER is not an Objective-C++ compiler\"\n"
  32. "#endif\n"
  33. "int main(){return 0;}\n")
  34. try_compile(CMAKE_OBJCXX_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  35. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testOBJCXXCompiler.mm
  36. OUTPUT_VARIABLE __CMAKE_OBJCXX_COMPILER_OUTPUT)
  37. # Move result from cache to normal variable.
  38. set(CMAKE_OBJCXX_COMPILER_WORKS ${CMAKE_OBJCXX_COMPILER_WORKS})
  39. unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
  40. set(OBJCXX_TEST_WAS_RUN 1)
  41. __TestCompiler_restoreTryCompileTargetType()
  42. endif()
  43. if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
  44. PrintTestCompilerStatus("OBJCXX" " -- broken")
  45. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  46. "Determining if the Objective-C++ compiler works failed with "
  47. "the following output:\n${__CMAKE_OBJCXX_COMPILER_OUTPUT}\n\n")
  48. string(REPLACE "\n" "\n " _output "${__CMAKE_OBJCXX_COMPILER_OUTPUT}")
  49. message(FATAL_ERROR "The Objective-C++ compiler\n \"${CMAKE_OBJCXX_COMPILER}\"\n"
  50. "is not able to compile a simple test program.\nIt fails "
  51. "with the following output:\n ${_output}\n\n"
  52. "CMake will not be able to correctly generate this project.")
  53. else()
  54. if(OBJCXX_TEST_WAS_RUN)
  55. PrintTestCompilerStatus("OBJCXX" " -- works")
  56. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  57. "Determining if the Objective-C++ compiler works passed with "
  58. "the following output:\n${__CMAKE_OBJCXX_COMPILER_OUTPUT}\n\n")
  59. endif()
  60. # Try to identify the ABI and configure it into CMakeOBJCXXCompiler.cmake
  61. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  62. CMAKE_DETERMINE_COMPILER_ABI(OBJCXX ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompilerABI.mm)
  63. # Try to identify the compiler features
  64. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
  65. CMAKE_DETERMINE_COMPILE_FEATURES(OBJCXX)
  66. # Re-configure to save learned information.
  67. configure_file(
  68. ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompiler.cmake.in
  69. ${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake
  70. @ONLY
  71. )
  72. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeOBJCXXCompiler.cmake)
  73. if(CMAKE_OBJCXX_SIZEOF_DATA_PTR)
  74. foreach(f ${CMAKE_OBJCXX_ABI_FILES})
  75. include(${f})
  76. endforeach()
  77. unset(CMAKE_OBJCXX_ABI_FILES)
  78. endif()
  79. endif()
  80. set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
  81. unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
  82. unset(__CMAKE_OBJCXX_COMPILER_OUTPUT)