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 # if the compiler is broken make sure to remove the platform file
33 # since Windows-cl configures both c/cxx files both need to be removed
35 FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake )
36 FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake )
37 MESSAGE(FATAL_ERROR "The C compiler \"${CMAKE_C_COMPILER}\" "
38 "is not able to compile a simple test program.\nIt fails "
39 "with the following output:\n ${OUTPUT}\n\n"
40 "CMake will not be able to correctly generate this project.")
41 ELSE(NOT CMAKE_C_COMPILER_WORKS)
43 MESSAGE(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} -- works")
44 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
45 "Determining if the C compiler works passed with "
46 "the following output:\n${OUTPUT}\n\n")
48 SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
50 IF(CMAKE_C_COMPILER_FORCED)
51 # The compiler configuration was forced by the user.
52 # Assume the user has configured all compiler information.
53 ELSE(CMAKE_C_COMPILER_FORCED)
54 # Try to identify the ABI and configure it into CMakeCCompiler.cmake
55 INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
56 CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c)
58 ${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
59 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCCompiler.cmake
60 @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
62 ENDIF(CMAKE_C_COMPILER_FORCED)
63 ENDIF(NOT CMAKE_C_COMPILER_WORKS)