CMake build phases

Building a CMake project involves three phases:

  1. Configure time (when cmake itself is running)
  2. Build time (when the generator such as make or ninja is running to compile/link the projects)
  3. Install time (when running the INSTALL target generated by CMake)

In Visual Studio the build phase occurs when you select the menu item Build/Build All, whereas the install phase occurs when you select the menu item Build/Install <project>.

To confuse things a bit, it's common to use cmake to run the build and install steps, such as in the following windows batch file:


cmake -G "Ninja" ^
    -DBUILD_SHARED_LIBS=%SHARED_LIBS% ^
    -DCMAKE_INSTALL_PREFIX:PATH="install" ^
    -DCMAKE_TOOLCHAIN_FILE="%VCPKG_ROOT_DIR%/scripts/buildsystems/vcpkg.cmake" ^
    -DVCPKG_TARGET_TRIPLET=%TRIPLET% ^
    -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS="TRUE" ^
    -DCMAKE_CXX_COMPILER=%WINDOWS_COMPILER% ^
    -DCMAKE_C_COMPILER=%WINDOWS_COMPILER% ^
    -DCMAKE_BUILD_TYPE="%CONFIG%" ^
    -DCMAKE_MAKE_PROGRAM=ninja ^
    --config %CONFIG% ^
    "%SOURCE%"

cmake --build . --target install --config %CONFIG%