Why does IntelliSense not find system headers (e.g. `string`) of custom cross toolchains when using CMake?
I would like to use Visual Studio 2019 (Version 16.9.4) to develop Linux applications for a custom embedded board with a custom toolchain and CMake. To achieve this, I created a CMake toolchain file and passed it via the cmakeToolchain
option in CMakeSettings.json
. CMake chooses the correct toolchain during build system generation (generator is Ninja) and can build the project succesfully.
However, IntelliSense does not work as expected. If I set inheritEnvironments
to something like linux_arm
, then IntelliSense uses the system headers (e.g. string
) associated to this environment (e.g. C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\VC\Linux\include\usr\include\c++\5\string
). This are not the headers from the configured toolchain.
If I do not set inheritEnvironments
to anything (i.e. pass an empty array), then the system header are not found at all and IntelliSense basically stops working.
I followed the recommendations from https://devblogs.microsoft.com/cppblog/configure-intellisense-with-cmake-toolchain-files-in-visual-studio-2019-16-9-preview-2/ and set intelliSenseMode
to linux-gcc-arm
, but that did not change anything (meaning that the system headers are still not found at all). The toolchain file configures CMAKE_C_COMPILER
and CMAKE_CXX_COMPILER
, so it should have worked. Just to make sure, I set useCompilerDefaults
to true
under intellisenseOptions
. Still, no change.
Here is the content of the toolchain file:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
The compiler is available on PATH and Visual Studio correctly expands the path to its absolute path in CMakeCache.txt
.
The content of CMakeSettings.json
is
{
"configurations": [
{
"name": "aarch64-linux-gnu_Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"cmakeToolchain": ".cmake_toolchain_definitions/aarch64-linux-gnu.cmake",
"inheritEnvironments": [],
"intelliSenseMode": "linux-gcc-arm",
"intellisenseOptions": {"useCompilerDefaults": true}
}
]
}
What can I do to make IntelliSense work and find the correct system headers of the custom toolchain?