[CMake] Link flags not applied to static library
Ben Medina
ben.medina at gmail.com
Mon Jun 13 14:50:35 EDT 2011
Hello all,
I'm using CMake 2.8.4 and am seeing an odd differenc between static
and shared libraries in regard to the LINK_FLAGS property. In
particular, I'm enabling "Whole program optimization" in Visual Studio
2010, which is done by add /GL as a compiler flag and /LTCG as a
linker flag for the release configuration. However, the link flag is
not used for static libraries, leading to a build warning about
compiling with /GL but linking without /LTCG.
Here's an example:
cmake_minimum_required (VERSION 2.8)
project (link_test)
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
add_library (static_test STATIC a.cpp)
set_target_properties (
static_test
PROPERTIES
LINK_FLAGS_RELEASE "/LTCG"
)
add_library (shared_test SHARED a.cpp)
set_target_properties (
shared_test
PROPERTIES
LINK_FLAGS_RELEASE "/LTCG"
)
Just add an empty file called a.cpp to the directory, then build the
whole project in release configuration. You'll get a warning like this
for the static_test library:
2> a.obj : MSIL .netmodule or module compiled with /GL found;
restarting link with /LTCG; add /LTCG to the link command line to
improve
Why is CMake not applying LINK_FLAGS_RELEASE to the static library?
Thanks,
Ben
More information about the CMake
mailing list