[CMake] modifying cmake_build_type cflags per target

Eric Doenges doenges at mvtec.com
Tue Nov 19 06:35:01 EST 2019


Am 19.11.19 um 12:09 schrieb Stéphane Ancelot:
>
> Hi,
>
> I have a particular target (using swig / jni) that must not have -O3 
> -NDEBUG flags from Relase build type
>
> How can I overload this target flags ?
>
Since CMAKE_<lang>_FLAGS_RELEASE does not map to a user-visible target 
property, you cannot override it directly (anything added to the 
COMPILE_FLAGS property is appended to the command line and does not 
replace any of the compiler flags CMake sets by itself). However, you 
can redefine this variable before you create your special target(s), and 
then restore it so that other targets are not affected:

set(_CMAKE_CXX_FLAGS_RELEASE_SAVE ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE)
< add your target(s) here >
set(CMAKE_CXX_FLAGS_RELEASE ${_CMAKE_CXX_FLAGS_RELEASE_SAVE})

This assumes your target is C++; if it is C, simply replace the _CXX_ 
with _C_.

-- 

*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/20191119/d44f7863/attachment.html>


More information about the CMake mailing list