[CMake] Different CMAKE_CXX_FLAGS for different executables

David Doria daviddoria at gmail.com
Thu Mar 24 11:06:05 EDT 2011


On Thu, Mar 24, 2011 at 10:44 AM, David Doria <daviddoria at gmail.com> wrote:
> Is there a way to explicitly set the CMAKE_CXX_FLAGS for a particular
> executable? That is, if I set CMAKE_CXX_FLAGS and then have a
> add_executable line, then change CMAKE_CXX_FLAGS and then have another
> add_executable, will the first set of CMAKE_CXX_FLAGS be applied to
> the first executable and the second set of CMAKE_CXX_FLAGS be applied
> to the second executable?
>
> I guess my confusion is that I don't understand how CMake variables are cached.
>
> Each time I modify the variable, should I do it using
>
> SET(CMAKE_CXX_FLAGS "some flags")
>
> or
>
> SET(CMAKE_CXX_FLAGS "some flags" CACHE STRING "compiler flags")
>
> ?
>
> In this example: http://codepad.org/PGJRBjss the messages are actually
> not displayed at all, which is only adding to my confusion :)
>
> Any comments on this?
>
> Thanks,
>
> David
>

Scratch that last part, I was looking in the wrong place in my IDE.
The output is:

Using flags
Using flags

when I would expect:

Using flags Flags1
Using flags Flags2

Can anyone explain this?

David


More information about the CMake mailing list