@@ -220,13 +220,30 @@ function(interrogate_sources target output database language_flags)
220220 endif ()
221221 set (define_flags "$<$<BOOL :${_compile_defs} >:-D ${_q} $<JOIN :${_compile_defs} ,${_q} \t -D ${_q} >${_q} >" )
222222
223- # If this is a release build that has NDEBUG defined, we need that too:
224- foreach (build_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} )
225- string (TOUPPER "${build_type} " build_type )
226- if (CMAKE_CXX_FLAGS_${build_type} MATCHES ".*NDEBUG.*" )
227- list (APPEND define_flags "$<$<CONFIG :${build_type} >:-DNDEBUG >" )
223+ # Some of the definitions may be specified using -D flags in the global
224+ # CXX_FLAGS variables; parse those out (this also picks up NDEBUG)
225+ set (_configs ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} "<ALL>" )
226+ list (REMOVE_DUPLICATES _configs)
227+ foreach (_config ${_configs} )
228+ if (_config STREQUAL "<ALL>" )
229+ set (flags "${CMAKE_CXX_FLAGS} " )
230+ else ()
231+ string (TOUPPER "${_config} " _CONFIG)
232+ set (flags "${CMAKE_CXX_FLAGS_${_CONFIG} }" )
233+ endif ()
234+
235+ # Convert "/D define1" and "-Ddefine2" flags, interspersed with other
236+ # compiler nonsense, into a basic "-Ddefine1 -Ddefine2" string
237+ string (REGEX MATCHALL "[/-]D[ \t ]*[A-Za-z0-9_]+" igate_flags "${flags} " )
238+ string (REPLACE ";" " " igate_flags "${igate_flags} " )
239+ string (REPLACE "/D" "-D" igate_flags "${igate_flags} " )
240+
241+ if (_config STREQUAL "<ALL>" )
242+ list (APPEND define_flags "${igate_flags} " )
243+ else ()
244+ list (APPEND define_flags "$<$<CONFIG :${_config} >:${igate_flags} >" )
228245 endif ()
229- endforeach (build_type )
246+ endforeach (_config )
230247
231248 # In case the user (or a distro buildsystem) is throwing NDEBUG in by hand:
232249 if (CMAKE_CXX_FLAGS MATCHES ".*NDEBUG.*" )
0 commit comments