[CMake] Setting COMPILE_FLAGS property on a target in only debug?

Petr Kmoch petr.kmoch at gmail.com
Sat May 5 03:23:40 EDT 2012


Unfortunately, this only works for single-configuration generators
(Makefiles). If you're targetting Visual Studio as well, you're pretty
much out of luck. I see this as one of the major issues with cmake.

A possible workaround is to move the target(s) in question to a
separate CMakeLists.txt included via add_subdirectory(). Then, you can
override the variable CMAKE_<LANG>_COMPILE_FLAGS_DEBUG in that
CMakeList.

Petr

On Fri, May 4, 2012 at 10:40 PM, Tim Gallagher <tim.gallagher at gatech.edu> wrote:
> Put an:
>
> if(CMAKE_BUILD_TYPE STREQUAL "Debug")
> endif()
>
> guard around the set_property call.
>
> Tim
>
> ________________________________
> From: "Robert Dailey" <rcdailey.lists at gmail.com>
> To: "CMake ML" <cmake at cmake.org>
> Sent: Friday, May 4, 2012 4:16:47 PM
> Subject: [CMake] Setting COMPILE_FLAGS property on a target in only debug?
>
>
> I'm doing the following:
>
> set_property( TARGET ${target_name} APPEND_STRING PROPERTY
> COMPILE_FLAGS "/ZI /Gy "
> )
>
> However this applies to all configurations. I want to only set this compiler
> flag for debug builds, not release. How can I do this?
>


More information about the CMake mailing list