CMakeTestCXXCompiler.cmake 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #=============================================================================
  2. # Copyright 2003-2012 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distribute this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. if(CMAKE_CXX_COMPILER_FORCED)
  14. # The compiler configuration was forced by the user.
  15. # Assume the user has configured all compiler information.
  16. set(CMAKE_CXX_COMPILER_WORKS TRUE)
  17. return()
  18. endif()
  19. include(CMakeTestCompilerCommon)
  20. # Remove any cached result from an older CMake version.
  21. # We now store this in CMakeCXXCompiler.cmake.
  22. unset(CMAKE_CXX_COMPILER_WORKS CACHE)
  23. # This file is used by EnableLanguage in cmGlobalGenerator to
  24. # determine that that selected C++ compiler can actually compile
  25. # and link the most basic of programs. If not, a fatal error
  26. # is set and cmake stops processing commands and will not generate
  27. # any makefiles or projects.
  28. if(NOT CMAKE_CXX_COMPILER_WORKS)
  29. PrintTestCompilerStatus("CXX" "")
  30. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
  31. "#ifndef __cplusplus\n"
  32. "# error \"The CMAKE_CXX_COMPILER is set to a C compiler\"\n"
  33. "#endif\n"
  34. "int main(){return 0;}\n")
  35. try_compile(CMAKE_CXX_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  36. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
  37. OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)
  38. # Move result from cache to normal variable.
  39. set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
  40. unset(CMAKE_CXX_COMPILER_WORKS CACHE)
  41. set(CXX_TEST_WAS_RUN 1)
  42. endif()
  43. if(NOT CMAKE_CXX_COMPILER_WORKS)
  44. PrintTestCompilerStatus("CXX" " -- broken")
  45. # if the compiler is broken make sure to remove the platform file
  46. # since Windows-cl configures both c/cxx files both need to be removed
  47. # when c or c++ fails
  48. file(REMOVE ${CMAKE_PLATFORM_INFO_DIR}/CMakeCPlatform.cmake )
  49. file(REMOVE ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXPlatform.cmake )
  50. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  51. "Determining if the CXX compiler works failed with "
  52. "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
  53. message(FATAL_ERROR "The C++ compiler \"${CMAKE_CXX_COMPILER}\" "
  54. "is not able to compile a simple test program.\nIt fails "
  55. "with the following output:\n ${__CMAKE_CXX_COMPILER_OUTPUT}\n\n"
  56. "CMake will not be able to correctly generate this project.")
  57. else()
  58. if(CXX_TEST_WAS_RUN)
  59. PrintTestCompilerStatus("CXX" " -- works")
  60. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  61. "Determining if the CXX compiler works passed with "
  62. "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
  63. endif()
  64. # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
  65. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  66. CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
  67. # Re-configure to save learned information.
  68. configure_file(
  69. ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
  70. ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake
  71. @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
  72. )
  73. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake)
  74. if(CMAKE_CXX_SIZEOF_DATA_PTR)
  75. foreach(f ${CMAKE_CXX_ABI_FILES})
  76. include(${f})
  77. endforeach()
  78. unset(CMAKE_CXX_ABI_FILES)
  79. endif()
  80. endif()
  81. unset(__CMAKE_CXX_COMPILER_OUTPUT)