The options CMake uses for IPO on MSVC can be seen here. It compiles with /GL and links with /INCREMENTAL:NO /LTCG. The Visual Studio generator then sends the flags through this mapping to convert them to the actual .vcxproj content. I think the order of the flags in that mapping may be wrong. You can try hacking that json file in your local installation to switch the two blocks seen in my link.
After looking at the implementation, the Visual Studio generator is not using those places I linked that list LTCG flags. It is directly implementing the INTERPROCEDURAL_OPTIMIZATION target property by generating .vcxproj settings.
same issue here ASAN is incompatible with incremental LTCG
here is my workaround for now
# Set these to ON when including geoproc as a sub CMake project
option(GEOPROC_DISABLE_ASAN "" OFF)
option(GEOPROC_DISABLE_IPO "" OFF)
if (NOT GEOPROC_DISABLE_ASAN)
add_compile_definitions(GEOPROC_ASAN)
if (MSVC)
add_compile_options(/fsanitize=address)
add_link_options(/INCREMENTAL:NO) # Diable incremental linking becauase MSVC ASAN is not compatible with it.
else ()
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_link_options(-fsanitize=address)
endif ()
endif ()
if (NOT GEOPROC_DISABLE_IPO)
# https://web.archive.org/web/20240419204531/https://cliutils.gitlab.io/modern-cmake/chapters/features/small.html#interprocedural-optimization
include(CheckIPOSupported)
check_ipo_supported(RESULT is_ipo_supported)
if (is_ipo_supported)
if (MSVC AND NOT GEOPROC_DISABLE_ASAN)
# Default CMake interprocedural optimization MSVC flags are not compatible with ASAN
# https://gitlab.kitware.com/cmake/cmake/-/issues/20484
add_link_options(/LTCG) # Enable "Link Time Code Generation"
add_compile_options(/GL) # LTCG is useless without "Whole Program Optimization"
add_link_options(/INCREMENTAL:NO) # Disable incremental linking because /LTCG is not compatible with it.
else ()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
endif ()
endif ()