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

Stephen Kelly steveire at gmail.com
Mon May 7 13:42:00 EDT 2012


Robert Dailey wrote:

> On Mon, May 7, 2012 at 10:37 AM, Robert Dailey
> <rcdailey.lists at gmail.com>wrote:
> 
>> On Sat, May 5, 2012 at 5:34 AM, Michael Wild
>> <themiwi at gmail.com> wrote:
>>
>>> On 05/04/2012 10:16 PM, Robert Dailey wrote:
>>> > 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?
>>> >
>>>
>>> Can you misuse the COMPILE_DEFINITIONS_DEBUG property? Should work,
>>> IMHO.
>>
>>
>> I can try it as a hack/workaround, but I would prefer to use the "right
>> tool for the job". Perhaps this would make a good feature request. I
>> definitely need this to work for Visual Studio, so I can't assume the
>> build configuration is known at generation time in CMake.
>>
> 
> I just tried your workaround and it does not work. It places everything in
> my preprocessor definitions field, not actually on the command line.
> 
> I'm going to desperately need configuration-aware COMPILE_FLAGS, because
> in Visual Studio, I have cache variables that enable certain features,
> like edit & continue, minimal rebuild, etc... features that are not
> compatible with /O2 (optimizations on). Since CMake has no choice but to
> enable these MSVC features in all configurations, my release builds don't
> work, and the user will be required to disable these features via cache
> variable every time they want to build release, which is unnecessary.
> 
> If no one has the bandwidth to take up this feature I suppose I could look
> into it. Anyone have any tips on how to implement this before I dive into
> the CMake code?

If I've  understood you I think the solution to a super-set of your problem 
is already under discussion:

http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/3615

Thanks,

Steve.




More information about the CMake mailing list