CMakeTestCXXCompiler.cmake 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #=============================================================================
  2. # Copyright 2003-2009 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. include(CMakeTestCompilerCommon)
  14. # This file is used by EnableLanguage in cmGlobalGenerator to
  15. # determine that that selected C++ compiler can actually compile
  16. # and link the most basic of programs. If not, a fatal error
  17. # is set and cmake stops processing commands and will not generate
  18. # any makefiles or projects.
  19. if(NOT CMAKE_CXX_COMPILER_WORKS)
  20. PrintTestCompilerStatus("CXX" "")
  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. set(CXX_TEST_WAS_RUN 1)
  30. endif()
  31. if(NOT CMAKE_CXX_COMPILER_WORKS)
  32. PrintTestCompilerStatus("CXX" " -- broken")
  33. # if the compiler is broken make sure to remove the platform file
  34. # since Windows-cl configures both c/cxx files both need to be removed
  35. # when c or c++ fails
  36. file(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake )
  37. file(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake )
  38. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  39. "Determining if the CXX compiler works failed with "
  40. "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
  41. message(FATAL_ERROR "The C++ compiler \"${CMAKE_CXX_COMPILER}\" "
  42. "is not able to compile a simple test program.\nIt fails "
  43. "with the following output:\n ${__CMAKE_CXX_COMPILER_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. set(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
  53. if(CMAKE_CXX_COMPILER_FORCED)
  54. # The compiler configuration was forced by the user.
  55. # Assume the user has configured all compiler information.
  56. else()
  57. # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
  58. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  59. CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
  60. configure_file(
  61. ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
  62. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXCompiler.cmake
  63. @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
  64. )
  65. include(${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXCompiler.cmake)
  66. endif()
  67. if(CMAKE_CXX_SIZEOF_DATA_PTR)
  68. foreach(f ${CMAKE_CXX_ABI_FILES})
  69. include(${f})
  70. endforeach()
  71. unset(CMAKE_CXX_ABI_FILES)
  72. endif()
  73. endif()
  74. unset(__CMAKE_CXX_COMPILER_OUTPUT)