Unlike Java's Maven or Rust's Cargo, C++ has no single official build tool baked into the language ecosystem — CMake has become the de facto cross-platform standard by generating native build files for the platform's actual toolchain (Makefiles on Linux, Visual Studio projects on Windows, Ninja files for speed) from one shared CMakeLists.txt. This two-step process (CMake generates, then the real build tool builds) is what lets the same C++ project build natively across different operating systems and compilers without maintaining separate build configurations for each.
A minimal CMakeLists.txt
cmake_minimum_required states the oldest CMake version this file assumes; add_executable declares the target and which source files build it — the entire configuration for a simple project can be this short.
cmake_minimum_required(VERSION 3.20)
project(MyApp)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(myapp main.cpp utils.cpp)The generate-then-build two-step process
cmake -B build generates the platform-native build files inside the build/ directory; cmake --build build then invokes the actual underlying tool (make, ninja, or MSBuild, whichever CMake chose or was told to target) to compile.
$ cmake -B build // generates native build files into build/
$ cmake --build build // invokes the underlying tool to actually compile
$ ./build/myappAdding a dependency
find_package locates an already-installed library; target_link_libraries connects it to a specific target — this is the standard pattern for depending on any external C++ library through CMake.
find_package(fmt REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE fmt::fmt)