Updated formatting of documentation plus a little reorganization.
[cmake.git] / Modules / CMakeCXXInformation.cmake
blob4f536e6cad7c5040c3b74d73268b7d1a29064ac6
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
4 # if it exists.
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
10 IF(UNIX)
11   SET(CMAKE_CXX_OUTPUT_EXTENSION .o)
12 ELSE(UNIX)
13   SET(CMAKE_CXX_OUTPUT_EXTENSION .obj)
14 ENDIF(UNIX)
16 # Load compiler-specific information.
17 IF(CMAKE_CXX_COMPILER_ID)
18   INCLUDE(Compiler/${CMAKE_CXX_COMPILER_ID}-CXX OPTIONAL)
19 ENDIF(CMAKE_CXX_COMPILER_ID)
21 SET(CMAKE_BASE_NAME)
22 GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_CXX_COMPILER} NAME_WE)
23 # since the gnu compiler has several names force g++
24 IF(CMAKE_COMPILER_IS_GNUCXX)
25   SET(CMAKE_BASE_NAME g++)
26 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
29 # load a hardware specific file, mostly useful for embedded compilers
30 IF(CMAKE_SYSTEM_PROCESSOR)
31   IF(CMAKE_CXX_COMPILER_ID)
32     INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
33   ENDIF(CMAKE_CXX_COMPILER_ID)
34   IF (NOT _INCLUDED_FILE)
35     INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
36   ENDIF (NOT _INCLUDED_FILE)
37 ENDIF(CMAKE_SYSTEM_PROCESSOR)
39 # load the system- and compiler specific files
40 IF(CMAKE_CXX_COMPILER_ID)
41   INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
42 ENDIF(CMAKE_CXX_COMPILER_ID)
43 IF (NOT _INCLUDED_FILE)
44   INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
45 ENDIF (NOT _INCLUDED_FILE)
48 # This should be included before the _INIT variables are
49 # used to initialize the cache.  Since the rule variables 
50 # have if blocks on them, users can still define them here.
51 # But, it should still be after the platform file so changes can
52 # be made to those values.
54 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
55    INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
56 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
58 IF(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
59    INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX})
60 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
63 # for most systems a module is the same as a shared library
64 # so unless the variable CMAKE_MODULE_EXISTS is set just
65 # copy the values from the LIBRARY variables
66 IF(NOT CMAKE_MODULE_EXISTS)
67   SET(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS})
68 ENDIF(NOT CMAKE_MODULE_EXISTS)
69 # Create a set of shared library variable specific to C++
70 # For 90% of the systems, these are the same flags as the C versions
71 # so if these are not set just copy the flags from the c version
72 IF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
73   SET(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
74 ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
76 IF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
77   SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
78 ENDIF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
80 IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
81   SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
82 ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
84 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG)
85   SET(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}) 
86 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG)
88 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP)
89   SET(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
90 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP)
92 IF(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG)
93   SET(CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
94 ENDIF(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG)
96 IF(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG)
97   SET(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG})
98 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG)
100 IF(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP)
101   SET(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP})
102 ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP)
104 IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG)
105   SET(CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG})
106 ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG)
108 IF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH)
109   SET(CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH})
110 ENDIF(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH)
112 IF(NOT CMAKE_INCLUDE_FLAG_CXX)
113   SET(CMAKE_INCLUDE_FLAG_CXX ${CMAKE_INCLUDE_FLAG_C})
114 ENDIF(NOT CMAKE_INCLUDE_FLAG_CXX)
116 IF(NOT CMAKE_INCLUDE_FLAG_SEP_CXX)
117   SET(CMAKE_INCLUDE_FLAG_SEP_CXX ${CMAKE_INCLUDE_FLAG_SEP_C})
118 ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_CXX)
120 # repeat for modules
121 IF(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS)
122   SET(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
123 ENDIF(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS)
125 IF(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
126   SET(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
127 ENDIF(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
129 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG)
130   SET(CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_FLAG}) 
131 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG)
133 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP)
134   SET(CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_FLAG_SEP})
135 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP)
137 # Initialize CXX link type selection flags from C versions.
138 FOREACH(type SHARED_LIBRARY SHARED_MODULE EXE)
139   IF(NOT CMAKE_${type}_LINK_STATIC_CXX_FLAGS)
140     SET(CMAKE_${type}_LINK_STATIC_CXX_FLAGS
141       ${CMAKE_${type}_LINK_STATIC_C_FLAGS})
142   ENDIF(NOT CMAKE_${type}_LINK_STATIC_CXX_FLAGS)
143   IF(NOT CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS)
144     SET(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS
145       ${CMAKE_${type}_LINK_DYNAMIC_C_FLAGS})
146   ENDIF(NOT CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS)
147 ENDFOREACH(type)
149 # add the flags to the cache based
150 # on the initial values computed in the platform/*.cmake files
151 # use _INIT variables so that this only happens the first time
152 # and you can set these flags in the cmake cache
153 SET(CMAKE_CXX_FLAGS_INIT "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}")
154 # avoid just having a space as the initial value for the cache 
155 IF(CMAKE_CXX_FLAGS_INIT STREQUAL " ")
156   SET(CMAKE_CXX_FLAGS_INIT)
157 ENDIF(CMAKE_CXX_FLAGS_INIT STREQUAL " ")
158 SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT}" CACHE STRING
159      "Flags used by the compiler during all build types.")
161 IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
162   SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING
163      "Flags used by the compiler during debug builds.")
164   SET (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}" CACHE STRING
165       "Flags used by the compiler during release minsize builds.")
166   SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT}" CACHE STRING
167      "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
168   SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
169      "Flags used by the compiler during Release with Debug Info builds.")
171 ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
173 IF(CMAKE_CXX_STANDARD_LIBRARIES_INIT)
174   SET(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES_INIT}"
175     CACHE STRING "Libraries linked by defalut with all C++ applications.")
176   MARK_AS_ADVANCED(CMAKE_CXX_STANDARD_LIBRARIES)
177 ENDIF(CMAKE_CXX_STANDARD_LIBRARIES_INIT)
179 INCLUDE(CMakeCommonLanguageInclude)
181 # now define the following rules:
182 # CMAKE_CXX_CREATE_SHARED_LIBRARY
183 # CMAKE_CXX_CREATE_SHARED_MODULE
184 # CMAKE_CXX_COMPILE_OBJECT
185 # CMAKE_CXX_LINK_EXECUTABLE
187 # variables supplied by the generator at use time
188 # <TARGET>
189 # <TARGET_BASE> the target without the suffix
190 # <OBJECTS>
191 # <OBJECT>
192 # <LINK_LIBRARIES>
193 # <FLAGS>
194 # <LINK_FLAGS>
196 # CXX compiler information
197 # <CMAKE_CXX_COMPILER>  
198 # <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>
199 # <CMAKE_CXX_SHARED_MODULE_CREATE_FLAGS>
200 # <CMAKE_CXX_LINK_FLAGS>
202 # Static library tools
203 # <CMAKE_AR> 
204 # <CMAKE_RANLIB>
207 # create a shared C++ library
208 IF(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
209   SET(CMAKE_CXX_CREATE_SHARED_LIBRARY
210       "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
211 ENDIF(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
213 # create a c++ shared module copy the shared library rule by default
214 IF(NOT CMAKE_CXX_CREATE_SHARED_MODULE)
215   SET(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
216 ENDIF(NOT CMAKE_CXX_CREATE_SHARED_MODULE)
219 # Create a static archive incrementally for large object file counts.
220 # If CMAKE_CXX_CREATE_STATIC_LIBRARY is set it will override these.
221 SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
222 SET(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> r  <TARGET> <LINK_FLAGS> <OBJECTS>")
223 SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
225 # compile a C++ file into an object file
226 IF(NOT CMAKE_CXX_COMPILE_OBJECT)
227   SET(CMAKE_CXX_COMPILE_OBJECT
228     "<CMAKE_CXX_COMPILER>  <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
229 ENDIF(NOT CMAKE_CXX_COMPILE_OBJECT)
231 IF(NOT CMAKE_CXX_LINK_EXECUTABLE)
232   SET(CMAKE_CXX_LINK_EXECUTABLE
233     "<CMAKE_CXX_COMPILER>  <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
234 ENDIF(NOT CMAKE_CXX_LINK_EXECUTABLE)
236 MARK_AS_ADVANCED(
237 CMAKE_BUILD_TOOL
238 CMAKE_VERBOSE_MAKEFILE 
239 CMAKE_CXX_FLAGS
240 CMAKE_CXX_FLAGS_RELEASE
241 CMAKE_CXX_FLAGS_RELWITHDEBINFO
242 CMAKE_CXX_FLAGS_MINSIZEREL
243 CMAKE_CXX_FLAGS_DEBUG)
245 SET(CMAKE_CXX_INFORMATION_LOADED 1)