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
36 OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
37 ENDIF(CMAKE_C_COMPILER_ID)
38 IF (NOT _INCLUDED_FILE)
39 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
40 OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
41 ENDIF (NOT _INCLUDED_FILE)
42 # some systems include the compiler information in the system file
43 # and if this is the enable_language command then it may not have been
44 # included at this point, or needs to be included again so that the
45 # language_INIT variables are set correctly
46 IF (NOT _INCLUDED_FILE)
47 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}
48 OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
49 ENDIF (NOT _INCLUDED_FILE)
52 # This should be included before the _INIT variables are
53 # used to initialize the cache. Since the rule variables
54 # have if blocks on them, users can still define them here.
55 # But, it should still be after the platform file so changes can
56 # be made to those values.
58 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
59 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
60 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
62 IF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
63 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_C})
64 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
67 # for most systems a module is the same as a shared library
68 # so unless the variable CMAKE_MODULE_EXISTS is set just
69 # copy the values from the LIBRARY variables
70 IF(NOT CMAKE_MODULE_EXISTS)
71 SET(CMAKE_SHARED_MODULE_C_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
72 SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
73 ENDIF(NOT CMAKE_MODULE_EXISTS)
75 SET(CMAKE_C_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}")
76 # avoid just having a space as the initial value for the cache
77 IF(CMAKE_C_FLAGS_INIT STREQUAL " ")
78 SET(CMAKE_C_FLAGS_INIT)
79 ENDIF(CMAKE_C_FLAGS_INIT STREQUAL " ")
80 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT}" CACHE STRING
81 "Flags used by the compiler during all build types.")
83 IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
84 # default build type is none
85 IF(NOT CMAKE_NO_BUILD_TYPE)
86 SET (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
87 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
88 ENDIF(NOT CMAKE_NO_BUILD_TYPE)
89 SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING
90 "Flags used by the compiler during debug builds.")
91 SET (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING
92 "Flags used by the compiler during release minsize builds.")
93 SET (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING
94 "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
95 SET (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
96 "Flags used by the compiler during Release with Debug Info builds.")
97 ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
99 IF(CMAKE_C_STANDARD_LIBRARIES_INIT)
100 SET(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}"
101 CACHE STRING "Libraries linked by defalut with all C applications.")
102 MARK_AS_ADVANCED(CMAKE_C_STANDARD_LIBRARIES)
103 ENDIF(CMAKE_C_STANDARD_LIBRARIES_INIT)
105 INCLUDE(CMakeCommonLanguageInclude)
107 # now define the following rule variables
109 # CMAKE_C_CREATE_SHARED_LIBRARY
110 # CMAKE_C_CREATE_SHARED_MODULE
111 # CMAKE_C_COMPILE_OBJECT
112 # CMAKE_C_LINK_EXECUTABLE
114 # variables supplied by the generator at use time
116 # <TARGET_BASE> the target without the suffix
123 # C compiler information
125 # <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
126 # <CMAKE_SHARED_MODULE_CREATE_C_FLAGS>
127 # <CMAKE_C_LINK_FLAGS>
129 # Static library tools
134 # create a C shared library
135 IF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
136 SET(CMAKE_C_CREATE_SHARED_LIBRARY
137 "<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>")
138 ENDIF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
140 # create a C shared module just copy the shared library rule
141 IF(NOT CMAKE_C_CREATE_SHARED_MODULE)
142 SET(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
143 ENDIF(NOT CMAKE_C_CREATE_SHARED_MODULE)
145 # Create a static archive incrementally for large object file counts.
146 # If CMAKE_C_CREATE_STATIC_LIBRARY is set it will override these.
147 SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
148 SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
149 SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
151 # compile a C file into an object file
152 IF(NOT CMAKE_C_COMPILE_OBJECT)
153 SET(CMAKE_C_COMPILE_OBJECT
154 "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
155 ENDIF(NOT CMAKE_C_COMPILE_OBJECT)
157 IF(NOT CMAKE_C_LINK_EXECUTABLE)
158 SET(CMAKE_C_LINK_EXECUTABLE
159 "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
160 ENDIF(NOT CMAKE_C_LINK_EXECUTABLE)
162 IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
163 SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
164 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
166 IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
167 SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
168 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
170 IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
171 SET(CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
172 ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
177 CMAKE_C_FLAGS_MINSIZEREL
178 CMAKE_C_FLAGS_RELEASE
179 CMAKE_C_FLAGS_RELWITHDEBINFO
181 SET(CMAKE_C_INFORMATION_LOADED 1)