From e9d021657715f32cdb465664d46d6c6971068eaf Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Wed, 18 Sep 2013 13:44:23 +0200 Subject: [PATCH] Clear default flags in an (im)proper way The CMAKE_NOT_USING_CONFIG_FLAGS option is really only settable by a user that doesn't want _DEBUG or _RELEASE flags to not have effect. If we want other flags than the platform default, we must do hairy things like clearing them from the cache (overriding the user's seletion if it was the same as the platform default). --- cmake/Modules/AddOptions.cmake | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/AddOptions.cmake b/cmake/Modules/AddOptions.cmake index 56c62326..19f02966 100644 --- a/cmake/Modules/AddOptions.cmake +++ b/cmake/Modules/AddOptions.cmake @@ -78,8 +78,20 @@ function (set_default_option lang varname flag regex) endif () endfunction (set_default_option) -# note: this must be called before project() +# clear default options as a proxy for not using any default options +# at all. there is one *huge* problem with this: CMake runs the platform +# initialization before executing any line at all in the project and +# there seems to be no way to disable that behaviour, so we cannot really +# distinguish between a platform default and something that the user has +# passed on the command line. the best thing we can do is to all user- +# defined setting if they are something other than the platform default. macro (no_default_options) - # prevent the platform probe to set options - set (CMAKE_NOT_USING_CONFIG_FLAGS TRUE) + foreach (lang IN ITEMS C CXX Fortran) + foreach (build IN ITEMS DEBUG RELEASE MINSIZEREL RELWITHDEBINFO) + if ("${CMAKE_${lang}_FLAGS_${build}}" STREQUAL "${CMAKE_${lang}_FLAGS_${build}_INIT}") + # for some strange reason we cannot clear this flag, only set it to empty + set (CMAKE_${lang}_FLAGS_${build} "") + endif () + endforeach (build) + endforeach (lang) endmacro (no_default_options)