This extension provides several language model tools to allow Copilot to interact with the CMake Tools extension.
Current state
I'm creating a first version of this extension with the help of my friend, Copilot.
I still need to validate it a bit more and actually use it in my own development workflow,
to see how practical it is and what improvements are needed.
Below is a list of language model tools that are provided by this extension.
#get_cmake_project_info
This tool returns comprehensive information about the current CMake project including the source directory, build directory, and an alphabetically sorted list of all targets with their types. It provides a high-level overview of the project structure and available build targets.
#get_cmake_cache_variable
This tool retrieves one or more values from the CMake cache. It supports exact name matching, wildcard (*
) searches, or listing all variables when no parameter is provided. It is useful for getting configuration values that are kept in the CMake cache.
Parameters:
variableName
(optional): The name of the CMake cache variable to retrieve. This can be an exact name or a pattern containing a wildcard (*
). If not specified, returns a list of all cache variables.
#build_cmake_target
This tool builds the specified CMake target (or all targets if none is specified).
Parameters:
targets
(optional): Array of target names to build. If not specified, builds all targets.
#find_cmake_build_target_containing_file
This tool helps to find the CMake target(s) that can build/include a specific file in the workspace.
It searches for targets that either have the file listed as a source, have an include directory that contains the file, or the target's source directory matches the file's path.
This is useful for determining which targets to build when testing if a specific file can be compiled successfully.
Parameters:
file_path
(required): The path to the file to search for in CMake targets. Can be absolute or relative to the workspace.
Requirements
- VS Code 1.102.0 or later
- CMake Tools extension
- A workspace with a CMake project (containing CMakeLists.txt)
Usage
Once installed, the language model tools will be automatically available when you have a CMake project open. You can reference these tools in Copilot Chat using the #
syntax (e.g., #get_cmake_project_info
).
The extension automatically activates when it detects a CMakeLists.txt file in your workspace.
Of course, it will only provide real data as soon as the CMake Tools extension has configured the project and can provide the necessary information.
Example Usage
- "Show me an overview of this CMake project" → Uses
#get_cmake_project_info
- "What targets are available in this project?" → Uses
#get_cmake_project_info
- "Get the value of CMAKE_BUILD_TYPE from the cache" → Uses
#get_cmake_cache_variable
- "Build the main target" → Uses
#build_cmake_target
- "Which targets should I build to test src/math.h?" → Uses
#find_cmake_build_target_containing_file
License
MIT License - see LICENSE for details.