2 # This file is used by EnableLanguage in cmGlobalGenerator to
3 # determine that that selected C compiler can actually compile
4 # and link the most basic of programs. If not, a fatal error
5 # is set and cmake stops processing commands and will not generate
6 # any makefiles or projects.
7 IF(NOT CMAKE_C_COMPILER_WORKS)
8 MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER}")
9 FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCCompiler.c
10 "#ifdef __cplusplus\n"
11 "# error \"The CMAKE_C_COMPILER is set to a C++ compiler\"\n"
13 "#if defined(__CLASSIC_C__)\n"
14 "int main(argc, argv)\n"
18 "int main(int argc, char* argv[])\n"
20 "{ 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)
25 ENDIF(NOT CMAKE_C_COMPILER_WORKS)
27 IF(NOT CMAKE_C_COMPILER_WORKS)
28 MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} -- broken")
29 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
30 "Determining if the C compiler works failed with "
31 "the following output:\n${OUTPUT}\n\n")
32 MESSAGE(FATAL_ERROR "The C compiler \"${CMAKE_C_COMPILER}\" "
33 "is not able to compile a simple test program.\nIt fails "
34 "with the following output:\n ${OUTPUT}\n\n"
35 "CMake will not be able to correctly generate this project.")
36 ELSE(NOT CMAKE_C_COMPILER_WORKS)
38 MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} -- works")
39 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
40 "Determining if the C compiler works passed with "
41 "the following output:\n${OUTPUT}\n\n")
43 SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
45 IF(CMAKE_C_COMPILER_FORCED)
46 # The compiler configuration was forced by the user.
47 # Assume the user has configured all compiler information.
48 ELSE(CMAKE_C_COMPILER_FORCED)
49 # Try to identify the ABI and configure it into CMakeCCompiler.cmake
50 INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
51 CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c)
53 ${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
54 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCCompiler.cmake
55 @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
57 ENDIF(CMAKE_C_COMPILER_FORCED)
58 ENDIF(NOT CMAKE_C_COMPILER_WORKS)