Check Build Type/Config Changed

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Check Build Type/Config Changed

Romain LEGUAY

Hi everyone,

 

Is there a way to test if the build type changed?


I try to create a cache variable with CMAKE_BUILD_TYPE as value but I found an unexpected result: CMAKE_BUILD_TYPE or CMAKE_CONFIGURATION_TYPES are not defined (I'm working on Windows with Visual Studio 2017, Visual Studio Code and Qt Creator).


Thank you,


Romain


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Check Build Type/Config Changed

frodak17


On Sat, Jan 5, 2019 at 11:08 AM Romain LEGUAY <[hidden email]> wrote:

Hi everyone,

 

Is there a way to test if the build type changed?


I try to create a cache variable with CMAKE_BUILD_TYPE as value but I found an unexpected result: CMAKE_BUILD_TYPE or CMAKE_CONFIGURATION_TYPES are not defined (I'm working on Windows with Visual Studio 2017, Visual Studio Code and Qt Creator).


Thank you,



CMAKE_CONFIGURATION_TYPES is used by multi-config generators and CMAKE_BUILD_TYPE isn't used.
CMAKE_CONFIGURATION_TYPES should default to "Debug;Release;MinSizeRel;RelWithDebInfo" for Visual Studio generators unless it was explicitly set to something else.

If you aren't using a multi-config generator then CMAKE_BUILD_TYPE will be empty unless it was set by the user or the CMakeLists.txt sets a default value if empty.

When building with Visual Studio the build type probably could be written to a file using a post-build rule or something like that.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Check Build Type/Config Changed

Romain LEGUAY
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.

Le sam. 5 janv. 2019 à 17:35, frodak17 <[hidden email]> a écrit :


On Sat, Jan 5, 2019 at 11:08 AM Romain LEGUAY <[hidden email]> wrote:

Hi everyone,

 

Is there a way to test if the build type changed?


I try to create a cache variable with CMAKE_BUILD_TYPE as value but I found an unexpected result: CMAKE_BUILD_TYPE or CMAKE_CONFIGURATION_TYPES are not defined (I'm working on Windows with Visual Studio 2017, Visual Studio Code and Qt Creator).


Thank you,



CMAKE_CONFIGURATION_TYPES is used by multi-config generators and CMAKE_BUILD_TYPE isn't used.
CMAKE_CONFIGURATION_TYPES should default to "Debug;Release;MinSizeRel;RelWithDebInfo" for Visual Studio generators unless it was explicitly set to something else.

If you aren't using a multi-config generator then CMAKE_BUILD_TYPE will be empty unless it was set by the user or the CMakeLists.txt sets a default value if empty.

When building with Visual Studio the build type probably could be written to a file using a post-build rule or something like that.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Check Build Type/Config Changed

frodak17


On Sun, Jan 6, 2019 at 10:00 AM Romain LEGUAY <[hidden email]> 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.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake