[CMake] Check Build Type/Config Changed

frodak17 frodak17 at gmail.com
Sun Jan 6 10:19:37 EST 2019


On Sun, Jan 6, 2019 at 10:00 AM Romain LEGUAY <romain.leguay at gmail.com>
wrote:

> Thank you for your answer!
>
> What I found strange is that CMAKE_CONFIGURATION_TYPES and
> CMAKE_BUILD_TYPE are empty at the begining of the cmake script.
>
> When do those variables instanciated?
>
> The purpose to know if the build type changed is to reactivate a
> superbuild variable to build my external dependencies in the good build
> type.
>
>
Either of them can be set at the command line using -D or preloaded into
the cache.

Then either of them can be set by whatever CMakeLists.txt is doing.
For example I've seen some projects set CMAKE_BUILD_TYPE to RELEASE if it
wasn't already set by the user.

Then for Visual Studio generator it will set CMAKE_CONFIGURATION_TYPES if
it wasn't already set by something else when it processes the project()
command.

So for Makefile generators CMAKE_BUILD_TYPE it might never be set.  This
indicates its a generic build and not one of DEBUG/RELEASE/etc which adds
extra flags to the generic build.

CMAKE_CONFIGURATION_TYPES isn't really safe to check until after the
project() command.
But CMAKE_CONFIGURATION_TYPES is just a list of all possible build types is
does not contain the last chosen build.

You mentioned that you were using Visual Studio 2017 as the generator.
Then you should know since it's a multi config generator CMAKE_BUILD_TYPE
is ignored and has no bearing on the build type.
This is because the build type isn't known at configuration time but at
build time when the user selects the build type from the GUI.
Also a user could even change the build type per target if they don't just
do a build all.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190106/a0cc5c8e/attachment.html>


More information about the CMake mailing list