CMakeTestCCompiler.cmake 3.4 KB

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