How can I preserve paths if importing one CMakePresets.json into another?

Let’s say I have a build infrastructure repository, containing a cmake/common_presets.json, and various toolchain files that are referenced in this file’s presets, e.g.:

{
  "name": "toolchain-gcc",
  "hidden": true,
  "toolchainFile": "${sourceDir}/cmake/toolchains/gcc.cmake"
},

I wish to include common_presets.json in another project’s root-level CMakePresets.json via a submodule. Unfortunately, it doesn’t look like a currentSourceDir macro exists, so if I include common_presets.json in my CMakePresets.json, the sourceDir macro expands to the new project root, and all of the paths break. I believe that this also happens if you simply specify a relative path, since it seems that the relative path is with respect to the top-level CMakePresets.json, as opposed to the included file.

Any ideas on some possible workarounds?

You’re probably looking for ${fileDir}, which is supported since presets schema version 4.

Hi @craig.scott , always a pleasure!

Unfortunately, it seems like fileDir also evaluates to the path of the `CMakePresets.json` that is including common_presets.json, as opposed to the path to common_presets.json itself. While this might be the expected behavior if macros aren’t expanded until after inclusion in the calling file, this is still undesirable for me.

Bleh. Sadly, it’s a known bug with ${fileDir}: https://gitlab.kitware.com/cmake/cmake/-/issues/26982

Ah, dang. Well, at least I have something to keep an eye out for. Thanks!

It seems nobody is working on this ?