# cmake --build --preset gives "file not found"

**URL:** https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468
**Category:** Usage
**Created:** [November 11, 2021, 10:07am UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468 "2021-11-11T10:07:21Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 11, 2021, 10:07am UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/1 "2021-11-11T10:07:21Z")

</div>

My project tree is:

```auto
|--CMakeLists.txt
   CMakePresets.json
   |--builds
      |--myBuildDir

```

from myBuildDir I can configure the build with a configure preset:

```auto
cmake --preset <myConfigurePreset> ../..
...
-- Configuring done
-- Generating done

```

but the build preset fails:

```auto
$ cmake --build --preset=<myBuildPreset> ../..
Unknown argument ../..
CMake Error: Could not read presets from /mnt/c/<snip>/builds/myBuildDir: File not found

```

What would be the correct syntax please?

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 11, 2021, 5:56pm UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/2 "2021-11-11T17:56:29Z")

</div>

Still struggling with this.

I believe the general cmake usage is:

`cmake [options] <path-to-source>`

so why does this fail?

```auto
$ cmake --build --preset=<myBuildPreset> ../..
Unknown argument ../..
CMake Error: Could not read presets from /mnt/c/<snip>/builds/myBuildDir: File not found

```

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 11, 2021, 6:09pm UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/3 "2021-11-11T18:09:11Z")

</div>

Online documentation shows `cmake --build --preset <preset> [<options>] [-- <build-tool-options>]`. You don’t supply a directory path, the directory is required when not using `--preset <preset>`.

Try without the directory, this works for me when the current directory is the source directory:  
`$ cmake --build --preset=<myBuildPreset>`

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 11, 2021, 6:14pm UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/4 "2021-11-11T18:14:11Z")

</div>

@fdk17 But what if CMakePresets.json is not in the current (build) directory?

With:  
`$ cmake --build --preset=<myBuildPreset>`  
I get:  
`CMake Error: Could not read presets from <path>/builds/<myBuildDir>: File not found`

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 11, 2021, 6:18pm UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/5 "2021-11-11T18:18:33Z")

</div>

Well, the documentation says `CMakePresets.json and CMakeUserPresets.json live in the project's root directory. `. To me this means they need to be in the source root directory. This is how I use it and its been working so far.

[https://cmake.org/cmake/help/v3.22/manual/cmake-presets.7.html](https://cmake.org/cmake/help/v3.22/manual/cmake-presets.7.html)

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 11, 2021, 6:28pm UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/6 "2021-11-11T18:28:15Z")

</div>

@fdk17 Thanks for your help. The thing is, I do have CMakePresets.json in my root directory:

`<path>/CMakePresets.json`

but when I run the command you suggested in:

`<path>/builds/<myBuildDir>`

I see:

`CMake Error: Could not read presets from <path>/builds/<myBuildDir>: File not found`

I don’t know why it is attempting to read from `<path>/builds/<myBuildDir>` instead of `<path>`.

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 11, 2021, 6:33pm UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/7 "2021-11-11T18:33:35Z")

</div>

> [@DavidA](#):
>
> I run the command you suggested in:
> 
> `<path>/builds/<myBuildDir>`

Why are you changing to this directory before running the command?

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [November 11, 2021, 6:40pm UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/8 "2021-11-11T18:40:25Z")

</div>

@fdk A very good point. Sorry, I think you’ve demonstrated that I haven’t thought this through properly. Thanks for your help. I will close the issue and mark your comment as the solution.

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 11, 2021, 9:32pm UTC](https://discourse.cmake.org/t/cmake-build-preset-gives-file-not-found/4468/9 "2021-11-11T21:32:15Z")

</div>

@DavidA Good luck, I’ve just started using presets myself (and ran into some issues) and it is a different work flow.
