CMakeTestCCompiler.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_C_COMPILER_WORKS)
  7. MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER}")
  8. FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler.c
  9. "#ifdef __cplusplus\n"
  10. "# error \"The CMAKE_C_COMPILER is set to a C++ compiler\"\n"
  11. "#endif\n"
  12. "#if defined(__CLASSIC_C__)\n"
  13. "int main(argc, argv)\n"
  14. " int argc;\n"
  15. " char* argv[];\n"
  16. "#else\n"
  17. "int main(int argc, char* argv[])\n"
  18. "#endif\n"
  19. "{ (void)argv; return argc-1;}\n")
  20. TRY_COMPILE(CMAKE_C_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  21. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler.c
  22. OUTPUT_VARIABLE OUTPUT)
  23. SET(C_TEST_WAS_RUN 1)
  24. ENDIF(NOT CMAKE_C_COMPILER_WORKS)
  25. IF(NOT CMAKE_C_COMPILER_WORKS)
  26. MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} -- broken")
  27. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  28. "Determining if the C compiler works failed with "
  29. "the following output:\n${OUTPUT}\n\n")
  30. # if the compiler is broken make sure to remove the platform file
  31. # since Windows-cl configures both c/cxx files both need to be removed
  32. # when c or c++ fails
  33. FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake )
  34. FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake )
  35. MESSAGE(FATAL_ERROR "The C compiler \"${CMAKE_C_COMPILER}\" "
  36. "is not able to compile a simple test program.\nIt fails "
  37. "with the following output:\n ${OUTPUT}\n\n"
  38. "CMake will not be able to correctly generate this project.")
  39. ELSE(NOT CMAKE_C_COMPILER_WORKS)
  40. IF(C_TEST_WAS_RUN)
  41. MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} -- works")
  42. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  43. "Determining if the C compiler works passed with "
  44. "the following output:\n${OUTPUT}\n\n")
  45. ENDIF(C_TEST_WAS_RUN)
  46. SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
  47. IF(CMAKE_C_COMPILER_FORCED)
  48. # The compiler configuration was forced by the user.
  49. # Assume the user has configured all compiler information.
  50. ELSE(CMAKE_C_COMPILER_FORCED)
  51. # Try to identify the ABI and configure it into CMakeCCompiler.cmake
  52. INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  53. CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c)
  54. CONFIGURE_FILE(
  55. ${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
  56. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCCompiler.cmake
  57. @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
  58. )
  59. ENDIF(CMAKE_C_COMPILER_FORCED)
  60. ENDIF(NOT CMAKE_C_COMPILER_WORKS)