# cmake --build --preset=default from non-SOURCE\_DIR

**URL:** https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300
**Category:** Usage
**Created:** [May 12, 2021, 10:46am UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300 "2021-05-12T10:46:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Kris\_Malfettone](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kris_malfettone/32/117_2.png) [@Kris\_Malfettone](https://discourse.cmake.org/u/Kris_Malfettone)
#### Post date: [May 12, 2021, 10:46am UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/1 "2021-05-12T10:46:36Z")

</div>

Hi there, first of all I wanted to say the new “presets” feature is amazing and definitely has the possibility to fundementally change how we interact with CMake in the future.

However, for some reason the following usages do not seem to work and we are basically required to run the cmake command from the CMAKE\_SOURCE\_DIR only.  
cmake --build --preset=default path-to-source  
cmake --build --preset=default path-to-existing-build  
cmake --build path-to-source --preset=default  
cmake --build path-to-existing-build --preset=default  
cmake --build --preset=default -S path-to-source  
cmake --build --preset=default -B path-to-existing-build  
cmake --build --preset=default -S path-to-source -B path-to-existing-build

If I manually cd to the CMAKE\_SOURCE\_DIR the following works:  
cmake --build --preset=default

The equivalent of the above for the configure step all work though:  
cmake --preset=default path-to-source  
cmake --preset=default path-to-existing-build  
cmake --preset=default -S path-to-source  
cmake --preset=default -B path-to-existing-build  
cmake --preset=default -S path-to-source -B path-to-existing-build

I believe the --build behavior should match the configure behavior. Am I missing something? I would think the -S argument or path to source would function similarly to the -C option in make/ninja. I might also suggest that a simple enviornment variable would be a good way for interactive users where I could simply export CMAKE\_SOURCE\_DIR and have it respected in all the various cmake utilities versus passing command line parameters.

I did look and I did not see this reported before.

\*Edit: angle brackets didn’t show up correctly, so I removed them

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 12, 2021, 12:36pm UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/2 "2021-05-12T12:36:06Z")

</div>

Cc: @kyle.edwards

---

<div class="post-metadata">

### Author: ![Kris\_Malfettone](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kris_malfettone/32/117_2.png) [@Kris\_Malfettone](https://discourse.cmake.org/u/Kris_Malfettone)
#### Post date: [May 20, 2021, 2:00pm UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/3 "2021-05-20T14:00:25Z")

</div>

Just checking in. Looking to at least confirm whether or not this is expected behavior or a bug.

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [May 20, 2021, 2:17pm UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/4 "2021-05-20T14:17:28Z")

</div>

The build presets were the creation of Sam Freed from the Visual Studio team at Microsoft. I’d tag them here, but I don’t know if they’re on Discourse or not.

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [May 20, 2021, 9:55pm UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/5 "2021-05-20T21:55:15Z")

</div>

I can’t seem to find the discussion, but earlier this year Craig Scott and I among others were discussing having an optional system-wide preset, vs. environment variables, etc.

I also run into this issue, so I think it’s a topic among multiple preset users here.

---

<div class="post-metadata">

### Author: ![Kris\_Malfettone](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kris_malfettone/32/117_2.png) [@Kris\_Malfettone](https://discourse.cmake.org/u/Kris_Malfettone)
#### Post date: [May 20, 2021, 10:17pm UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/6 "2021-05-20T22:17:15Z")

</div>

I do think most of my concerns would be addressed by a simple ‘change working directory’ flag similar to Make’s or Ninja’s. It allows you to easily execute the commands regardless of current working directory. In addition, it is easy to use in aliases and the like with something as simple as:  
ninja -C ${SRC\_DIR:-.}

I am not 100 percent what you mean by a system wide preset. But for our projects we use a machine for many purposes so it doesn’t sound like it would apply. But I may be misunderstanding something.

The other one I feel is missing would be a user presets file in a home directory. We have many cmake projects that I would want to share some presets between. In my current situation I have to copy them into each projects location.

With all that said I think the preset stuff is super useful and really appreciative of all the current work done on it so far.

---

<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: [May 22, 2021, 1:07am UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/7 "2021-05-22T01:07:48Z")

</div>

> [@scivision](#):
>
> I can’t seem to find the discussion, but earlier this year Craig Scott and I among others were discussing having an optional system-wide preset, vs. environment variables, etc.

[Issue 21331](https://gitlab.kitware.com/cmake/cmake/-/issues/21331) is probably what you’re looking for.

---

<div class="post-metadata">

### Author: ![fwh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fwh/32/3780_2.png) [@fwh](https://discourse.cmake.org/u/fwh)
#### Post date: [October 20, 2023, 9:45am UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/8 "2023-10-20T09:45:59Z")

</div>

Is there any news on this topic?

I looked at the discussion but using include from a top-level CMakePresets.json file does not seem to work with build presets.

For the following project:

```auto

CMakePresets.json (include: 3rdPartyLibrary/CMakePresets.json)
    |
    | ----- 3rdPartyLibrary
                     |
                     | ------- CMakePresets.json (confgurePreset: default, buildPreset: default)

```

From top level I can configure a build:

`cmake --preset=default`

But I cannot build:

`cmake --build --preset=default`

I have also been looking for way to retrieve property values from the configPreset like binaryDir. I could parse the file with other tools, but it would be great if I could do it through cmake.

---

<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: [October 20, 2023, 9:29pm UTC](https://discourse.cmake.org/t/cmake-build-preset-default-from-non-source-dir/3300/9 "2023-10-20T21:29:13Z")

</div>

To my knowledge, build presets work fine with `include`. You might not have specified things correctly. I suggest you open a new discussion thread with a minimal set of presets files that demonstrate your problem.
