CMakeTestCCompiler.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. "{ 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. MESSAGE(FATAL_ERROR "The C compiler \"${CMAKE_C_COMPILER}\" "
  31. "is not able to compile a simple test program.\nIt fails "
  32. "with the following output:\n ${OUTPUT}\n\n"
  33. "CMake will not be able to correctly generate this project.")
  34. ELSE(NOT CMAKE_C_COMPILER_WORKS)
  35. IF(C_TEST_WAS_RUN)
  36. MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} -- works")
  37. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  38. "Determining if the C compiler works passed with "
  39. "the following output:\n${OUTPUT}\n\n")
  40. ENDIF(C_TEST_WAS_RUN)
  41. INCLUDE (${CMAKE_ROOT}/Modules/CheckTypeSize.cmake)
  42. # Check the size of void*. This used to be "void *" but icc expands the *.
  43. CHECK_TYPE_SIZE("void*" CMAKE_SIZEOF_VOID_P)
  44. SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
  45. # re-configure this file CMakeCCompiler.cmake so that it gets
  46. # the value for CMAKE_SIZEOF_VOID_P
  47. # configure variables set in this file for fast reload later on
  48. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
  49. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCCompiler.cmake IMMEDIATE)
  50. ENDIF(NOT CMAKE_C_COMPILER_WORKS)