Is there a way to disable incremental linking for Visual Studio 2022

CMake 3.21.3, Windows 10, Visual Studio 2022

I am trying to create executable that I can examine with SizeBench. For that, I need full debug info, and no incremental linking. I’ve tried disabling incremental linking by passing these to my configure script (bat):

cmake ^
    -G "Visual Studio 17 2022" ^
    -A x64 ^
    -Thost=x64 ^
    -B build ^
    -S . ^
    -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ^
    -DCMAKE_EXE_LINKER_FLAGS_DEBUG="/debug /incremental:no" ^
    -DCMAKE_EXE_LINKER_FLAGS_MINSIZEREL="/debug /incremental:no" ^
    -DCMAKE_EXE_LINKER_FLAGS_RELEASE="/debug /incremental:no" ^
    -DCMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO="/debug /incremental:no" ^
    -DCMAKE_STATIC_LINKER_FLAGS_DEBUG="/debug /incremental:no" ^
    -DCMAKE_STATIC_LINKER_FLAGS_MINSIZEREL="/debug /incremental:no" ^
    -DCMAKE_STATIC_LINKER_FLAGS_RELEASE="/debug /incremental:no" ^
    -DCMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO="/debug /incremental:no" ^
    -DCMAKE_SHARED_LINKER_FLAGS_DEBUG="/debug /incremental:no" ^
    -DCMAKE_SHARED_LINKER_FLAGS_MINSIZEREL="/debug /incremental:no" ^
    -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="/debug /incremental:no" ^
    -DCMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO="/debug /incremental:no" ^
    -DCMAKE_MODULE_LINKER_FLAGS_DEBUG="/debug /incremental:no" ^
    -DCMAKE_MODULE_LINKER_FLAGS_MINSIZEREL="/debug /incremental:no" ^
    -DCMAKE_MODULE_LINKER_FLAGS_RELEASE="/debug /incremental:no" ^
    -DCMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO="/debug /incremental:no"

However, the generated solution has in my executable project /INCREMENTAL enabled. Looking inside .vcxproj I can find things like

<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</LinkIncremental>

Can I somehow really disable incremental linking with CMake?

1 Like

For me it worked with all uppercase flags /DEBUG /INCREMENTAL:NO.

My careful guess why this happens: I think CMake uses flags tables like v143_Link.json to parse command line flags and map them to the corresponding MSBuild options and this is probably done in a case-sensitive way. If you provide the flag in lowercase, this parsing/mapping fails and then the fallback value for LinkIncremental is true, see here.

If you think lowercase flags should be recognized as well, maybe you could open a new issue.

Main problem are entries: -DCMAKE_STATIC_LINKER_FLAGS_*.
Static libraries do not have incremental linking, so linker files an error for this switch for static libraries (it should warn this function is not available for this kind of target).