[CMake] Different CMAKE_CXX_FLAGS for different executables
Michael Hertling
mhertling at online.de
Fri Mar 25 00:10:40 EDT 2011
On 03/24/2011 03:44 PM, David Doria 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?
AFAIK, CMAKE_CXX_FLAGS et al. are special in as much as the last value
they receive within a CMakeLists.txt file is effective for all targets
defined in that file, i.e. they undergo a kind of lazy evaluation. So,
the answer to your question is: No, you can't specify CMAKE_CXX_FLAGS
individually for targets within the same CMakeLists.txt, but you can
specify them per directory, i.e. individually in each CMakeLists.txt.
Nevertheless, CMAKE_CXX_FLAGS should be considered as project-wide
settings, IMO.
> 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")
>
> ?
See [1] for a consideration of SET() w.r.t. the cache and scopes.
> In this example: http://codepad.org/PGJRBjss [...]
ATM, that site seems to be offline. Could you post the example here?
Regards,
Michael
[1] http://www.mail-archive.com/cmake@cmake.org/msg29869.html et seq.
More information about the CMake
mailing list