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