1 # This file sets the basic flags for the C language in CMake.
2 # It also loads the available platform file for the system-compiler
5 GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_C_COMPILER} NAME_WE)
6 IF(CMAKE_COMPILER_IS_GNUCC)
7 SET(CMAKE_BASE_NAME gcc)
8 ENDIF(CMAKE_COMPILER_IS_GNUCC)
9 SET(CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE
10 ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
11 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
13 # for most systems a module is the same as a shared library
14 # so unless the variable CMAKE_MODULE_EXISTS is set just
15 # copy the values from the LIBRARY variables
16 IF(NOT CMAKE_MODULE_EXISTS)
17 SET(CMAKE_SHARED_MODULE_C_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
18 SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
19 ENDIF(NOT CMAKE_MODULE_EXISTS)
21 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_ENV_INIT} $ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}" CACHE STRING
22 "Flags for C compiler.")
24 IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
25 # default build type is none
26 IF(NOT CMAKE_NO_BUILD_TYPE)
27 SET (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
28 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
29 ENDIF(NOT CMAKE_NO_BUILD_TYPE)
30 SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING
31 "Flags used by the compiler during debug builds.")
32 SET (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING
33 "Flags used by the compiler during release minsize builds.")
34 SET (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING
35 "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
36 SET (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
37 "Flags used by the compiler during Release with Debug Info builds.")
38 ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
40 INCLUDE(CMakeCommonLanguageInclude)
42 # now define the following rule variables
44 # CMAKE_C_CREATE_SHARED_LIBRARY
45 # CMAKE_C_CREATE_SHARED_MODULE
46 # CMAKE_C_CREATE_STATIC_LIBRARY
47 # CMAKE_C_COMPILE_OBJECT
48 # CMAKE_C_LINK_EXECUTABLE
50 # variables supplied by the generator at use time
52 # <TARGET_BASE> the target without the suffix
59 # C compiler information
61 # <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
62 # <CMAKE_SHARED_MODULE_CREATE_C_FLAGS>
63 # <CMAKE_C_LINK_FLAGS>
65 # Static library tools
70 # create a C shared library
71 IF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
72 SET(CMAKE_C_CREATE_SHARED_LIBRARY
73 "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
74 ENDIF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
76 # create a C shared module just copy the shared library rule
77 IF(NOT CMAKE_C_CREATE_SHARED_MODULE)
78 SET(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
79 ENDIF(NOT CMAKE_C_CREATE_SHARED_MODULE)
81 # create a C static library
82 IF(NOT CMAKE_C_CREATE_STATIC_LIBRARY)
83 SET(CMAKE_C_CREATE_STATIC_LIBRARY
84 "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
85 "<CMAKE_RANLIB> <TARGET> ")
86 ENDIF(NOT CMAKE_C_CREATE_STATIC_LIBRARY)
88 # compile a C file into an object file
89 IF(NOT CMAKE_C_COMPILE_OBJECT)
90 SET(CMAKE_C_COMPILE_OBJECT
91 "<CMAKE_C_COMPILER> -o <OBJECT> <FLAGS> -c <SOURCE>")
92 ENDIF(NOT CMAKE_C_COMPILE_OBJECT)
94 IF(NOT CMAKE_C_LINK_EXECUTABLE)
95 SET(CMAKE_C_LINK_EXECUTABLE
96 "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
97 ENDIF(NOT CMAKE_C_LINK_EXECUTABLE)
99 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
100 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
101 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
106 CMAKE_C_FLAGS_MINSIZEREL
107 CMAKE_C_FLAGS_RELEASE
108 CMAKE_C_FLAGS_RELWITHDEBINFO
110 SET(CMAKE_C_INFOMATION_LOADED 1)