I’m developing a C++ bases software for Linux using CMake 3.29.3
.
In my CMake based project, I’ve the following CMakePresets.json
:
{
"version": 6,
"cmakeMinimumRequired": {
<snip>
},
"configurePresets": [
{
"name": "debug",
"binaryDir": "out/debug",
"installDir": "out/debug/bin",
<snip>
},
{
"name": "release",
"binaryDir": "out/release",
"installDir": "out/release/bin",
<snip>
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
}
]
}
Now I can build the debug
preset as follows:
cmake --preset=debug -S .
cmake --build --preset=debug --parallel $(nproc)
So far this looks good. I don’t need to specify any directory other than .
.
But if I try to install files, there seems to be the only way like this:
cmake --install out/debug/
The build directory must be specified explicitly to find the install script. If I need to change it, I need to change it in both CMakePresets.json
and my build script, which seems counterintuitive.
I can parse the json file and extract the build directory. Other than that, does CMake provide any way to find the build directory automatically?