CMake

CMake is an open-source, cross-platform family of tools designed to build, test and package software.

This typically involves writing files named CMakeLists.txt in a source-tree, containing cmake commands to define the project(s) to be built. See the cmake tutorial.

CMake integrates seamlessly in recent versions of Microsoft Visual Studio (see the C++ Team blog post CMake support in Visual Studio).

Note that Microsoft Visual Studio uses a file named CMakeSettings.json to help configure cmake, and a file named launch.vs.json to configure the debug and launch settings.

See also A CMake tutorial for Visual C++ developers by Marius Bancila.

When using CMake it is important to understand the build phases.

CMake also supports unit testing, see ctest.

CMake allows for defining top-level targets using the add_executable(), add_library(), or add_custom_target() commands. There are two library types - shared or static.

CMake allows for defining build rules using add_custom_command().

CMake can be used like a scripting language. See Learn CMake's Scripting Language in 15 Minutes.

Links:

Finding the python executable

The python executable is required in order to build and install python wheel files. find_program can be used to find the path to the python executable.


find_program(PYTHON "python")
if (NOT PYTHON)
	message( FATAL_ERROR "Fatal error: python not found, please install python and make it available in the system path" )
endif()

This sets the variable PYTHON to the path of the python executable.

Validating CMAKE_BUILD_TYPE

It's probably a good idea to validate the value of the cmake variable CMAKE_BUILD_TYPE which is used to define what build variable is to be built. For example:


string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
if(    NOT cmake_build_type_tolower STREQUAL "debug"
   AND NOT cmake_build_type_tolower STREQUAL "release"
   AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
  message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
endif()