CMakeTestCCompiler.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. "#include <stdio.h>\n"
  13. "#if defined(__CLASSIC_C__)\n"
  14. "int main(argc, argv)\n"
  15. " int argc;\n"
  16. " char* argv[];\n"
  17. "#else\n"
  18. "int main(int argc, char* argv[])\n"
  19. "#endif\n"
  20. "{ printf(\"%s\\n\", argv[0]); return argc-1;}\n")
  21. TRY_COMPILE(CMAKE_C_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  22. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler.c
  23. OUTPUT_VARIABLE OUTPUT)
  24. SET(C_TEST_WAS_RUN 1)
  25. ENDIF(NOT CMAKE_C_COMPILER_WORKS)
  26. IF(NOT CMAKE_C_COMPILER_WORKS)
  27. MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} -- broken")
  28. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  29. "Determining if the C compiler works failed with "
  30. "the following output:\n${OUTPUT}\n\n")
  31. MESSAGE(FATAL_ERROR "The C compiler \"${CMAKE_C_COMPILER}\" "
  32. "is not able to compile a simple test program.\nIt fails "
  33. "with the following output:\n ${OUTPUT}\n\n"
  34. "CMake will not be able to correctly generate this project.")
  35. ELSE(NOT CMAKE_C_COMPILER_WORKS)
  36. IF(C_TEST_WAS_RUN)
  37. MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} -- works")
  38. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  39. "Determining if the C compiler works passed with "
  40. "the following output:\n${OUTPUT}\n\n")
  41. ENDIF(C_TEST_WAS_RUN)
  42. INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
  43. # Check the size of void*. This used to be "void *" but icc expands the *.
  44. CHECK_TYPE_SIZE("void*" CMAKE_SIZEOF_VOID_P)
  45. SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
  46. # re-configure this file CMakeCCompiler.cmake so that it gets
  47. # the value for CMAKE_SIZEOF_VOID_P
  48. # configure variables set in this file for fast reload later on
  49. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
  50. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCCompiler.cmake IMMEDIATE)
  51. ENDIF(NOT CMAKE_C_COMPILER_WORKS)