MSVC Incremental linking with CMake and the Ninja generator

丶灬走出姿态 提交于 2019-12-10 12:28:02

问题


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:


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:

  • CMake compile with /MT instead of /MD
  • CMake: How to set a preprocessor define for all build configurations except one ?


来源:https://stackoverflow.com/questions/42117149/msvc-incremental-linking-with-cmake-and-the-ninja-generator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!