Any way to choose path of CMakePresets.json?

New to cmake preset

according to cmake doc

–preset <preset>, --preset=<preset>
Reads a preset from <path-to-source>/CMakePresets.json and <path-to-source>/CMakeUserPresets.json.
The preset may specify the generator and the build directory, and a list of variables and other arguments to pass to CMake.
The current working directory must contain CMake preset files.
The CMake GUI can also recognize CMakePresets.json and CMakeUserPresets.json files.

CMake assumes CMakePresets.json is in <path-to-source>

Anyway to put CMakePresets.json in alternative directory,
while, if possible, keep CMAKE_SOURCE_DIR unchanged?

No, CMakePresets.json must be at the top level of your source tree (i.e. the same directory as your top level CMakeLists.txt file).

Any way to tell cmake CLI where the top level of the source tree is for the purposes of finding CMakePresets.json?

-S does not seem to support this

~/some/other/dir$ cmake -S ~/engines/ --build --preset linux-debug
CMake Error: Unknown argument --build

According to CMake documentation, cmake --build --preset must be invoked in the directory containing the preset files (i.e. the toplevel source directory):

--preset <preset>, --preset=<preset>

Use a build preset to specify build options. The project binary directory is inferred from the configurePreset key. The current working directory must contain CMake preset files. See preset for more details.

(Emphasis mine)

1 Like