CMakeTestCXXCompiler.cmake 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 that 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. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
  21. "#ifndef __cplusplus\n"
  22. "# error \"The CMAKE_CXX_COMPILER is set to a C compiler\"\n"
  23. "#endif\n"
  24. "int main(){return 0;}\n")
  25. try_compile(CMAKE_CXX_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  26. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
  27. OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)
  28. # Move result from cache to normal variable.
  29. set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
  30. unset(CMAKE_CXX_COMPILER_WORKS CACHE)
  31. set(CXX_TEST_WAS_RUN 1)
  32. endif()
  33. if(NOT CMAKE_CXX_COMPILER_WORKS)
  34. PrintTestCompilerStatus("CXX" " -- broken")
  35. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  36. "Determining if the CXX compiler works failed with "
  37. "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
  38. message(FATAL_ERROR "The C++ compiler \"${CMAKE_CXX_COMPILER}\" "
  39. "is not able to compile a simple test program.\nIt fails "
  40. "with the following output:\n ${__CMAKE_CXX_COMPILER_OUTPUT}\n\n"
  41. "CMake will not be able to correctly generate this project.")
  42. else()
  43. if(CXX_TEST_WAS_RUN)
  44. PrintTestCompilerStatus("CXX" " -- works")
  45. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  46. "Determining if the CXX compiler works passed with "
  47. "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
  48. endif()
  49. # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
  50. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  51. CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
  52. # Try to identify the compiler features
  53. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
  54. CMAKE_DETERMINE_COMPILE_FEATURES(CXX)
  55. # Re-configure to save learned information.
  56. configure_file(
  57. ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
  58. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake
  59. @ONLY
  60. )
  61. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake)
  62. if(CMAKE_CXX_SIZEOF_DATA_PTR)
  63. foreach(f ${CMAKE_CXX_ABI_FILES})
  64. include(${f})
  65. endforeach()
  66. unset(CMAKE_CXX_ABI_FILES)
  67. endif()
  68. endif()
  69. unset(__CMAKE_CXX_COMPILER_OUTPUT)