I build a shared library with CMake and the Ninja generator on Windows. I'd like to use incremental linking to reduce the time required for linking.
I tried to set CMAKE_SHARED_LINKER_FLAGS
to "/incremental"
but this flag is always overridden by a "/INCREMENTAL:NO"
which is appended by CMake.
I also tried to set MSVC_INCREMENTAL_DEFAULT
to ON
, but this didn't have any effect.
So how can I get incremental linking working with CMake and the Ninja generator?
Turning my comment into an answer
I use a similar
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL:YES" CACHE STRING "" FORCE)
in my VS toolchain file.Be aware that CMake does combine/append its linker flags out of the general e.g.
CMAKE_SHARED_LINKER_FLAGS
and the build type specific parts likeCMAKE_SHARED_LINKER_FLAGS_RELEASE
.So you have to either find out where CMake does set
/INCREMENTAL:NO
for shared libraries - as you and I have done - and overwrite it with:Or you could iterate over the different build configuration specific variables like: