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

**URL:** https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380
**Category:** Usage
**Created:** [December 9, 2025, 11:47pm UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380 "2025-12-09T23:47:57Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dograt](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dograt/32/5777_2.png) [@dograt](https://discourse.cmake.org/u/dograt)
#### Post date: [December 9, 2025, 11:47pm UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380/1 "2025-12-09T23:47:57Z")

</div>

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.:

```auto
{
  "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?

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 10, 2025, 4:07am UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380/2 "2025-12-10T04:07:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dograt](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dograt/32/5777_2.png) [@dograt](https://discourse.cmake.org/u/dograt)
#### Post date: [December 10, 2025, 5:18am UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380/3 "2025-12-10T05:18:36Z")

</div>

> [@craig.scott](#):
>
> fileDir

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.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 10, 2025, 6:02am UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380/4 "2025-12-10T06:02:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dograt](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dograt/32/5777_2.png) [@dograt](https://discourse.cmake.org/u/dograt)
#### Post date: [December 10, 2025, 6:28am UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380/5 "2025-12-10T06:28:09Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [December 10, 2025, 5:26pm UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380/6 "2025-12-10T17:26:21Z")

</div>

It seems nobody is working on this ?

---

<div class="post-metadata">

### Author: ![Chardrazle](https://discourse.cmake.org/user_avatar/discourse.cmake.org/chardrazle/32/4362_2.png) [@Chardrazle](https://discourse.cmake.org/u/Chardrazle)
#### Post date: [December 22, 2025, 8:01am UTC](https://discourse.cmake.org/t/how-can-i-preserve-paths-if-importing-one-cmakepresets-json-into-another/15380/7 "2025-12-22T08:01:40Z")

</div>

We found a workaround was to set and use env-vars during the processing of the presets files.

See: [CMake presets: `inherit` makes it hard to include toolchain file - #6 by Chardrazle](https://discourse.cmake.org/t/cmake-presets-inherit-makes-it-hard-to-include-toolchain-file/7784/6)
