MSVC Incremental linking with CMake and the Ninja

2019-06-13 20:44发布

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?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-06-13 21:11

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:

查看更多
登录 后发表回答