CMakeTestCXXCompiler.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. string(REPLACE "\n" "\n " _output "${__CMAKE_CXX_COMPILER_OUTPUT}")
  39. message(FATAL_ERROR "The C++ compiler\n \"${CMAKE_CXX_COMPILER}\"\n"
  40. "is not able to compile a simple test program.\nIt fails "
  41. "with the following output:\n ${_output}\n\n"
  42. "CMake will not be able to correctly generate this project.")
  43. else()
  44. if(CXX_TEST_WAS_RUN)
  45. PrintTestCompilerStatus("CXX" " -- works")
  46. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  47. "Determining if the CXX compiler works passed with "
  48. "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
  49. endif()
  50. # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
  51. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  52. CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
  53. # Try to identify the compiler features
  54. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
  55. CMAKE_DETERMINE_COMPILE_FEATURES(CXX)
  56. # Re-configure to save learned information.
  57. configure_file(
  58. ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
  59. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake
  60. @ONLY
  61. )
  62. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake)
  63. if(CMAKE_CXX_SIZEOF_DATA_PTR)
  64. foreach(f ${CMAKE_CXX_ABI_FILES})
  65. include(${f})
  66. endforeach()
  67. unset(CMAKE_CXX_ABI_FILES)
  68. endif()
  69. endif()
  70. unset(__CMAKE_CXX_COMPILER_OUTPUT)