Build CMake from dev sources

While CMake binaries can be downloaded for most platforms, there are certain cases where one wishes to build CMake from source. For example, when preparing a merge request to fix or enhance CMake. Usually the computer will have at least an older version of CMake that can be used. If so, we recommend using the existing CMake to build the newer CMake from the CMake source directory. We recommend using Ninja in general for faster build and rebuild for any CMake project.

cmake -B build -DBUILD_TESTING:BOOL=OFF -DCMAKE_BUILD_TYPE=Release --install-prefix=$HOME/cmake-dev -G Ninja

cmake --build build

cmake --install build

A one-step download-build script is the scripts/build_cmake.cmake.


If an old CMake isn’t available on the computer, then use CMake bootstrap:

./bootstrap --prefix=$HOME/cmake-dev --generator=Ninja -- -DBUILD_TESTING:BOOL=OFF -DCMAKE_BUILD_TYPE:STRING=Release

ninja -C Bootstrap.cmk/ install

This puts the compiled CMake under ~/cmake-dev, without disturbing the primary CMake install. Upon making any CMake code changes, simply recompile the minimum needed bits by:

ninja -C Bootstrap.cmk/ install