1 # determine the compiler to use for C programs
2 # NOTE, a generator may set CMAKE_C_COMPILER before
3 # loading this file to force a compiler.
4 # use environment variable CCC first if defined by user, next use
5 # the cmake variable CMAKE_GENERATOR_CC which can be defined by a generator
6 # as a default compiler
8 IF(NOT CMAKE_C_COMPILER)
9 SET(CMAKE_CXX_COMPILER_INIT NOTFOUND)
11 # prefer the environment variable CC
12 IF($ENV{CC} MATCHES ".+")
13 GET_FILENAME_COMPONENT(CMAKE_C_COMPILER_INIT $ENV{CC} PROGRAM PROGRAM_ARGS CMAKE_C_FLAGS_ENV_INIT)
14 IF(EXISTS ${CMAKE_C_COMPILER_INIT})
15 ELSE(EXISTS ${CMAKE_C_COMPILER_INIT})
16 MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable CC:\n$ENV{CC}.")
17 ENDIF(EXISTS ${CMAKE_C_COMPILER_INIT})
18 ENDIF($ENV{CC} MATCHES ".+")
20 # next try prefer the compiler specified by the generator
21 IF(CMAKE_GENERATOR_CC)
22 IF(NOT CMAKE_C_COMPILER_INIT)
23 SET(CMAKE_C_COMPILER_INIT ${CMAKE_GENERATOR_CC})
24 ENDIF(NOT CMAKE_C_COMPILER_INIT)
25 ENDIF(CMAKE_GENERATOR_CC)
27 # if no compiler has been specified yet, then look for one
28 IF(NOT CMAKE_C_COMPILER_INIT)
29 # if not in the envionment then search for the compiler in the path
30 SET(CMAKE_C_COMPILER_LIST gcc cc cl bcc xlc)
31 FIND_PROGRAM(CMAKE_C_COMPILER_FULLPATH NAMES ${CMAKE_C_COMPILER_LIST} )
32 GET_FILENAME_COMPONENT(CMAKE_C_COMPILER_INIT
33 ${CMAKE_C_COMPILER_FULLPATH} NAME)
34 SET(CMAKE_C_COMPILER_FULLPATH "${CMAKE_C_COMPILER_FULLPATH}" CACHE INTERNAL "full path to the compiler cmake found")
35 ENDIF(NOT CMAKE_C_COMPILER_INIT)
37 SET(CMAKE_C_COMPILER ${CMAKE_C_COMPILER_INIT} CACHE STRING "C compiler")
38 ENDIF(NOT CMAKE_C_COMPILER)
39 MARK_AS_ADVANCED(CMAKE_C_COMPILER)
40 FIND_PROGRAM(CMAKE_AR NAMES ar )
42 FIND_PROGRAM(CMAKE_RANLIB NAMES ranlib)
44 SET(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
45 ENDIF(NOT CMAKE_RANLIB)
46 MARK_AS_ADVANCED(CMAKE_RANLIB)
48 # do not test for GNU if the generator is visual studio
49 IF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
50 SET(CMAKE_COMPILER_IS_GNUCC_RUN 1)
51 ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
54 IF(NOT CMAKE_COMPILER_IS_GNUCC_RUN)
55 # test to see if the c compiler is gnu
58 SET(CMAKE_BOOT_C_FLAGS ${CMAKE_C_FLAGS})
60 SET(CMAKE_BOOT_C_FLAGS $ENV{CFLAGS})
62 EXEC_PROGRAM(${CMAKE_C_COMPILER} ARGS ${CMAKE_BOOT_C_FLAGS} -E "\"${CMAKE_ROOT}/Modules/CMakeTestGNU.c\"" OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT RETURN_VALUE CMAKE_COMPILER_RETURN)
63 SET(CMAKE_COMPILER_IS_GNUCC_RUN 1)
64 IF(NOT CMAKE_COMPILER_RETURN)
65 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
66 SET(CMAKE_COMPILER_IS_GNUCC 1)
67 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
68 "Determining if the C compiler is GNU succeeded with "
69 "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
70 ELSE("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
71 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
72 "Determining if the C compiler is GNU failed with "
73 "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
74 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
75 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
76 SET(CMAKE_COMPILER_IS_MINGW 1)
77 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
78 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
79 SET(CMAKE_COMPILER_IS_CYGWIN 1)
80 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
81 ENDIF(NOT CMAKE_COMPILER_RETURN)
82 ENDIF(NOT CMAKE_COMPILER_IS_GNUCC_RUN)
85 # configure variables set in this file for fast reload later on
86 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
87 ${CMAKE_BINARY_DIR}/CMakeCCompiler.cmake IMMEDIATE)
88 MARK_AS_ADVANCED(CMAKE_AR)
90 SET(CMAKE_C_COMPILER_ENV_VAR "CC")