CMakeTestCXXCompiler.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 distributed this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  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. MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER}")
  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 OUTPUT)
  28. SET(CXX_TEST_WAS_RUN 1)
  29. ENDIF(NOT CMAKE_CXX_COMPILER_WORKS)
  30. IF(NOT CMAKE_CXX_COMPILER_WORKS)
  31. MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} -- broken")
  32. # if the compiler is broken make sure to remove the platform file
  33. # since Windows-cl configures both c/cxx files both need to be removed
  34. # when c or c++ fails
  35. FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake )
  36. FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake )
  37. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  38. "Determining if the CXX compiler works failed with "
  39. "the following output:\n${OUTPUT}\n\n")
  40. MESSAGE(FATAL_ERROR "The C++ compiler \"${CMAKE_CXX_COMPILER}\" "
  41. "is not able to compile a simple test program.\nIt fails "
  42. "with the following output:\n ${OUTPUT}\n\n"
  43. "CMake will not be able to correctly generate this project.")
  44. ELSE(NOT CMAKE_CXX_COMPILER_WORKS)
  45. IF(CXX_TEST_WAS_RUN)
  46. MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} -- works")
  47. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  48. "Determining if the CXX compiler works passed with "
  49. "the following output:\n${OUTPUT}\n\n")
  50. ENDIF(CXX_TEST_WAS_RUN)
  51. SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
  52. IF(CMAKE_CXX_COMPILER_FORCED)
  53. # The compiler configuration was forced by the user.
  54. # Assume the user has configured all compiler information.
  55. ELSE(CMAKE_CXX_COMPILER_FORCED)
  56. # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
  57. INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  58. CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
  59. CONFIGURE_FILE(
  60. ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
  61. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXCompiler.cmake
  62. @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
  63. )
  64. ENDIF(CMAKE_CXX_COMPILER_FORCED)
  65. ENDIF(NOT CMAKE_CXX_COMPILER_WORKS)