# CMAKE\_IPO\_ISSUE msvc (/LTCG:incremental)

**URL:** https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826
**Category:** Development
**Tags:** os:windows, comp:msvc
**Created:** [March 20, 2020, 3:29am UTC](https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826 "2020-03-20T03:29:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [March 20, 2020, 3:29am UTC](https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826/1 "2020-03-20T03:29:38Z")

</div>

I’ve create a public github to demonstrate this issue.

> **[hdf89shfdfs/cmake\_ipo\_issue](https://github.com/hdf89shfdfs/cmake_ipo_issue)**
>
> Contribute to hdf89shfdfs/cmake\_ipo\_issue development by creating an account on GitHub.

```auto
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)

```

The code above turns on LTO but not in an always desirable fashion.

It sets /LTCG to be INCREMENTAL. Which isn’t what I want for release configs.

I might want INCREMENTAL for debug, relwithdebinfo, etc. But not release. But it looks like I have no control over it.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [March 20, 2020, 3:31am UTC](https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826/2 "2020-03-20T03:31:02Z")

</div>

This issue is Windows MSVC specific.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [March 20, 2020, 10:58am UTC](https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826/3 "2020-03-20T10:58:01Z")

</div>

The options CMake uses for IPO on MSVC can be [seen here](https://gitlab.kitware.com/cmake/cmake/-/blob/v3.16.5/Modules/Platform/Windows-MSVC.cmake#L352-355). It compiles with `/GL` and links with `/INCREMENTAL:NO /LTCG`. The Visual Studio generator then sends the flags through [this mapping](https://gitlab.kitware.com/cmake/cmake/-/blob/v3.16.5/Templates/MSBuild/FlagTables/v142_Link.json#L255-268) 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.

Please open an issue for this on the [CMake Issue Tracker](https://gitlab.kitware.com/cmake/cmake/issues).

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [March 20, 2020, 12:25pm UTC](https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826/4 "2020-03-20T12:25:01Z")

</div>

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.

Either way, please open an issue for this.

---

<div class="post-metadata">

### Author: ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)
#### Post date: [March 20, 2020, 5:32pm UTC](https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826/5 "2020-03-20T17:32:30Z")

</div>

I’ve created the issue for this.

[https://gitlab.kitware.com/cmake/cmake/issues/20484](https://gitlab.kitware.com/cmake/cmake/issues/20484)

I’ve also been having this issue.

Thanks [hdf89shfdfs](https://discourse.cmake.org/u/hdf89shfdfs) 🙂

---

<div class="post-metadata">

### Author: ![esnosy](https://discourse.cmake.org/user_avatar/discourse.cmake.org/esnosy/32/4450_2.png) [@esnosy](https://discourse.cmake.org/u/esnosy)
#### Post date: [April 26, 2024, 2:17pm UTC](https://discourse.cmake.org/t/cmake-ipo-issue-msvc-ltcg-incremental/826/6 "2024-04-26T14:17:16Z")

</div>

same issue here ASAN is incompatible with incremental LTCG ☹

here is my workaround for now

```cmake
# 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 ()

```
