Reputation: 861
I am using cmake 2.8.0 to build my VS2012 solution that has multiple projects. For each project, I wish to set the properties->Linker-> Enable Incremental Linking to NO for each project.
There are flags such as CMAKE_EXE_LINKER_FLAGS_DEBUG that can probably be used. I am not sure though, tried some online help as well to no effect.
Please advise
Upvotes: 5
Views: 8311
Reputation: 498
Checking WIN32
is not enough. The flag only means that the target system is Windows.
So, in case we are building with GCC
or any other compiler on Windows, the flag /INCREMENTAL
would fail because it is MSVC
specific.
for CMake >= 3.13 this should do it.
if(MSVC)
target_link_options(${TARGET_NAME} <INTERFACE|PUBLIC|PRIVATE>
# $<$<CONFIG:Debug>:/INCREMENTAL> is active by default for debug
$<$<CONFIG:Release>:/INCREMENTAL:NO>
)
endif()
Upvotes: 1
Reputation: 193
Solution that works for me is:
if(WIN32)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/INCREMENTAL:NO")
endif()
Upvotes: 1
Reputation: 861
I managed to find the solution. Apparently a lot of other flags also need to be set to /INCREMENTAL:NO
FOREACH(FLAG_TYPE EXE MODULE SHARED)
STRING (REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" FLAG_TMP
"${CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG}")
STRING (REPLACE "/EDITANDCONTINUE" "" FLAG_TMP
"${CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG}")
SET(CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG "/INCREMENTAL:NO ${FLAG_TMP}" CACHE
STRING "Overriding default debug ${FLAG_TYPE} linker flags." FORCE)
MARK_AS_ADVANCED (CMAKE_${FLAG_TYPE}_LINKER_FLAGS_DEBUG)
ENDFOREACH ()
Upvotes: 2
Reputation: 17708
You should set the /INCREMENTAL:NO
linker flag.
To override it in CMake, you should follow the techniques provided in How to add linker or compile flag in cmake file?:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /INCREMENTAL:NO" )
Upvotes: 2