4

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

user1036908
  • 831
  • 1
  • 12
  • 16

4 Answers4

2

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" )
Community
  • 1
  • 1
Mark Garcia
  • 17,424
  • 4
  • 58
  • 94
  • 2
    Hi, I tried this approach and it does not work. Does it work at your end? I also read somewhere that the following line has to be added above project `SET(MSVC_INCREMENTAL_DEFAULT ON) PROJECT(XXX)` Is it correct? – user1036908 Feb 06 '14 at 03:48
  • This does not work. Somewhere deep in the bowels of CMAKE, it sets "/INCREMENTAL:YES" by default and adding "/INCREMENTAL:NO" to CMAKE_EXE_LINKER_FLAGS does not override this. – user168715 Jan 09 '17 at 20:13
2

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 ()
user1036908
  • 831
  • 1
  • 12
  • 16
1

Solution that works for me is:

if(WIN32)
    set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/INCREMENTAL:NO")
endif()
Jakub Jeziorski
  • 173
  • 2
  • 10
1

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()

target_link_options docs

hamaney
  • 454
  • 7
  • 16