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