CMakeTestCCompiler.cmake 2.2 KB

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