Can I specify -S via CMakePresets.json?

Our homebrew scripts to build our project look like

cmake -S path/to/project_dir -G Ninja -etc

We are trying to convert to CMakePresets.json, but the only thing preventing that is the first argument above – the -S argument. Visual Studio runs cmake in weird places, so we would like to override it to something sensible, or else CMAKE_CURRENT_SOURCE_DIR/etc get busted. I have not been able to find somewhere to override this in the CMakePresets.json spec. Is it unsupported?

Is the issue that you wish to omit the -S parameter and set sourceDir in a CMakePresets.json in the current working directory? I don’t think that’s possible.

The buildPreset and testPreset require the current working directory to be the source directory where CMakePresets.json is. There are multiple open CMake issues about this, the most recent is: https://gitlab.kitware.com/cmake/cmake/-/issues/23982

In short, to use presets to configure, build, and test currently require CMake to be executed from the top-level project directory where CMakePresets.json is to the best of my knowledge. I also would like to be able to execute CMake from arbitrary CWD and use presets, but I think that can’t be done yet.

VS is blatantly violating that then. It wants to run it with the source directory in the build directory.