CMakeTestCXXCompiler.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 OUTPUT)
  29. SET(CXX_TEST_WAS_RUN 1)
  30. ENDIF(NOT CMAKE_CXX_COMPILER_WORKS)
  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${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 ${OUTPUT}\n\n"
  44. "CMake will not be able to correctly generate this project.")
  45. ELSE(NOT CMAKE_CXX_COMPILER_WORKS)
  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${OUTPUT}\n\n")
  51. ENDIF(CXX_TEST_WAS_RUN)
  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(CMAKE_CXX_COMPILER_FORCED)
  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(CMAKE_CXX_COMPILER_FORCED)
  67. ENDIF(NOT CMAKE_CXX_COMPILER_WORKS)