vscode-cmake-tools
vscode-cmake-tools copied to clipboard
Add support for CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES and CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
If I include in CMakeLists.txt lines:
LIST(APPEND CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "SomePathToDir")
LIST(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "SomePathToDir")
then i would expect that header C/C++ files inside these directories will be searched for when included in regular .C/.CPP source files for example:
#include "header.h"
and header.h will be in SomePathToDir then VS Code will not complain that file header.h is missing. I know that this requirer integration with C/C++ Microsoft extension.
Just use target_include_directories() for that. It should work.
I normally would - but these include dirs are some kind of system includes added by cross compiler (yes I am talking here about cross-compilation with custom toolchain.cmake file) - if i add them by target_include_directories() then they will be double added by compiler and by compiler args - and the program will not compile (because cross compiler adds them in a special way). These vars CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES and CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES are only for IDE to not to complain that for example #include <stdio.h> is not in include path.
https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.html
Oh, didn't realize that. But I don't think that this is an issue with CMake Tools, since intellisense/linting is provided by the cpp extension.
From my understanding CMake Tools works with C/C++ Microsoft extension - so maybe there is a need of cooperation to make this as feature of both C/C++ Microsoft extension and CMake Tools.
Can you tell us which compiler are you using and which system paths are missing? I'm wondering why the compiler doesn't report the necessary paths to cpptools when it queries it (i.e. this only works for GCC/clang/MSVC compilers right now).
Are you adding those lines to your CMake with the intent that it will make cpptools integration will work, or is there some other purpose?
@lmatusz, we are triaging this with a lower priority for the moment, considering only the 'nice to have' support of the mentioned CMake variables. Depending on your reply to the above questions that @bobbrow asked, we may realize that there are other issues happening and we will address those faster, depending on their severity. We are hoping that you are working with latest CMake Tools extension and that you are unblocked by now.
I need this also ....
Can you tell us which compiler are you using and which system paths are missing? I'm wondering why the compiler doesn't report the necessary paths to cpptools when it queries it (i.e. this only works for GCC/clang/MSVC compilers right now).
Are you adding those lines to your CMake with the intent that it will make cpptools integration will work, or is there some other purpose?
Mentioned upper vars set directories for cmake extensions like cpptools to not to blame that some include defines are not met (not resolved). It will make cpptools integration work better.
Expert from cmake.org: " CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES Directories implicitly searched by the compiler for header files.
CMake does not explicitly specify these directories on compiler command lines for language <LANG>. This prevents system include directories from being treated as user include directories on some compilers, which is important for C, CXX, and CUDA to avoid overriding standard library headers.
This value is not used for Fortran because it has no standard library headers and some compilers do not search their implicit include directories for module .mod files. "
Sorry for such late late late reply. Currently I am starting to fight with https://github.com/microsoft/MIEngine/issues/1227 which is also housed at mighty Microsoft. Again sorry ;(
(some notes for us)
Doing some tests, it appears that when added in CMakeLists.txt as in the first message in this thread, the implicit paths appear in the 'toolchains' json file of the file-api under toolchains[].compiler.implicit.includeDirectories[]. They do not appear in the cache. When specified as a cacheVariable in a CMakePresets.json file, they appear in the CMakeCache.txt, not the file-api.
It should be safe to send these extra paths to cpptools for IntelliSense purposes. Duplicates will be automatically removed.
defining
"environments": [
{
"include": "${env.INCLUDE};path/to/headers"
}
],
in CMakeSettings.json also seems to be working, for those who are searching for workarounds