[CMake] printing CMAKE_CXX_FLAGS_* based on build type

Eric Doenges doenges at mvtec.com
Mon Sep 30 01:39:34 EDT 2019


Unfortunately, the standard values for CMAKE_BUILD_TYPE only have their 
first letter capitalized, i.e. for a release build CMAKE_BUILD_TYPE will 
normally be "Release". To use it like you want to, it would need to be 
"RELEASE". To get around this problem, we define an all upper-case 
BUILD_TYPE in our projects, i.e.:

string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
message(STATUS "CXX compiler ${CMAKE_BUILD_TYPE} build options: 
${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}")

If you do this, keep in mind what fdk17 said - CMAKE_BUILD_TYPE may not 
be set depending on the generator you use.

Am 27.09.19 um 22:18 schrieb Zdenko Podobny:
> Hello,
>
> I try to print CMAKE_CXX_FLAGS_DEBUG/CMAKE_CXX_FLAGS_RELEASE as one 
> line statement but is does not work for me:
>
> message( STATUS "CXX compiler ${CMAKE_BUILD_TYPE} build options: 
> ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}")
>
> Produce empy result, but
> message( STATUS "CXX compiler  Release build options: 
> ${CMAKE_CXX_FLAGS_RELEASE}")
> works as expected.
> Is it possible to do it in one line or I have to use if/elseif ?
>
> Zdenko
>
-- 

*Dr. Eric Dönges*
Senior Software Engineer

MVTec Software GmbH | Arnulfstr. 205 | 80634 Munich | Germany
doenges at mvtec.com <mailto:mustermann at mvtec.com> | Tel: +49 89 457 695-0 
| www.mvtec.com <http://www.mvtec.com>

Find our privacy policy here <https://www.mvtec.com/imprint>.

Sign up <https://www.mvtec.com/newsletter> for our MVTec Newsletter!

Geschäftsführer: Dr. Wolfgang Eckstein, Dr. Olaf Munkelt
Amtsgericht München HRB 114695

MVTec Software GmbH Logo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190930/b3520a29/attachment.html>


More information about the CMake mailing list