Allow new build directory to be specified (rather than defaulting to current working directory)
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
When scripting build interactions, I find that if the current working directory contains my root CMakeLists.txt and I want to create a new build, I need to do something along the lines of
BUILD_DIR=/path/to/build
SRC_DIR=`${PWD}`
if [ ! -d "${BUILD_DIR}" ]
then
mkdir -p "${BUILD_DIR}"
(cd "${BUILD_DIR}" && cmake -DCMAKE_TOOLCHAIN_FILE="${SRC_DIR}/toolchain.cmake" "${SRC_DIR}")
fi
make -C "${BUILD_DIR}"
# or cmake --build "${BUILD_DIR}"
Rather than muck around with reverse paths and inline directory changes, it would be much easier to be able to tell CMake "get files from here, and put the build there". This would require allowing an optional second directory () when using mode. Ideally, it could create the directory if missing.
Many tools which seem similar (make, tar, ...) support a "change working directory before executing" option - I can't find one for CMake.