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 # Load compiler-specific information.
17 IF(CMAKE_C_COMPILER_ID)
18 INCLUDE(Compiler/${CMAKE_C_COMPILER_ID}-C OPTIONAL)
19 ENDIF(CMAKE_C_COMPILER_ID)
22 GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_C_COMPILER} NAME_WE)
23 IF(CMAKE_COMPILER_IS_GNUCC)
24 SET(CMAKE_BASE_NAME gcc)
25 ENDIF(CMAKE_COMPILER_IS_GNUCC)
28 # load a hardware specific file, mostly useful for embedded compilers
29 IF(CMAKE_SYSTEM_PROCESSOR)
30 IF(CMAKE_C_COMPILER_ID)
31 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
32 ENDIF(CMAKE_C_COMPILER_ID)
33 IF (NOT _INCLUDED_FILE)
34 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
35 ENDIF (NOT _INCLUDED_FILE)
36 ENDIF(CMAKE_SYSTEM_PROCESSOR)
39 # load the system- and compiler specific files
40 IF(CMAKE_C_COMPILER_ID)
41 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C
42 OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
43 ENDIF(CMAKE_C_COMPILER_ID)
44 IF (NOT _INCLUDED_FILE)
45 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
46 OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
47 ENDIF (NOT _INCLUDED_FILE)
48 # some systems include the compiler information in the system file
49 # and if this is the enable_language command then it may not have been
50 # included at this point, or needs to be included again so that the
51 # language_INIT variables are set correctly
52 IF (NOT _INCLUDED_FILE)
53 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}
54 OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
55 ENDIF (NOT _INCLUDED_FILE)
58 # This should be included before the _INIT variables are
59 # used to initialize the cache. Since the rule variables
60 # have if blocks on them, users can still define them here.
61 # But, it should still be after the platform file so changes can
62 # be made to those values.
64 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
65 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
66 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
68 IF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
69 INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_C})
70 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
73 # for most systems a module is the same as a shared library
74 # so unless the variable CMAKE_MODULE_EXISTS is set just
75 # copy the values from the LIBRARY variables
76 IF(NOT CMAKE_MODULE_EXISTS)
77 SET(CMAKE_SHARED_MODULE_C_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
78 SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
79 ENDIF(NOT CMAKE_MODULE_EXISTS)
81 SET(CMAKE_C_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}")
82 # avoid just having a space as the initial value for the cache
83 IF(CMAKE_C_FLAGS_INIT STREQUAL " ")
84 SET(CMAKE_C_FLAGS_INIT)
85 ENDIF(CMAKE_C_FLAGS_INIT STREQUAL " ")
86 SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT}" CACHE STRING
87 "Flags used by the compiler during all build types.")
89 IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
90 # default build type is none
91 IF(NOT CMAKE_NO_BUILD_TYPE)
92 SET (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
93 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
94 ENDIF(NOT CMAKE_NO_BUILD_TYPE)
95 SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING
96 "Flags used by the compiler during debug builds.")
97 SET (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING
98 "Flags used by the compiler during release minsize builds.")
99 SET (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING
100 "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
101 SET (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
102 "Flags used by the compiler during Release with Debug Info builds.")
103 ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
105 IF(CMAKE_C_STANDARD_LIBRARIES_INIT)
106 SET(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}"
107 CACHE STRING "Libraries linked by defalut with all C applications.")
108 MARK_AS_ADVANCED(CMAKE_C_STANDARD_LIBRARIES)
109 ENDIF(CMAKE_C_STANDARD_LIBRARIES_INIT)
111 INCLUDE(CMakeCommonLanguageInclude)
113 # now define the following rule variables
115 # CMAKE_C_CREATE_SHARED_LIBRARY
116 # CMAKE_C_CREATE_SHARED_MODULE
117 # CMAKE_C_COMPILE_OBJECT
118 # CMAKE_C_LINK_EXECUTABLE
120 # variables supplied by the generator at use time
122 # <TARGET_BASE> the target without the suffix
129 # C compiler information
131 # <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
132 # <CMAKE_SHARED_MODULE_CREATE_C_FLAGS>
133 # <CMAKE_C_LINK_FLAGS>
135 # Static library tools
140 # create a C shared library
141 IF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
142 SET(CMAKE_C_CREATE_SHARED_LIBRARY
143 "<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>")
144 ENDIF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
146 # create a C shared module just copy the shared library rule
147 IF(NOT CMAKE_C_CREATE_SHARED_MODULE)
148 SET(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
149 ENDIF(NOT CMAKE_C_CREATE_SHARED_MODULE)
151 # Create a static archive incrementally for large object file counts.
152 # If CMAKE_C_CREATE_STATIC_LIBRARY is set it will override these.
153 SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
154 SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
155 SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
157 # compile a C file into an object file
158 IF(NOT CMAKE_C_COMPILE_OBJECT)
159 SET(CMAKE_C_COMPILE_OBJECT
160 "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
161 ENDIF(NOT CMAKE_C_COMPILE_OBJECT)
163 IF(NOT CMAKE_C_LINK_EXECUTABLE)
164 SET(CMAKE_C_LINK_EXECUTABLE
165 "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
166 ENDIF(NOT CMAKE_C_LINK_EXECUTABLE)
168 IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
169 SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
170 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
172 IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
173 SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
174 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
176 IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
177 SET(CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
178 ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
183 CMAKE_C_FLAGS_MINSIZEREL
184 CMAKE_C_FLAGS_RELEASE
185 CMAKE_C_FLAGS_RELWITHDEBINFO
187 SET(CMAKE_C_INFORMATION_LOADED 1)