I have a CMakePresets.json
file which makes use of inheritance and macro expansion.
Here is an excerpt, in reality I use multiple versions of "Foo":
{
"configurePresets": [
{
"name": "default",
"hidden": true,
"generator": "Unix Makefiles",
"binaryDir": "cmake-build-${presetName}",
"environment": {
"PATH": "/opt/foo/$env{FOO_VERSION}/bin:$penv{PATH}",
"LD_LIBRARY_PATH": "/opt/foo/$env{FOO_VERSION}.0/lib"
},
"cacheVariables": {
"FOO_VERSION": "$env{FOO_VERSION}",
}
},
{
"name": "debug-foo1",
"inherits": "default",
"environment": { "FOO_VERSION": "1" }
},
{
"name": "release-foo1",
"inherits": "debug-foo1",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
}
],
"buildPresets": [
{
"name": "debug-foo1",
"configurePreset": "debug-foo1"
},
{
"name": "release-foo1",
"configurePreset": "release-foo1"
}
]
}
Now assume I select the preset release-foo1
. This would render the following variables, among others:
binaryDir = "cmake-build-release-foo1"
FOO_VERSION = "1"
LD_LIBRARY_PATH = "/opt/foo/1.0/lib"
Is there a way to query these results for a given preset? For example, given release-foo1
, I want to know the resulting binaryDir
.
Of course I could parse the JSON myself, but that seems tedious, especially because of the cross references and substitutions which are being made by CMake.
jq
to extract the elements. – Elrod