2 # This file sets the basic flags for the C language in CMake.
3 # It also loads the available platform file for the system-compiler
5 # It also loads a system - compiler - processor (or target hardware)
6 # specific file, which is mainly useful for crosscompiling and embedded systems.
8 # some compilers use different extensions (e.g. sdcc uses .rel)
9 # so set the extension here first so it can be overridden by the compiler specific file
11 SET(CMAKE_C_OUTPUT_EXTENSION .o)
13 SET(CMAKE_C_OUTPUT_EXTENSION .obj)
16 GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_C_COMPILER} NAME_WE)
17 IF(CMAKE_COMPILER_IS_GNUCC)
18 SET(CMAKE_BASE_NAME gcc)
19 ENDIF(CMAKE_COMPILER_IS_GNUCC)
22 # load a hardware specific file, mostly useful for embedded compilers
23 IF(CMAKE_SYSTEM_PROCESSOR)
24 IF(CMAKE_C_COMPILER_ID)
25 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
26 ENDIF(CMAKE_C_COMPILER_ID)
27 IF (NOT _INCLUDED_FILE)
28 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
29 ENDIF (NOT _INCLUDED_FILE)
30 ENDIF(CMAKE_SYSTEM_PROCESSOR)
33 # load the system- and compiler specific files
34 IF(CMAKE_C_COMPILER_ID)
35 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
36 ENDIF(CMAKE_C_COMPILER_ID)
37 IF (NOT _INCLUDED_FILE)
38 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
39 ENDIF (NOT _INCLUDED_FILE)
42 # This should be included before the _INIT variables are
43 # used to initialize the cache. Since the rule variables
44 # have if blocks on them, users can still define them here.
45 # But, it should still be after the platform file so changes can
46 # be made to those values.
48 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
49 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
50 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
52 IF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
53 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_C})
54 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
57 # for most systems a module is the same as a shared library
58 # so unless the variable CMAKE_MODULE_EXISTS is set just
59 # copy the values from the LIBRARY variables
60 IF(NOT CMAKE_MODULE_EXISTS)
61 SET(CMAKE_SHARED_MODULE_C_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
62 SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
63 ENDIF(NOT CMAKE_MODULE_EXISTS)
65 SET(CMAKE_C_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}")
66 # avoid just having a space as the initial value for the cache
67 IF(CMAKE_C_FLAGS_INIT STREQUAL " ")
68 SET(CMAKE_C_FLAGS_INIT)
69 ENDIF(CMAKE_C_FLAGS_INIT STREQUAL " ")
70 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT}" CACHE STRING
71 "Flags used by the compiler during all build types.")
73 IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
74 # default build type is none
75 IF(NOT CMAKE_NO_BUILD_TYPE)
76 SET (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
77 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
78 ENDIF(NOT CMAKE_NO_BUILD_TYPE)
79 SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING
80 "Flags used by the compiler during debug builds.")
81 SET (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING
82 "Flags used by the compiler during release minsize builds.")
83 SET (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING
84 "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
85 SET (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
86 "Flags used by the compiler during Release with Debug Info builds.")
87 ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
89 IF(CMAKE_C_STANDARD_LIBRARIES_INIT)
90 SET(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}"
91 CACHE STRING "Libraries linked by defalut with all C applications.")
92 MARK_AS_ADVANCED(CMAKE_C_STANDARD_LIBRARIES)
93 ENDIF(CMAKE_C_STANDARD_LIBRARIES_INIT)
95 INCLUDE(CMakeCommonLanguageInclude)
97 # now define the following rule variables
99 # CMAKE_C_CREATE_SHARED_LIBRARY
100 # CMAKE_C_CREATE_SHARED_MODULE
101 # CMAKE_C_COMPILE_OBJECT
102 # CMAKE_C_LINK_EXECUTABLE
104 # variables supplied by the generator at use time
106 # <TARGET_BASE> the target without the suffix
113 # C compiler information
115 # <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
116 # <CMAKE_SHARED_MODULE_CREATE_C_FLAGS>
117 # <CMAKE_C_LINK_FLAGS>
119 # Static library tools
124 # create a C shared library
125 IF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
126 SET(CMAKE_C_CREATE_SHARED_LIBRARY
127 "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
128 ENDIF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
130 # create a C shared module just copy the shared library rule
131 IF(NOT CMAKE_C_CREATE_SHARED_MODULE)
132 SET(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
133 ENDIF(NOT CMAKE_C_CREATE_SHARED_MODULE)
135 # Create a static archive incrementally for large object file counts.
136 # If CMAKE_C_CREATE_STATIC_LIBRARY is set it will override these.
137 SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
138 SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
139 SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
141 # compile a C file into an object file
142 IF(NOT CMAKE_C_COMPILE_OBJECT)
143 SET(CMAKE_C_COMPILE_OBJECT
144 "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
145 ENDIF(NOT CMAKE_C_COMPILE_OBJECT)
147 IF(NOT CMAKE_C_LINK_EXECUTABLE)
148 SET(CMAKE_C_LINK_EXECUTABLE
149 "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
150 ENDIF(NOT CMAKE_C_LINK_EXECUTABLE)
152 IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
153 SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
154 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
156 IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
157 SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
158 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
160 IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
161 SET(CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
162 ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
167 CMAKE_C_FLAGS_MINSIZEREL
168 CMAKE_C_FLAGS_RELEASE
169 CMAKE_C_FLAGS_RELWITHDEBINFO
171 SET(CMAKE_C_INFORMATION_LOADED 1)