CMakeTestCXXCompiler.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # This file is used by EnableLanguage in cmGlobalGenerator to
  2. # determine that that selected C++ compiler can actually compile
  3. # and link the most basic of programs. If not, a fatal error
  4. # is set and cmake stops processing commands and will not generate
  5. # any makefiles or projects.
  6. IF(NOT CMAKE_CXX_COMPILER_WORKS)
  7. MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER}")
  8. FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
  9. "#ifndef __cplusplus\n"
  10. "# error \"The CMAKE_CXX_COMPILER is set to a C compiler\"\n"
  11. "#endif\n"
  12. "int main(){return 0;}\n")
  13. TRY_COMPILE(CMAKE_CXX_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  14. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
  15. OUTPUT_VARIABLE OUTPUT)
  16. SET(CXX_TEST_WAS_RUN 1)
  17. ENDIF(NOT CMAKE_CXX_COMPILER_WORKS)
  18. IF(NOT CMAKE_CXX_COMPILER_WORKS)
  19. MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} -- broken")
  20. # if the compiler is broken make sure to remove the platform file
  21. # since Windows-cl configures both c/cxx files both need to be removed
  22. # when c or c++ fails
  23. FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake )
  24. FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake )
  25. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  26. "Determining if the CXX compiler works failed with "
  27. "the following output:\n${OUTPUT}\n\n")
  28. MESSAGE(FATAL_ERROR "The C++ compiler \"${CMAKE_CXX_COMPILER}\" "
  29. "is not able to compile a simple test program.\nIt fails "
  30. "with the following output:\n ${OUTPUT}\n\n"
  31. "CMake will not be able to correctly generate this project.")
  32. ELSE(NOT CMAKE_CXX_COMPILER_WORKS)
  33. IF(CXX_TEST_WAS_RUN)
  34. MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} -- works")
  35. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  36. "Determining if the CXX compiler works passed with "
  37. "the following output:\n${OUTPUT}\n\n")
  38. ENDIF(CXX_TEST_WAS_RUN)
  39. SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
  40. IF(CMAKE_CXX_COMPILER_FORCED)
  41. # The compiler configuration was forced by the user.
  42. # Assume the user has configured all compiler information.
  43. ELSE(CMAKE_CXX_COMPILER_FORCED)
  44. # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
  45. INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  46. CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
  47. CONFIGURE_FILE(
  48. ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
  49. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXCompiler.cmake
  50. @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
  51. )
  52. ENDIF(CMAKE_CXX_COMPILER_FORCED)
  53. ENDIF(NOT CMAKE_CXX_COMPILER_WORKS)