printing CMAKE_CXX_FLAGS_* based on build type

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

printing CMAKE_CXX_FLAGS_* based on build type

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

--

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: printing CMAKE_CXX_FLAGS_* based on build type

fdk17
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}}")

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

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



--

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: printing CMAKE_CXX_FLAGS_* based on build type

Zdenko Podobny
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 <[hidden email]> 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}}")

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

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:


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

Follow this link to subscribe/unsubscribe:


--

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

--

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: printing CMAKE_CXX_FLAGS_* based on build type

Craig Scott-3


On Sat, Sep 28, 2019 at 8:15 AM Zdenko Podobny <[hidden email]> 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 <[hidden email]> 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

Get the hand-book for every CMake user: Professional CMake: A Practical Guide
Consulting services (CMake, C++, build/release processes): https://crascit.com/services

--

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: printing CMAKE_CXX_FLAGS_* based on build type

Eric Doenges
In reply to this post by Zdenko Podobny

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
[hidden email] | Tel: +49 89 457 695-0 | www.mvtec.com

Find our privacy policy here.

 Sign up for our MVTec Newsletter!

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

 

MVTec Software GmbH Logo

--

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