# Imported projects don't resolve include paths in intellisense

**URL:** <https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185>\
**Category:** Code\
**Created:** [October 12, 2023, 2:58am UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185 "2023-10-12T02:58:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tombrownridge](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tombrownridge/32/3918_2.png) [@tombrownridge](https://discourse.cmake.org/u/tombrownridge)\
**Post date:** [October 12, 2023, 2:58am UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/1 "2023-10-12T02:58:02Z")

</div>

When I create an **imported** project and generate for MSVC, the include paths are specified with additional options `<AdditionalOptions>/external:I "/path/to/my/external/"</AdditionalOptions>`, which then doesn’t allow intellisense to find the imported headers. On the contrary, **interface** targets generate `<AdditionalIncludeDirectories>path/to/my/external/</AdditionalIncludeDirectories>`, which do work with intellisense.

Is there a way to achieve an imported target that specifies `AdditionalIncludeDirectories` instead, so that our intellisense can work?

PS - Editing MSVC.cmake and removing the lines about `CMAKE_INCLUDE_SYSTEM_FLAG_` have exactly the effect I’m looking for. I wonder if it should also be conditional on a policy? Using CMake 3.24.0.

PPS - the following solved my problem near the top of my CMakeLists.txt file:  
`unset(CMAKE_INCLUDE_SYSTEM_FLAG_CXX)`  
`unset(_CMAKE_INCLUDE_SYSTEM_FLAG_CXX_WARNING)`

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 12, 2023, 12:31pm UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/2 "2023-10-12T12:31:46Z")

</div>

What versions of CMake, MSVC, and Visual Studio are involved here?

---

<div class="post-metadata">

**Author:** ![tombrownridge](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tombrownridge/32/3918_2.png) [@tombrownridge](https://discourse.cmake.org/u/tombrownridge)\
**Post date:** [October 16, 2023, 2:32pm UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/3 "2023-10-16T14:32:58Z")

</div>

cmake 3.24.0  
Microsoft Visual Studio 16.11.30  
MSVC 19.29.30152.0

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 16, 2023, 2:57pm UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/4 "2023-10-16T14:57:27Z")

</div>

Hrm. It looks like this was added in [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/7238](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7238). I suspect that IntelliSense needs to learn about how to use these flags, but maybe an option could be added?

Cc: @brad.king

---

<div class="post-metadata">

**Author:** ![tombrownridge](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tombrownridge/32/3918_2.png) [@tombrownridge](https://discourse.cmake.org/u/tombrownridge)\
**Post date:** [October 16, 2023, 3:03pm UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/5 "2023-10-16T15:03:03Z")

</div>

Yes, that sure looks the the right MR. I’ve been looking for some documentation from MS that relates to /external:I and the behavior of intellisense, but no luck. I presume MS’s intent was that that headers in external include paths don’t show up in intellisense? I’m still playing with visual studio settings to see if I can find a workaround on the MS side of the equation.

---

<div class="post-metadata">

**Author:** ![tombrownridge](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tombrownridge/32/3918_2.png) [@tombrownridge](https://discourse.cmake.org/u/tombrownridge)\
**Post date:** [October 16, 2023, 3:36pm UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/6 "2023-10-16T15:36:04Z")

</div>

I’ve been through both project and IDE options lists with respect to external libraries and intellisense, and I can find no way to instruct intellisense that it should process external libraries.

There are two workarounds I’ve been able to succeed with:

1. Unset `CMAKE_INCLUDE_SYSTEM_FLAG_CXX` and `_CMAKE_INCLUDE_SYSTEM_FLAG_CXX_WARNING` near the top of my CMakeLists.txt, which effectively negates MR 7238 cited above, or
2. Add the same path that appears in `/external:I` again in the normal include paths via `/I`.

I can see use cases for MR 7238, but being unconditionally railroaded into that new behavior is a breaking change for my project. I’d like to see the ability to turn it off either wholesale, or for specific imported projects. In the meantime, I have these workarounds.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 16, 2023, 6:37pm UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/7 "2023-10-16T18:37:39Z")

</div>

FWIW, tooling around the compiler is not generally considered when implementing features. For example, `clang-cl` did not understand `-external:I` when first added, so `clangd`-based tooling choked on the flag when we first implemented the MSVC support and the flags showed up in the `compile_commands.json` files. Note that there might be some leeway here given how tightly integrated IntelliSense is to Visual Studio, but I think the core problem is that IntelliSense doesn’t understand the flags that the target compiler supports. I suggest at least contacting Microsoft to handle this regardless of how CMake ends up resolving this.

---

<div class="post-metadata">

**Author:** ![tombrownridge](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tombrownridge/32/3918_2.png) [@tombrownridge](https://discourse.cmake.org/u/tombrownridge)\
**Post date:** [October 17, 2023, 1:35am UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/8 "2023-10-17T01:35:02Z")

</div>

I tried the Microsoft documentation project here: [Impacts on intellisense/autocomplete? · Issue #4769 · MicrosoftDocs/cpp-docs · GitHub](https://github.com/MicrosoftDocs/cpp-docs/issues/4769), but your prompting caused me to look one more time and I found what looks like a fix from MS: [Developer Community](https://developercommunity.visualstudio.com/t/Go-To-Document-F12-for-C-include/1191078). I intend to give it a shot and let you know how it turns out.

---

<div class="post-metadata">

**Author:** ![tombrownridge](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tombrownridge/32/3918_2.png) [@tombrownridge](https://discourse.cmake.org/u/tombrownridge)\
**Post date:** [October 17, 2023, 3:10am UTC](https://discourse.cmake.org/t/imported-projects-dont-resolve-include-paths-in-intellisense/9185/9 "2023-10-17T03:10:12Z")

</div>

As advertised in the link above, Microsoft fixed this problem in VS 2022. I also confirmed that its not fixed in VS 2019 (Version 17.6.4) , nor do I suspect they will go back and fix VS 2019.
