[CMake] Visual Studio library link flags

Simon Sasburg simon.sasburg at gmail.com
Sat Oct 4 04:20:55 EDT 2008


In my application i have 1 executable target, and a number of static
support libaries.
Often when linking the support libraries, visual studio gives me the
following warning:

MSIL .netmodule or module compiled with /GL found; restarting link
with /LTCG; add /LTCG to the link command line to improve linker
performance

When, in visual studio, i go to the properties of the library, and add
/LTCG to "Configuration Properties"->"Librarian"->"Command
Line"->"Additional Options", the warning goes away.

But, i want to do this from the CMakeLists.txt, preferably just in 1
place and not once for each library.
I tried something like this but it doesn't work:
SET(CMAKE_MODULE_LINKER_FLAGS_RELEASE
"${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG")

For compiling and linking executables the following lines DO work:
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")

So, how do i add flags to the (static) library link command line with cmake?

(I'm using MSVC 2008 Express and CMake 2.6.2)


More information about the CMake mailing list