CMakeTestOBJCXXCompiler.cmake 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 executable 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. # Try to identify the ABI and configure it into CMakeOBJCXXCompiler.cmake
  19. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  20. CMAKE_DETERMINE_COMPILER_ABI(OBJCXX ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompilerABI.mm)
  21. if(CMAKE_OBJCXX_ABI_COMPILED)
  22. # The compiler worked so skip dedicated test below.
  23. set(CMAKE_OBJCXX_COMPILER_WORKS TRUE)
  24. message(STATUS "Check for working OBJCXX compiler: ${CMAKE_OBJCXX_COMPILER} - skipped")
  25. endif()
  26. # This file is used by EnableLanguage in cmGlobalGenerator to
  27. # determine that the selected Objective-C++ compiler can actually compile
  28. # and link the most basic of programs. If not, a fatal error
  29. # is set and cmake stops processing commands and will not generate
  30. # any makefiles or projects.
  31. if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
  32. PrintTestCompilerStatus("OBJCXX")
  33. __TestCompiler_setTryCompileTargetType()
  34. string(CONCAT __TestCompiler_testObjCXXCompilerSource
  35. "#ifndef __cplusplus\n"
  36. "# error \"The CMAKE_OBJCXX_COMPILER is set to a C compiler\"\n"
  37. "#endif\n"
  38. "#ifndef __OBJC__\n"
  39. "# error \"The CMAKE_OBJCXX_COMPILER is not an Objective-C++ compiler\"\n"
  40. "#endif\n"
  41. "int main(){return 0;}\n")
  42. # Clear result from normal variable.
  43. unset(CMAKE_OBJCXX_COMPILER_WORKS)
  44. # Puts test result in cache variable.
  45. try_compile(CMAKE_OBJCXX_COMPILER_WORKS
  46. SOURCE_FROM_VAR testObjCXXCompiler.mm __TestCompiler_testObjCXXCompilerSource
  47. OUTPUT_VARIABLE __CMAKE_OBJCXX_COMPILER_OUTPUT)
  48. unset(__TestCompiler_testObjCXXCompilerSource)
  49. # Move result from cache to normal variable.
  50. set(CMAKE_OBJCXX_COMPILER_WORKS ${CMAKE_OBJCXX_COMPILER_WORKS})
  51. unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
  52. __TestCompiler_restoreTryCompileTargetType()
  53. if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
  54. PrintTestCompilerResult(CHECK_FAIL "broken")
  55. string(REPLACE "\n" "\n " _output "${__CMAKE_OBJCXX_COMPILER_OUTPUT}")
  56. message(FATAL_ERROR "The Objective-C++ compiler\n \"${CMAKE_OBJCXX_COMPILER}\"\n"
  57. "is not able to compile a simple test program.\nIt fails "
  58. "with the following output:\n ${_output}\n\n"
  59. "CMake will not be able to correctly generate this project.")
  60. endif()
  61. PrintTestCompilerResult(CHECK_PASS "works")
  62. endif()
  63. # Try to identify the compiler features
  64. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerSupport.cmake)
  65. CMAKE_DETERMINE_COMPILER_SUPPORT(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. set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
  80. unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
  81. unset(__CMAKE_OBJCXX_COMPILER_OUTPUT)