1 # Macro to import the build settings from another project. Provide as
2 # an argument the file created by the other project's
3 # CMAKE_EXPORT_BUILD_SETTINGS command.
4 MACRO(CMAKE_IMPORT_BUILD_SETTINGS SETTINGS_FILE)
5 IF(${SETTINGS_FILE} MATCHES ".+")
7 INCLUDE(${SETTINGS_FILE})
9 # Check the CMake version that stored the settings.
10 IF(${CMAKE_BUILD_SETTING_CMAKE_MAJOR_VERSION}.${CMAKE_BUILD_SETTING_CMAKE_MINOR_VERSION}
11 GREATER ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
13 "${CMAKE_BUILD_SETTING_PROJECT_NAME} was built using CMake "
14 "${CMAKE_BUILD_SETTING_CMAKE_MAJOR_VERSION}.${CMAKE_BUILD_SETTING_CMAKE_MINOR_VERSION}, "
15 "but this is CMake${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}. "
16 "Please upgrade CMake to a more recent version.")
17 ENDIF(${CMAKE_BUILD_SETTING_CMAKE_MAJOR_VERSION}.${CMAKE_BUILD_SETTING_CMAKE_MINOR_VERSION}
18 GREATER ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
20 # Check the build tool.
21 SET(CMAKE_BUILD_TOOL1 "")
23 GET_FILENAME_COMPONENT (CMAKE_BUILD_TOOL1 ${CMAKE_BUILD_TOOL} NAME_WE)
24 STRING(TOLOWER ${CMAKE_BUILD_TOOL1} CMAKE_BUILD_TOOL1)
25 ENDIF(CMAKE_BUILD_TOOL)
26 SET(CMAKE_BUILD_TOOL2 "")
27 IF(CMAKE_BUILD_SETTING_BUILD_TOOL)
28 GET_FILENAME_COMPONENT (CMAKE_BUILD_TOOL2 ${CMAKE_BUILD_SETTING_BUILD_TOOL} NAME_WE)
29 STRING(TOLOWER ${CMAKE_BUILD_TOOL2} CMAKE_BUILD_TOOL2)
30 ENDIF(CMAKE_BUILD_SETTING_BUILD_TOOL)
31 STRING(COMPARE NOTEQUAL "x${CMAKE_BUILD_TOOL1}" "x${CMAKE_BUILD_TOOL2}"
32 CMAKE_BUILD_TOOL_MISMATCH)
34 IF(CMAKE_BUILD_SETTING_BUILD_TOOL MATCHES "^msdev$")
35 SET(CMAKE_IMPORT_BUILD_SETTINGS_IMPORTING_FROM_MS_STUDIO 1)
36 ENDIF(CMAKE_BUILD_SETTING_BUILD_TOOL MATCHES "^msdev$")
37 IF(CMAKE_BUILD_SETTING_BUILD_TOOL MATCHES "^devenv$")
38 SET(CMAKE_IMPORT_BUILD_SETTINGS_IMPORTING_FROM_MS_STUDIO 1)
39 ENDIF(CMAKE_BUILD_SETTING_BUILD_TOOL MATCHES "^devenv$")
41 # Check the C++ compiler setting. If it is empty, the imported
42 # project is not a C++ project, and doesn't need a matching compiler.
43 IF(CMAKE_BUILD_SETTING_CXX_COMPILER)
44 STRING(COMPARE NOTEQUAL
45 "x${CMAKE_CXX_COMPILER}" "x${CMAKE_BUILD_SETTING_CXX_COMPILER}"
46 CMAKE_CXX_COMPILER_MISMATCH)
47 ENDIF(CMAKE_BUILD_SETTING_CXX_COMPILER)
49 # Check the C build variation flags.
50 STRING(COMPARE NOTEQUAL
51 "x${CMAKE_C_FLAGS_DEBUG}" "x${CMAKE_BUILD_SETTING_C_FLAGS_DEBUG}"
52 CMAKE_C_FLAGS_DEBUG_MISMATCH)
53 STRING(COMPARE NOTEQUAL
54 "x${CMAKE_C_FLAGS_RELEASE}" "x${CMAKE_BUILD_SETTING_C_FLAGS_RELEASE}"
55 CMAKE_C_FLAGS_RELEASE_MISMATCH)
56 STRING(COMPARE NOTEQUAL
57 "x${CMAKE_C_FLAGS_MINSIZEREL}" "x${CMAKE_BUILD_SETTING_C_FLAGS_MINSIZEREL}"
58 CMAKE_C_FLAGS_MINSIZEREL_MISMATCH)
59 STRING(COMPARE NOTEQUAL
60 "x${CMAKE_C_FLAGS_RELWITHDEBINFO}" "x${CMAKE_BUILD_SETTING_C_FLAGS_RELWITHDEBINFO}"
61 CMAKE_C_FLAGS_RELWITHDEBINFO_MISMATCH)
63 # Check the C++ build variation flags.
64 STRING(COMPARE NOTEQUAL
65 "x${CMAKE_CXX_FLAGS_DEBUG}" "x${CMAKE_BUILD_SETTING_CXX_FLAGS_DEBUG}"
66 CMAKE_CXX_FLAGS_DEBUG_MISMATCH)
67 STRING(COMPARE NOTEQUAL
68 "x${CMAKE_CXX_FLAGS_RELEASE}" "x${CMAKE_BUILD_SETTING_CXX_FLAGS_RELEASE}"
69 CMAKE_CXX_FLAGS_RELEASE_MISMATCH)
70 STRING(COMPARE NOTEQUAL
71 "x${CMAKE_CXX_FLAGS_MINSIZEREL}" "x${CMAKE_BUILD_SETTING_CXX_FLAGS_MINSIZEREL}"
72 CMAKE_CXX_FLAGS_MINSIZEREL_MISMATCH)
73 STRING(COMPARE NOTEQUAL
74 "x${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" "x${CMAKE_BUILD_SETTING_CXX_FLAGS_RELWITHDEBINFO}"
75 CMAKE_CXX_FLAGS_RELWITHDEBINFO_MISMATCH)
77 # Check the build type.
78 SET(CMAKE_BUILD_TYPE_MISMATCH 0)
80 IF(NOT CMAKE_IMPORT_BUILD_SETTINGS_IMPORTING_FROM_MS_STUDIO)
81 STRING(COMPARE NOTEQUAL
82 "x${CMAKE_BUILD_TYPE}" "x${CMAKE_BUILD_SETTING_BUILD_TYPE}"
83 CMAKE_BUILD_TYPE_MISMATCH)
84 ENDIF(NOT CMAKE_IMPORT_BUILD_SETTINGS_IMPORTING_FROM_MS_STUDIO)
87 # Build tool must match on Windows.
89 IF(CMAKE_BUILD_TOOL_MISMATCH)
91 "This project, ${PROJECT_NAME}, depends on the project "
92 "${CMAKE_BUILD_SETTING_PROJECT_NAME}. Unfortunately "
93 "${CMAKE_BUILD_SETTING_PROJECT_NAME} was built using "
94 "\"${CMAKE_BUILD_TOOL2}\", but you are trying to build "
95 "${PROJECT_NAME} using \"${CMAKE_BUILD_TOOL1}\"."
96 "In order for this build to succeed, both projects must be "
97 "built with the same Generator. To change the Generator you "
98 "are using for the project ${PROJECT_NAME}, you must "
99 "delete the cache, and then rerun cmake and this "
100 "time select the same Generator that was used to build "
101 "${CMAKE_BUILD_SETTING_PROJECT_NAME}. If "
102 "${CMAKE_BUILD_SETTING_PROJECT_NAME} was built using a "
103 "generator that you do not have (for example it was built "
104 "with Visual Studio 6 and you only have 7) then you will "
105 "need to select a different version of "
106 "${CMAKE_BUILD_SETTING_PROJECT_NAME} or rebuild "
107 "${CMAKE_BUILD_SETTING_PROJECT_NAME} with the correct "
109 ENDIF(CMAKE_BUILD_TOOL_MISMATCH)
112 # Enforce the C++ compiler setting.
113 IF(CMAKE_CXX_COMPILER_MISMATCH)
114 MESSAGE("Warning: CMake is forcing CMAKE_CXX_COMPILER to "
115 "\"${CMAKE_BUILD_SETTING_CXX_COMPILER}\" to match that imported "
116 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. This is required "
117 "because C++ projects must use the same compiler. "
118 "If this message appears for more than one imported project, "
119 "you have conflicting C++ compilers and will have to "
120 "re-build one of those projects.")
121 SET(CMAKE_CXX_COMPILER ${CMAKE_BUILD_SETTING_CXX_COMPILER}
122 CACHE STRING "C++ compiler imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
123 ENDIF(CMAKE_CXX_COMPILER_MISMATCH)
125 # Enforce the build type.
126 IF(CMAKE_BUILD_TYPE_MISMATCH)
127 MESSAGE("Warning: CMake is forcing CMAKE_BUILD_TYPE to "
128 "\"${CMAKE_BUILD_SETTING_BUILD_TYPE}\" to match that imported "
129 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. This is required "
130 "because projects must use the same compiler settings. "
131 "If this message appears for more than one imported project, "
132 "you have conflicting compiler settings and will have to "
133 "re-build one of those projects.")
134 SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_SETTING_BUILD_TYPE}
135 CACHE STRING "Build type imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
136 ENDIF(CMAKE_BUILD_TYPE_MISMATCH)
138 # Enforce the C build variation flags.
140 IF(CMAKE_C_FLAGS_DEBUG_MISMATCH)
141 MESSAGE("Warning: CMake is forcing CMAKE_C_FLAGS_DEBUG to "
142 "\"${CMAKE_BUILD_SETTING_C_FLAGS_DEBUG}\" to match that imported "
143 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. "
144 "If this message appears for more than one imported project, "
145 "you have conflicting options and will have to "
146 "re-build one of those projects.")
147 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_BUILD_SETTING_C_FLAGS_DEBUG}
148 CACHE STRING "C DEBUG flags imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
149 ENDIF(CMAKE_C_FLAGS_DEBUG_MISMATCH)
151 IF(CMAKE_C_FLAGS_RELEASE_MISMATCH)
152 MESSAGE("Warning: CMake is forcing CMAKE_C_FLAGS_RELEASE to "
153 "\"${CMAKE_BUILD_SETTING_C_FLAGS_RELEASE}\" to match that imported "
154 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. "
155 "If this message appears for more than one imported project, "
156 "you have conflicting options and will have to "
157 "re-build one of those projects.")
158 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_BUILD_SETTING_C_FLAGS_RELEASE}
159 CACHE STRING "C RELEASE flags imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
160 ENDIF(CMAKE_C_FLAGS_RELEASE_MISMATCH)
162 IF(CMAKE_C_FLAGS_MINSIZEREL_MISMATCH)
163 MESSAGE("Warning: CMake is forcing CMAKE_C_FLAGS_MINSIZEREL to "
164 "\"${CMAKE_BUILD_SETTING_C_FLAGS_MINSIZEREL}\" to match that imported "
165 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. "
166 "If this message appears for more than one imported project, "
167 "you have conflicting options and will have to "
168 "re-build one of those projects.")
169 SET(CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_BUILD_SETTING_C_FLAGS_MINSIZEREL}
170 CACHE STRING "C MINSIZEREL flags imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
171 ENDIF(CMAKE_C_FLAGS_MINSIZEREL_MISMATCH)
173 IF(CMAKE_C_FLAGS_RELWITHDEBINFO_MISMATCH)
174 MESSAGE("Warning: CMake is forcing CMAKE_C_FLAGS_RELWITHDEBINFO to "
175 "\"${CMAKE_BUILD_SETTING_C_FLAGS_RELWITHDEBINFO}\" to match that imported "
176 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. "
177 "If this message appears for more than one imported project, "
178 "you have conflicting options and will have to "
179 "re-build one of those projects.")
180 SET(CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_BUILD_SETTING_C_FLAGS_RELWITHDEBINFO}
181 CACHE STRING "C RELWITHDEBINFO flags imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
182 ENDIF(CMAKE_C_FLAGS_RELWITHDEBINFO_MISMATCH)
184 # Enforce the C++ build variation flags.
186 IF(CMAKE_CXX_FLAGS_DEBUG_MISMATCH)
187 MESSAGE("Warning: CMake is forcing CMAKE_CXX_FLAGS_DEBUG to "
188 "\"${CMAKE_BUILD_SETTING_CXX_FLAGS_DEBUG}\" to match that imported "
189 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. "
190 "If this message appears for more than one imported project, "
191 "you have conflicting options and will have to "
192 "re-build one of those projects.")
193 SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_BUILD_SETTING_CXX_FLAGS_DEBUG}
194 CACHE STRING "C++ DEBUG flags imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
195 ENDIF(CMAKE_CXX_FLAGS_DEBUG_MISMATCH)
197 IF(CMAKE_CXX_FLAGS_RELEASE_MISMATCH)
198 MESSAGE("Warning: CMake is forcing CMAKE_CXX_FLAGS_RELEASE to "
199 "\"${CMAKE_BUILD_SETTING_CXX_FLAGS_RELEASE}\" to match that imported "
200 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. "
201 "If this message appears for more than one imported project, "
202 "you have conflicting options and will have to "
203 "re-build one of those projects.")
204 SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_BUILD_SETTING_CXX_FLAGS_RELEASE}
205 CACHE STRING "C++ RELEASE flags imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
206 ENDIF(CMAKE_CXX_FLAGS_RELEASE_MISMATCH)
208 IF(CMAKE_CXX_FLAGS_MINSIZEREL_MISMATCH)
209 MESSAGE("Warning: CMake is forcing CMAKE_CXX_FLAGS_MINSIZEREL to "
210 "\"${CMAKE_BUILD_SETTING_CXX_FLAGS_MINSIZEREL}\" to match that imported "
211 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. "
212 "If this message appears for more than one imported project, "
213 "you have conflicting options and will have to "
214 "re-build one of those projects.")
215 SET(CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_BUILD_SETTING_CXX_FLAGS_MINSIZEREL}
216 CACHE STRING "C++ MINSIZEREL flags imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
217 ENDIF(CMAKE_CXX_FLAGS_MINSIZEREL_MISMATCH)
219 IF(CMAKE_CXX_FLAGS_RELWITHDEBINFO_MISMATCH)
220 MESSAGE("Warning: CMake is forcing CMAKE_CXX_FLAGS_RELWITHDEBINFO to "
221 "\"${CMAKE_BUILD_SETTING_CXX_FLAGS_RELWITHDEBINFO}\" to match that imported "
222 "from ${CMAKE_BUILD_SETTING_PROJECT_NAME}. "
223 "If this message appears for more than one imported project, "
224 "you have conflicting options and will have to "
225 "re-build one of those projects.")
226 SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_BUILD_SETTING_CXX_FLAGS_RELWITHDEBINFO}
227 CACHE STRING "C++ RELWITHDEBINFO flags imported from ${CMAKE_BUILD_SETTING_PROJECT_NAME}." FORCE)
228 ENDIF(CMAKE_CXX_FLAGS_RELWITHDEBINFO_MISMATCH)
230 ELSE(${SETTINGS_FILE} MATCHES ".+")
231 MESSAGE(SEND_ERROR "CMAKE_IMPORT_BUILD_SETTINGS called with no argument.")
232 ENDIF(${SETTINGS_FILE} MATCHES ".+")
233 ENDMACRO(CMAKE_IMPORT_BUILD_SETTINGS)