CMakeTestCCompiler.cmake 3.4 KB

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