CMake is not a compiler — it is a build generator. It reads aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/VrajPatel105/cpp-gpu-inference/llms.txt
Use this file to discover all available pages before exploring further.
CMakeLists.txt description of your project and produces the native build files that a real build tool (Make, MinGW, Visual Studio) uses to do the actual compiling. This two-layer design means you describe your project once in a platform-neutral file, and CMake figures out the correct g++ invocations, linker flags, and dependency tracking for whatever machine it runs on. For a project like cpp-gpu-inference that will eventually mix C++, CUDA, and third-party ML libraries, CMake is the standard way the industry manages this complexity.
The Two-Step Cycle
Every CMake workflow follows the same two steps. Run them from inside a dedicatedbuild/ directory:
Configure — generate build files
CMakeLists.txt from the parent directory (..) and writes
Makefiles (or equivalent) into build/. Run this once when you first clone
the project, and again whenever CMakeLists.txt itself changes.On Windows with MinGW (no Visual Studio installed), specify the generator
explicitly:Re-run
cmake .. only when CMakeLists.txt changes (added a source
file, changed the C++ standard, added a library). Re-run cmake --build .
after every source edit. Running cmake --build . when only .cpp files
changed is always sufficient.The Project’s CMakeLists.txt
This is the exact build file from the 1. cpp core module:
| Line | Purpose |
|---|---|
cmake_minimum_required(VERSION 3.10) | Reject CMake versions older than 3.10 with a clear error |
set(CMAKE_CXX_STANDARD 20) | Compile all targets with -std=c++20 — no need to type it per file |
set(CMAKE_CXX_STANDARD_REQUIRED ON) | Fail the configure step if C++20 is unavailable; don’t silently downgrade |
project(hellow) | Names the project; sets ${PROJECT_NAME} |
add_executable(hellow hellow.cpp integers.cpp) | Compile hellow.cpp and integers.cpp together into one executable |
Out-of-Source Builds
CMake separates generated files from source files. All Makefiles, CMake caches, and compiled objects live inbuild/ — never in the source directory. The project tree looks like this:
build/ to .gitignore. The directory is fully reproducible from CMakeLists.txt and the source files.
Adding Executables
Each standalone concept file can become its own executable with a separateadd_executable line:
cmake .. from build/, then cmake --build ..
Windows + MinGW: The Working Sequence
If CMake defaults to NMake (which requires Visual Studio) but only g++/MinGW is installed, delete the stale build cache and force the MinGW generator:Quick Reference
| Action | Command |
|---|---|
| First-time configure (Linux/Mac) | cmake .. |
| Configure with MinGW (Windows) | cmake .. -G "MinGW Makefiles" |
| Compile after source edits | cmake --build . |
| Clean rebuild | Delete build/ folder, then reconfigure |
| Add a new source file | Edit CMakeLists.txt, re-run cmake .., then cmake --build . |
Single-File Compilation (Without CMake)
For quick one-off tests, compile a single file directly withg++: