STYLE: Nightly Version update
[cmake.git] / Modules / CMakeCXXInformation.cmake
blob16a010f70b07f3befe8bbc2663e438d60fe3a6b4
1 # This file sets the basic flags for the C++ language in CMake.
2 # It also loads the available platform file for the system-compiler
3 # if it exists.
6 GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_CXX_COMPILER} NAME_WE)
7 # since the gnu compiler has several names force g++
8 IF(CMAKE_COMPILER_IS_GNUCXX)
9   SET(CMAKE_BASE_NAME g++)
10 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
11 SET(CMAKE_SYSTEM_AND_CXX_COMPILER_INFO_FILE
12   ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake)
13 INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
15 # for most systems a module is the same as a shared library
16 # so unless the variable CMAKE_MODULE_EXISTS is set just
17 # copy the values from the LIBRARY variables
18 IF(NOT CMAKE_MODULE_EXISTS)
19   SET(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS})
20 ENDIF(NOT CMAKE_MODULE_EXISTS)
21 # Create a set of shared library variable specific to C++
22 # For 90% of the systems, these are the same flags as the C versions
23 # so if these are not set just copy the flags from the c version
24 IF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
25   SET(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
26 ENDIF(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS)
28 IF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
29   SET(CMAKE_SHARED_LIBRARY_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
30 ENDIF(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS)
32 IF(NOT CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
33   SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
34 ENDIF(NOT CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
36 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG)
37   SET(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}) 
38 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG)
40 IF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP)
41   SET(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
42 ENDIF(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP)
44 IF(NOT CMAKE_INCLUDE_FLAG_CXX)
45   SET(CMAKE_INCLUDE_FLAG_CXX ${CMAKE_INCLUDE_FLAG_C})
46 ENDIF(NOT CMAKE_INCLUDE_FLAG_CXX)
48 IF(NOT CMAKE_INCLUDE_FLAG_SEP_CXX)
49   SET(CMAKE_INCLUDE_FLAG_SEP_CXX ${CMAKE_INCLUDE_FLAG_SEP_C})
50 ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_CXX)
52 # repeat for modules
53 IF(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS)
54   SET(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS})
55 ENDIF(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS)
57 IF(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
58   SET(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS})
59 ENDIF(NOT CMAKE_SHARED_MODULE_CXX_FLAGS)
61 IF(NOT CMAKE_SHARED_MODULE_LINK_CXX_FLAGS)
62   SET(CMAKE_SHARED_MODULE_LINK_CXX_FLAGS ${CMAKE_SHARED_MODULE_LINK_C_FLAGS})
63 ENDIF(NOT CMAKE_SHARED_MODULE_LINK_CXX_FLAGS)
65 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG)
66   SET(CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG ${CMAKE_SHARED_MODULE_RUNTIME_FLAG}) 
67 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG)
69 IF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP)
70   SET(CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_MODULE_RUNTIME_FLAG_SEP})
71 ENDIF(NOT CMAKE_SHARED_MODULE_RUNTIME_CXX_FLAG_SEP)
73 # add the flags to the cache based
74 # on the initial values computed in the platform/*.cmake files
75 # use _INIT variables so that this only happens the first time
76 # and you can set these flags in the cmake cache
77 SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_ENV_INIT} $ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}" CACHE STRING
78      "Flags used by the compiler during all build types.")
81 IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
82   SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING
83      "Flags used by the compiler during debug builds.")
84   SET (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}" CACHE STRING
85       "Flags used by the compiler during release minsize builds.")
86   SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT}" CACHE STRING
87      "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
88   SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
89      "Flags used by the compiler during Release with Debug Info builds.")
91 ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
94 INCLUDE(CMakeCommonLanguageInclude)
96 # now define the following rules:
97 # CMAKE_CXX_CREATE_SHARED_LIBRARY
98 # CMAKE_CXX_CREATE_SHARED_MODULE
99 # CMAKE_CXX_CREATE_STATIC_LIBRARY
100 # CMAKE_CXX_COMPILE_OBJECT
101 # CMAKE_CXX_LINK_EXECUTABLE
103 # variables supplied by the generator at use time
104 # <TARGET>
105 # <TARGET_BASE> the target without the suffix
106 # <OBJECTS>
107 # <OBJECT>
108 # <LINK_LIBRARIES>
109 # <FLAGS>
110 # <LINK_FLAGS>
112 # CXX compiler information
113 # <CMAKE_CXX_COMPILER>  
114 # <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>
115 # <CMAKE_CXX_SHARED_MODULE_CREATE_FLAGS>
116 # <CMAKE_CXX_LINK_FLAGS>
118 # Static library tools
119 # <CMAKE_AR> 
120 # <CMAKE_RANLIB>
123 # create a shared C++ library
124 IF(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
125   SET(CMAKE_CXX_CREATE_SHARED_LIBRARY
126       "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
127 ENDIF(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
129 IF(CMAKE_COMPILER_IS_GNUCXX)
130   SET(CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} -lgcc")
131 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
133 # create a c++ shared module copy the shared library rule by default
134 IF(NOT CMAKE_CXX_CREATE_SHARED_MODULE)
135   SET(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY})
136 ENDIF(NOT CMAKE_CXX_CREATE_SHARED_MODULE)
139 # create a C++ static library
140 IF(NOT CMAKE_CXX_CREATE_STATIC_LIBRARY)
141   SET(CMAKE_CXX_CREATE_STATIC_LIBRARY
142       "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS> "
143       "<CMAKE_RANLIB> <TARGET> ")
144 ENDIF(NOT CMAKE_CXX_CREATE_STATIC_LIBRARY)
146 # compile a C++ file into an object file
147 IF(NOT CMAKE_CXX_COMPILE_OBJECT)
148   SET(CMAKE_CXX_COMPILE_OBJECT
149     "<CMAKE_CXX_COMPILER> -o <OBJECT> <FLAGS> -c <SOURCE>")
150 ENDIF(NOT CMAKE_CXX_COMPILE_OBJECT)
152 IF(NOT CMAKE_CXX_LINK_EXECUTABLE)
153   SET(CMAKE_CXX_LINK_EXECUTABLE
154     "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
155 ENDIF(NOT CMAKE_CXX_LINK_EXECUTABLE)
157 IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
158    INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
159 ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
162 MARK_AS_ADVANCED(
163 CMAKE_BUILD_TOOL
164 CMAKE_VERBOSE_MAKEFILE 
165 CMAKE_CXX_FLAGS
166 CMAKE_CXX_FLAGS_RELEASE
167 CMAKE_CXX_FLAGS_RELWITHDEBINFO
168 CMAKE_CXX_FLAGS_MINSIZEREL
169 CMAKE_CXX_FLAGS_DEBUG)
171 SET(CMAKE_CXX_INFOMATION_LOADED 1)