Closed atar-axis closed 5 years ago
CMake servers 'codemodel
does in fact hold a list of includes, even the propagated ones of sub-projects:
...
{
"buildDirectory":"/home/flood/work/fortiss/ff1/ff1_selfcheck/build",
"hasInstallRule":true,
"minimumCMakeVersion":"3.0",
"name":"ff1_selfcheck",
"sourceDirectory":"/home/flood/work/fortiss/ff1/ff1_selfcheck",
"targets":[
{
"artifacts":[
"/home/flood/work/fortiss/ff1/ff1_selfcheck/build/ff1_selfcheck"
],
"buildDirectory":"/home/flood/work/fortiss/ff1/ff1_selfcheck/build",
"fileGroups":[
{
"compileFlags":" -Wall -g -Wfatal-errors -std=gnu++11",
"includePath":[
{
"path":"/home/flood/work/fortiss/ff1/ff1_selfcheck/subs/yaml-cpp/include"
},
{
"path":"/home/flood/work/fortiss/ff1/ff1_selfcheck/subs/brick/source"
},
{
"path":"/home/flood/work/fortiss/ff1/ff1_selfcheck/subs/af3pihal/inc"
}
],
"isGenerated":false,
"language":"CXX",
"sources":[
"src/main.cpp",
"src/BrickChecker.cpp",
"src/DeviceFileChecker.cpp",
"src/ErrorDisplay_7seg.cpp",
"src/ErrorDisplay.cpp",
"src/ErrorDisplay_LEDButton.cpp",
"src/NetworkChecker.cpp",
"src/ConfigParser.cpp"
]
}
],
"fullName":"ff1_selfcheck",
"isGeneratorProvided":false,
"linkFlags":"-rdynamic",
"linkLibraries":"subs/yaml-cpp/libyaml-cpp.a subs/brick/libbrick.a subs/af3pihal/libaf3pihal.a -lpthread",
"linkerLanguage":"CXX",
"name":"ff1_selfcheck",
"sourceDirectory":"/home/flood/work/fortiss/ff1/ff1_selfcheck",
"type":"EXECUTABLE"
},
...
I don't know if you can easily communicate to the IntelliSense-Service, but if yes, then it should be easy to simply add those paths :)
See the add_cpp_provider branch. ;-) is my nr1 priority. I'll find some Time this Weekend, it is not so complecated. Just need to add some Code for the cmake cache to get the compiler and c/cpp Standard.
But its not ready for testing yet. Still work in progress.
Aiii, perfect coincidence :grin: let me know if I can help you somehow or when it's ready for testing and thanks for your efforts once again :wink:
Just need to add some Code for the cmake cache to get the compiler and c/cpp Standard.
Isn't that also available from the codemodel
? :)
So the code is ready. But there seems to be a bug in vscode-cpp extension. Bug I have to find some way around it.
nice - thank you! I guess the bug does only show up when I open my files to early - right? can you share the .vsix with me?
cheers!
Hi, I found the bug in my code. I published a new version v0.3.0. Happy Testing. I'll add some code later to support intellisense for include files and source files not added to cmake yet.
Perfect, works like a charm so far :) Thank you very very much!
I am sorry, I was wrong - since 0.3.0 the extension doesn't start up anymore in VScode Insiders. That means: No statusbar, no commands to run, and no added Intellisense paths.
Pls check v0.3.1, this was a hard one... I missed a dependency in the release which was only a dev dependency. But vscode didn't report any error. There are also some issues with windows I have to resolve.
Also note, there is a bug in vscode insiders in the extension api, so that all kind of cmake files get found and tried to use. So it might be unuseable.
Aii, I downloaded the normal version and updated CMake-Integration, the status bar is back but the includes do not yet work Is there some debug output I can provide to you?
Two issue are open:
Do you hit one of those? Or is it a regular source file on linux/mac?
I am on linux, and e.g. yaml-cpp
is imported as a subproject via
So this is most probably #7, eh?
btw, thank you very much for all your efforts! think about a donation button - like https://ko-fi.com/ :P
If the target has a target include dir, it should be there. Can you check the log of the output (ausgabe) of "C/C++" it should show you the information it has got from the extension.
The CMakeLists.txt in the base directory is:
# use modern target-based cmake features
cmake_minimum_required(VERSION 3.0)
# global compiler settings (propagated to subs!!!)
add_definitions(-Wall -g -Wfatal-errors)
# projectname
project(ff1_selfcheck)
## TODO: unfortunately the toolchain is somehow not propagated to some test subs of yaml-cpp,
## therefore we disable test-cases completely for now.
## A better solution would be to ensure that even the test subs use the given toolchain
set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Disable testing" FORCE)
# add sub directories to CMake build-tree
add_subdirectory(subs/yaml-cpp)
add_subdirectory(subs/brick)
add_subdirectory(subs/af3pihal)
# executable to create
add_executable(${PROJECT_NAME}
src/main.cpp
src/peripherals/DeviceFile.cpp
src/peripherals/Brick.cpp
src/peripherals/Network.cpp
src/errout/ErrorDisplay_7seg.cpp
src/errout/ErrorDisplay_Pipe.cpp
src/errout/ErrorDisplay_LEDButton.cpp
src/errout/ErrorDisplay_Server.cpp
)
# link libraries
target_link_libraries(${PROJECT_NAME}
PRIVATE
yaml-cpp # imported target
brick # imported target
af3pihal # imported target
pthread # system lib
#boost_program_options
)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
I just did a quick test with an example setup and it work with yaml-cpp to add the subdirectory and then set the target_link_libraries. The output off c++ should look like this:
Custom configurations received:
uri: file:///home/chris/Coding/cmake-test/src/main.cpp
config: {
"compilerPath": "/usr/bin/c++",
"defines": [],
"includePath": [
"/home/chris/Coding/cmake-test/3rd/include"
],
"standard": "c++14",
"intelliSenseMode": "gcc-x64"
}
Can you check that your config has C_Cpp.autocomplete
set to "Default" and run the command (strg+shift+p) "reset database" and try to reopen the file, the cpptools extension is quite buggy...
If you see a lines like:
sending compilation args for /home/chris/Coding/cmake-test/src/test.cpp
include: /usr/include/c++/8.2.1
include: /usr/include/c++/8.2.1/x86_64-pc-linux-gnu
include: /usr/include/c++/8.2.1/backward
include: /usr/local/include
include: /usr/lib/clang/7.0.1/include
include: /usr/include
This gets produced by the c_cpp_properties.json file, especially if the cpp config provider says, that he cannot provide a config (like headers and files not mentioned in the CMakeLists.txt).
I will completely remove everything related to vscode and reinstall, brb
It works now! Perfect :) Thank you!
I know that this is maybe not as easy as one might think, but it would be really handsome to have the plugin automatically adding the necessary include directories to IntelliSense.
gcc
does have a command that lists the the include-directories and defines:g++ -Wp,-v -E -xc -dD -x c++ /dev/null
- vscode-cpptools does use that output for IntelliSense.Maybe there is something similar for CMake?
Looks like the server does have something like that, see here: https://cmake.org/pipermail/cmake/2018-March/067291.html https://cmake.org/cmake/help/v3.7/manual/cmake-server.7.html#type-codemodel (includePath)