[CMake] printing CMAKE_CXX_FLAGS_* based on build type

Craig Scott craig.scott at crascit.com
Fri Sep 27 18:57:18 EDT 2019


On Sat, Sep 28, 2019 at 8:15 AM Zdenko Podobny <zdenop at gmail.com> wrote:

> Yes, build type is known (e.g   value of ${CMAKE_BUILD_TYPE}  is shown in
> output).  I use command like this:
> cmake .. -G Ninja  -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR%
> -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_BUILD_TYPE=Release
>
>
> Zdenko
>
>
> pi 27. 9. 2019 o 23:54 fdk17 <fdk17 at ftml.net> napísal(a):
>
>> Are you using a generator that uses CMAKE_BUILD_TYPE and has it set to a
>> known value?  Build type doesn’t have to be set and multi-config generators
>> don’t use it.
>>
>> On Fri, Sep 27, 2019, at 4:18 PM, Zdenko Podobny wrote:
>>
>> 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}}")
>>
>>
CMake variable names are case-sensitive. The value of CMAKE_BUILD_TYPE is
likely not all uppercase, so ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}} will
almost certainly end up naming a variable that isn't defined.

Also, as fdk17 has already mentioned, CMAKE_BUILD_TYPE isn't always
defined. For multi-configuration generators (e.g. Visual Studio, Xcode), it
typically won't be defined and if it was, it would be meaningless. If you
have logic switching on CMAKE_BUILD_TYPE, it is usually a sign you are
trying to do something you shouldn't (or that you explicitly don't support
multi-config generators).



>
>> 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
>>
>>

-- 
Craig Scott
Melbourne, Australia
https://crascit.com

Get the hand-book for every CMake user: Professional CMake: A Practical
Guide <https://crascit.com/professional-cmake/>
Consulting services (CMake, C++, build/release processes):
https://crascit.com/services
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190928/ab5de932/attachment.html>


More information about the CMake mailing list