Is it possible to somehow combine the same env/cache variable from two presets into a single value? Ideally, the goal is to define CMAKE_PREFIX_PATH cache variable based on values from multiple presets. Or at least define $env{CMAKE_PREFIX_PATH} that way.
- From reading documentation there seems to be no way to reference one variable from another inside preset.
- For environment variables
$env{CMAKE_PREFIX_PATH}works, but since it doesn’t allow circular references you can only save this value to a different variable, notCMAKE_PREFIX_PATH.
Using$penv{CMAKE_PREFIX_PATH}is accessing process environment variables, so it’s not very helpful for this case.
$env:CMAKE_PREFIX_PATH="42"
cmake --preset default
# Preset CMake variables:
#
# DEPENDENCY_PATH="L:/path/to/second/dependency"
#
# Preset environment variables:
#
# CMAKE_PREFIX_PATH="L:/path/to/first/dependency"
# CMAKE_PREFIX_PATH_env1="L:/path/to/second/dependency;L:/path/to/first/dependency"
# CMAKE_PREFIX_PATH_env2="L:/path/to/second/dependency;42"
CMakeUserPresets.json
{
"version": 10,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"$comment": "An example CMakePresets.json file",
"include": [],
"configurePresets": [
{
"name": "default",
"inherits": ["dependency"],
"binaryDir": "${sourceDir}/build_",
"cacheVariables": {
"DEPENDENCY_PATH": "L:/path/to/second/dependency"
},
"environment": {
"CMAKE_PREFIX_PATH_env1": "L:/path/to/second/dependency;$env{CMAKE_PREFIX_PATH}",
"CMAKE_PREFIX_PATH_env2": "L:/path/to/second/dependency;$penv{CMAKE_PREFIX_PATH}"
}
},
{
"name": "dependency",
"cacheVariables": {
"DEPENDENCY_PATH": "L:/path/to/first/dependency"
},
"environment": {
"CMAKE_PREFIX_PATH": "L:/path/to/first/dependency"
}
}
]
}