CMake Tutorial
CMake is an open-source, cross-platform automated build system used to manage the software build process; it does not depend on a particular compiler and supports multiple directories, applications and libraries.
Through the simple configuration file CMakeLists.txt, CMake automatically generates build files for different platforms (such as Makefile, Ninja build files and Visual Studio project files), simplifying compiling and building a project.
CMake itself is not a build tool but a tool that generates build systems; the generated build system can use different compilers and toolchains.
What CMake does and its advantages
- Cross-platform support: CMake supports many operating systems and compilers, so the same build configuration can be used in different environments.
- Simplified configuration: Through CMakeLists.txt users can define project structure, dependencies and compile options without writing complex build scripts by hand.
- Automated building: CMake can automatically detect libraries and tools on the system, reducing manual configuration work.
- Flexibility: It supports several build types and configurations (such as Debug and Release) and lets users customize build options and modules.
Build configuration
- The CMakeLists.txt file: CMake's configuration file defines build rules, dependencies, compile options and so on. Each CMake project usually contains one or more CMakeLists.txt files.
- Build directory: To keep the source tree clean, CMake encourages a separate build directory (out-of-source build), so generated files are stored apart from the source code.
Basic workflow
- Write the CMakeLists.txt file: Define the project's build rules and dependencies.
- Generate build files: Use CMake to generate build system files suited to the current platform (for example a Makefile or Visual Studio project files).
- Run the build: Use the generated build system files (such as
make,ninja,msbuild) to compile the project.

Related links
- CMake official site https://cmake.org/
- CMake official documentation:https://cmake.org/cmake/help/latest/guide/tutorial/index.html
- CMake source code:https://github.com/Kitware/CMake
- CMake source code:https://gitlab.kitware.com/cmake/cmakeku