–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?
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.