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

My project tree is:

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

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

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

but the build preset fails:

$ 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?

Still struggling with this.

I believe the general cmake usage is:

cmake [options] <path-to-source>

so why does this fail?

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

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>

@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

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

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

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

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

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