Using CMake on Windows

CMake on Windows is installed via the cmake*-win64-x64.msi graphical installer. Do not use sudo or Run As Administrator for cmake in general. We use the Ninja build system with CMake, which is generally faster on any platform and in particular for Windows solves numerous issues.

Compile programs using CMake

Navigate to the directory containing the file CMakeLists.txt using the Windows Terminal / Command Prompt.

  1. configure the build. This is normally run only once unless making major project changes.
cmake -B build
  1. compile the program. This is the command run each time you make a change to the project code.
cmake --build build
  1. Optionally, install the program with
cmake -install build

Generator selection

On Windows, CMake defaults to Visual Studio and Nmake–the CMAKE_GENERATOR environment variable suggested above overrides CMake defaults. CMAKE_GENERATOR can also be overridden like:

cmake -G "Visual Studio 16 2019"

sh.exe error with cmake

This error is fixed by upgrading to CMake ≥ 3.17.

sh.exe was found in your PATH, here: C:/Program Files/Git/user/bin/sh.exe For MinGW make to work correctly sh.exe must NOT be in your path. Run cmake from a shill that does not have sh.exe in your PATH. If you want to use a UNIX shell, then use MSYS Makefile

Notes