How to enable /INCREMENTAL:YES for release builds

2019-08-06 05:05发布

问题:

I need to use the linker flag /INCREMENTAL:YES when building some libraries with Visual Studio, but cmake seems to insist on using /INCREMENTAL:NO with release builds, and I can't figure out how to fix it. Some of the stuff that I've tried is

set(CMAKE_EXE_LINKER_FLAGS "/INCREMENTAL:YES")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/INCREMENTAL:YES")
set(CMAKE_EXE_LINKER_FLAGS_INIT "/INCREMENTAL:YES")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "/INCREMENTAL:YES")
set(CMAKE_CXX_FLAGS_RELEASE "/INCREMENTAL:YES ${CMAKE_CXX_FLAGS_RELEASE}")

Nothing fixes the problem. As far as I can tell, cmake is just plain hardwired to think that a release build must use /INCREMENTAL:NO. Does anyone know how to fix that and make it use /INCREMENTAL:YES?

回答1:

I've check CMakeCache.txt file and found more flags:

CMAKE_MODULE_LINKER_FLAGS_RELEASE
CMAKE_SHARED_LINKER_FLAGS_RELEASE

But I can't verify my assumption, seems like simply updating CMAKE_EXE_LINKER_FLAGS_RELEASE works fine for me (MSVC 2012, CMake 2.8.10), /INCREMENTAL:NO changed to /INCREMENTAL.