@@ -126,6 +126,50 @@ if(NOT CMAKE_VERSION VERSION_LESS "2.8.11")
126
126
endforeach ()
127
127
endif ()
128
128
129
+
130
+ if (NOT DEFINED OPENCV_MAP_IMPORTED_CONFIG )
131
+ if (CMAKE_GENERATOR MATCHES "Visual Studio" OR MSVC )
132
+ # OpenCV supports Debug and Release builds only.
133
+ # But MSVS has 'RelWithDebInfo' 'MinSizeRel' configurations for applications.
134
+ # By default CMake maps these configuration on the first available (Debug) which is wrong.
135
+ # Non-Debug build of Application can't be used with OpenCV Debug build (ABI mismatch problem)
136
+ # Add mapping of RelWithDebInfo and MinSizeRel to Release here
137
+ set (OPENCV_MAP_IMPORTED_CONFIG "RELWITHDEBINFO=!Release;MINSIZEREL=!Release" )
138
+ endif ()
139
+ endif ()
140
+ set (__remap_warnings "" )
141
+ macro (ocv_map_imported_config target )
142
+ if (DEFINED OPENCV_MAP_IMPORTED_CONFIG ) # list, "RELWITHDEBINFO=Release;MINSIZEREL=Release"
143
+ get_target_property (__available_configurations ${target} IMPORTED_CONFIGURATIONS )
144
+ foreach (remap ${OPENCV_MAP_IMPORTED_CONFIG} )
145
+ if (remap MATCHES "^(.+)=(!?)([^!]+)$" )
146
+ set (__remap_config "${CMAKE_MATCH_1} " )
147
+ set (__final_config "${CMAKE_MATCH_3} " )
148
+ set (__force_flag "${CMAKE_MATCH_2} " )
149
+ string (TOUPPER "${__final_config} " __final_config_upper )
150
+ string (TOUPPER "${__remap_config} " __remap_config_upper )
151
+ if (";${__available_configurations} ;" MATCHES ";${__remap_config_upper} ;" AND NOT "${__force_flag} " STREQUAL "!" )
152
+ # configuration already exists, skip remap
153
+ set (__remap_warnings "${__remap_warnings} ... Configuration already exists ${__remap_config} (skip mapping ${__remap_config} => ${__final_config} ) (available configurations: ${__available_configurations} )\n " )
154
+ continue ()
155
+ endif ()
156
+ if (__available_configurations AND NOT ";${__available_configurations} ;" MATCHES ";${__final_config_upper} ;" )
157
+ # skip, configuration is not available
158
+ if (NOT "${__force_flag} " STREQUAL "!" )
159
+ set (__remap_warnings "${__remap_warnings} ... Configuration is not available '${__final_config} ' for ${target} , build may fail (available configurations: ${__available_configurations} )\n " )
160
+ endif ()
161
+ endif ()
162
+ set_target_properties (${target} PROPERTIES
163
+ MAP_IMPORTED_CONFIG_${__remap_config} "${__final_config} "
164
+ )
165
+ else ()
166
+ message (WARNING "Invalid entry of OPENCV_MAP_IMPORTED_CONFIG: '${remap} ' (${OPENCV_MAP_IMPORTED_CONFIG} )" )
167
+ endif ()
168
+ endforeach ()
169
+ endif ()
170
+ endmacro ()
171
+
172
+
129
173
# ==============================================================
130
174
# Form list of modules (components) to find
131
175
# ==============================================================
@@ -199,16 +243,15 @@ foreach(__cvcomponent ${OpenCV_FIND_COMPONENTS})
199
243
)
200
244
endif ()
201
245
endif ()
202
- # OpenCV supports Debug and Release only.
203
- # RelWithDebInfo and MinSizeRel are mapped to Release
204
246
if (TARGET ${__cvcomponent} )
205
- set_target_properties (${__cvcomponent} PROPERTIES
206
- MAP_IMPORTED_CONFIG_MINSIZEREL "Release"
207
- MAP_IMPORTED_CONFIG_RELWITHDEBINFO "Release"
208
- )
247
+ ocv_map_imported_config (${__cvcomponent} )
209
248
endif ()
210
249
endforeach ()
211
250
251
+ if (__remap_warnings AND NOT OpenCV_FIND_QUIETLY )
252
+ message ("OpenCV: configurations remap warnings:\n ${__remap_warnings} OpenCV: Check variable OPENCV_MAP_IMPORTED_CONFIG=${OPENCV_MAP_IMPORTED_CONFIG} " )
253
+ endif ()
254
+
212
255
# ==============================================================
213
256
# Compatibility stuff
214
257
# ==============================================================
0 commit comments