0

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
tofucoder
  • 191
  • 1
  • 7
  • In my VS toolchain file I have `SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL:YES" CACHE STRING "" FORCE)`. So I assume `SET(CMAKE_SHARED_LINKER_FLAGS "/INCREMENTAL:YES" CACHE STRING "" FORCE)` should also work, but would overwrite all of CMake's defaults. – Florian Feb 08 '17 at 16:20
  • I figured it out. Since I set `CMAKE_BUILD_TYPE` to `Release`, I had to set `CMAKE_SHARED_LINKER_FLAGS_RELEASE` with `set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/incremental")` – tofucoder Feb 08 '17 at 18:51

1 Answers1

0

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 like CMAKE_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:

set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/INCREMENTAL:YES")

Or you could iterate over the different build configuration specific variables like:

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149