Getting CMake to build out of source without wrapping scripts

CMake 3.13 or newer supports the command line options -S and -B to specify source and binary directory, respectively.

cmake -S . -B build -G "MSYS Makefiles"

This will look for the CMakeLists.txt in the current folder and create a build folder (if it does not yet exist) in it.

For older versions of CMake, you can use the undocumented CMake options -H and -B to specify the source and binary directory upon invoking cmake:

cmake -H. -Bbuild -G "MSYS Makefiles"

Note that there must not be a space character between the option and the directory path.

Leave a Comment