Reputation: 681
I would like to configure correctly project's settings.json
file to use CMakeLists.txt
file of multiple sub-project.
The structure of the project is as like as follows.
vscode_build_cmake/
`-- task
|-- add
| |-- CMakeLists.txt
| |-- include
| | `-- foo.h
| `-- src
| |-- foo.cpp
| `-- main.cpp
`-- print
|-- CMakeLists.txt
|-- include
| `-- foo.h
`-- src
|-- foo.cpp
`-- main.cpp
Here, add
& print
are completely isolated sub-project of the main project task
. Each sub-project has their own build recipe which is written in their own CMakeLists.txt
file. Usual steps to build sub-project is :
cd task/add
mkdir build
cd build
cmake .. && make
Same steps is for task/print
.
Right now I would like to perform this build task
using VSCode Cmake tool. What I have found that I only need to make a vscode_build_cmake/.vscode/settings.json
file where I can point to the directory of CMakeLists.txt
file. I am now working with
{
"cmake.configureOnOpen": false,
"cmake.sourceDirectory": "${workspaceFolder}/task/add"
}
I just press ctrl+shift+p
and write in the command box run build task
and press Enter
. That one do the job for me and I can see build, bin, lib
directories inside task/add
directory.
But the problem, I am facing now is that if I need to build print
sub-project I have to manually edit the settings.json
file as like as follows
{
"cmake.configureOnOpen": false,
"cmake.sourceDirectory": "${workspaceFolder}/task/print"
}
After that, I have to delete cache and reconfigure
and build task
which perform now the build task only for print
project. This one is very tedious to me.
CMakeLists.txt
file of add
and print
in cmake.sourceDirectory
? Which can tell me which build task I would like to perform? Eg:{
"cmake.configureOnOpen": false,
"cmake.sourceDirectory": ["${workspaceFolder}/task/add",
"${workspaceFolder}/task/print"]
}
Or ,
I am using CMake Tools v1.13.4.
Upvotes: 6
Views: 6229
Reputation: 50284
CMake Tools supports an array of directories in cmake.sourceDirectory
since version 1.13.40. See PR #1374.
If you're intent on not having a tasks/CMakeLists.txt
that add_subdirectory
s add/
and print/
, then you can consider using VS Code's multi-root workspace feature, which the vscode-cmake-tools
extension supports.
If you have a reason not to use / that you don't like the multi-root workspace approach, you can show your support for vscode-cmake-tools issue #1374 ("Support Multiple CMakeLists.txt without Requiring a Multi-Root Workspace") and the proposed solutions. At the time of this writing, the proposal process is still in earlier stages.
Upvotes: 5