[CMake] Are CMAKE_CXX_FLAGS supposed to go on the link line?

Paul Smith paul at mad-scientist.net
Thu Jan 8 18:52:01 EST 2015


It seems different generators are handling this differently, which is
frustrating (I've tried with both CMake 3.1.0 and 2.8.12.2)... or else
there's something very bizarre about my cmake files.

The new doc layout looks nice, but it really needs an infusion of
detail.  Here's the doc for CMAKE_CXX_FLAGS:

http://www.cmake.org/cmake/help/v3.1/variable/CMAKE_LANG_FLAGS.html

which isn't so helpful for my question :-).

If I'm on OSX, then when I set CMAKE_CXX_FLAGS and do not set
CMAKE_EXE_LINKER_FLAGS, for example, and I use the Xcode generator, then
I see:
      * CMAKE_CXX_FLAGS show up on the compilation line
      * CMAKE_CXX_FLAGS do NOT show up in the linker line

On the other hand if I'm on OSX and I use the Unix Makefiles generator,
then I see:
      * CMAKE_CXX_FLAGS show up on the compilation line
      * CMAKE_CXX_FLAGS ALSO show up in the linker line

I assume the Xcode output is correct and the makefile output (with
CMAKE_CXX_FLAGS in both) is not correct... but there's nothing I can
find in the docs that says this explicitly.

I've printed the contents of the CMAKE_CXX_FLAGS and
CMAKE_EXE_LINKER_FLAGS at the end of my CMakeLists.txt and they're just
what I expect.  It's just that the link line has extra flags, when
invoked from make.

Can anyone else reproduce this?



More information about the CMake mailing list