This extension helps to bridge a gap between 2 great extensions:
ms-vscode.cpptools
) by Microsoft: Provides C and C++ language support (auto-completion, go to definition, etc.)vector-of-bool.cmake-tools
) by vector-of-bool: Provides support for CMake-based projects (configure, build, etc.)CMake Tools Helper enables cpptools to automatically know the information parsed by CMake Tools (such as include directories and defines) and use it to provide auto-completion, go to definition, etc.
In addition to that, this extension tries to reduce "friction" when using CMake by implementing convenient features. (e.g. managing multiple CMake versions)
c_cpp_properties.json
with the current CMake target's information (build type, include directories and defines)CMake: Install CMake
)CMake: Change CMake version
)cmake.useCMakeServer
set to true
. (i.e. CMake >= v3.7.2) Don't worry if you don't have CMake: You can simply execute CMake: Install CMake
, this extension will take care of the rest ;)c_cpp_properties.json
)TL;DR: I just want to open a CMake-based project and immediately start coding without configuring anything in VSCode. (Ok, maybe execute a "CMake configure", but that's all!)
In order to provide some its features, cpptools relies on a JSON file (c_cpp_properties.json
) that contains project-related information such as include paths and defines.
At the same time, CMake Tools parses the project's CMake files and extracts all the information that is needed to build it (e.g. compiler flags, includes, defines, etc.) and stores it in another JSON file. (.cmaketools.json
)
Currently, (I mean... before this extension was released :wink: ) there is no way for cpptools to automatically benefit from what CMake Tools knows -- i.e. The users have to manually copy the include paths and defines from their CMake files (or CMake Tools' .cmaketools.json
) to c_cpp_properties.json
.
Having found nothing to do the above automatically, I decided to create this extension!
Please note that discussions were started at https://github.com/vector-of-bool/vscode-cmake-tools/issues/22 and https://github.com/Microsoft/vscode-cpptools/issues/156 to try to address the issue, but AFAIK there is nothing concrete yet.
Another issue when wanting to use CMake, lazy users (such as myself ;) ) usually find themselves stuck with outdated versions of CMake. This extension tries to alleviate the "pain" of getting the latest version from cmake.com/download by proposing to download, extract and enable any version of CMake directly from VS Code.
TL;DR: Ugly hacks, sweat and tears :)
A combination of:
vscode.extensions.getExtension("vector-of-bool.cmake-tools").exports
: is the CMake Tools extension API. It allows getting the name of the currently-selected build target as well as the list of valid CMake configurations. Currently, CMake Tools provides 2 implementations:
CMake Tools Helper uses the "client" implementation and therefore requires the cmake.useCMakeServer
setting to be true
Event listeners: CMake Tools API >= 0.9.5 provides the following events:
CMake Tools Helper uses them in order to be notified when the configuration and/or the default build target changes
Each time CMake Tools Helper is notified, the following happens:
c_cpp_properties.json
using the information from step 1c_cpp_properties.json
has changed (as of cpptools v0.11.2 has a file watcher on it)c_cpp_properties.json
cmake.cmakePath
and cmake.useCMakeServer
accordinglyc_cpp_properties.json
. This is a workaround to the fact that cpptools doesn't export any API that other extensions could use to interact with it. This particular solution was inspired by the implementation of handleConfigurationChange
(ms-vscode.cpptools-0.11.2/out/src/LanguageServer/C_Cpp_ConfigurationProperties.js
)all
, clean
, ALL_BUILD
, ZERO_CHECK
, etc...) are not handled and selecting them results in a null
configuration in c_cpp_properties.json
(if you have ideas on what to do when those targets are selected, please feel free to open an issue at github.com/maddouri/vscode-cmake-tools-helper/issues, I'll see what I can do ;)Any contribution (feature requests, bug fixes, questions, ideas on how to make things better, etc.) is WELCOME !
Just head to github.com/maddouri/vscode-cmake-tools-helper ;)