CMakeTestCXXCompiler.cmake 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_CXX_COMPILER_FORCED)
  4. # The compiler configuration was forced by the user.
  5. # Assume the user has configured all compiler information.
  6. set(CMAKE_CXX_COMPILER_WORKS TRUE)
  7. return()
  8. endif()
  9. include(CMakeTestCompilerCommon)
  10. # Remove any cached result from an older CMake version.
  11. # We now store this in CMakeCXXCompiler.cmake.
  12. unset(CMAKE_CXX_COMPILER_WORKS CACHE)
  13. # This file is used by EnableLanguage in cmGlobalGenerator to
  14. # determine that the selected C++ compiler can actually compile
  15. # and link the most basic of programs. If not, a fatal error
  16. # is set and cmake stops processing commands and will not generate
  17. # any makefiles or projects.
  18. if(NOT CMAKE_CXX_COMPILER_WORKS)
  19. PrintTestCompilerStatus("CXX" "")
  20. __TestCompiler_setTryCompileTargetType()
  21. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
  22. "#ifndef __cplusplus\n"
  23. "# error \"The CMAKE_CXX_COMPILER is set to a C compiler\"\n"
  24. "#endif\n"
  25. "int main(){return 0;}\n")
  26. try_compile(CMAKE_CXX_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  27. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
  28. OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)
  29. # Move result from cache to normal variable.
  30. set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
  31. unset(CMAKE_CXX_COMPILER_WORKS CACHE)
  32. set(CXX_TEST_WAS_RUN 1)
  33. __TestCompiler_restoreTryCompileTargetType()
  34. endif()
  35. if(NOT CMAKE_CXX_COMPILER_WORKS)
  36. PrintTestCompilerStatus("CXX" " -- broken")
  37. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  38. "Determining if the CXX compiler works failed with "
  39. "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
  40. string(REPLACE "\n" "\n " _output "${__CMAKE_CXX_COMPILER_OUTPUT}")
  41. message(FATAL_ERROR "The C++ compiler\n \"${CMAKE_CXX_COMPILER}\"\n"
  42. "is not able to compile a simple test program.\nIt fails "
  43. "with the following output:\n ${_output}\n\n"
  44. "CMake will not be able to correctly generate this project.")
  45. else()
  46. if(CXX_TEST_WAS_RUN)
  47. PrintTestCompilerStatus("CXX" " -- works")
  48. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  49. "Determining if the CXX compiler works passed with "
  50. "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
  51. endif()
  52. # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
  53. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  54. CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
  55. # Try to identify the compiler features
  56. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
  57. CMAKE_DETERMINE_COMPILE_FEATURES(CXX)
  58. # Re-configure to save learned information.
  59. configure_file(
  60. ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
  61. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake
  62. @ONLY
  63. )
  64. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake)
  65. if(CMAKE_CXX_SIZEOF_DATA_PTR)
  66. foreach(f ${CMAKE_CXX_ABI_FILES})
  67. include(${f})
  68. endforeach()
  69. unset(CMAKE_CXX_ABI_FILES)
  70. endif()
  71. endif()
  72. unset(__CMAKE_CXX_COMPILER_OUTPUT)