Skip to main content

Documentation 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.

CMake is not a compiler — it is a build generator. It reads a 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 dedicated build/ directory:
1

Configure — generate build files

mkdir build && cd build
cmake ..
CMake reads 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:
cmake .. -G "MinGW Makefiles"
A successful configure prints the detected compiler, for example:
-- The CXX compiler identification is GNU 13.2.0
-- Build files have been written to: /path/to/build
2

Build — compile the code

cmake --build .
Runs the underlying build tool to compile every out-of-date source file. Run this after every .cpp edit. A successful build ends with:
[100%] Built target hellow
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:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(hellow)
add_executable(hellow hellow.cpp integers.cpp)
Line by line:
LinePurpose
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 in build/ — never in the source directory. The project tree looks like this:
1. cpp core/
├── CMakeLists.txt        ← you edit this
├── hellow.cpp
├── integers.cpp
├── concepts.cpp
│   ...
└── build/                ← generated; never edit manually
    ├── Makefile
    ├── CMakeCache.txt
    ├── cmake_install.cmake
    ├── CMakeFiles/
    └── hellow             ← compiled binary
Add 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 separate add_executable line:
cmake_minimum_required(VERSION 3.10)
project(cpp_core)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# single-file executables
add_executable(basics        basic.cpp)
add_executable(integers      integers.cpp)
add_executable(arrays        arrays.cpp)
add_executable(iteration     iteration.cpp)
add_executable(functions     functions.cpp)
add_executable(pointers      pointers.cpp)
add_executable(smartptr      smartpointers.cpp)
add_executable(move_sem      move_semantics.cpp)
add_executable(move_ctor     move_constructor.cpp)
add_executable(concepts      concepts.cpp)
add_executable(custom_cpts   customConcepts.cpp)
add_executable(stl           stl.cpp)
add_executable(padding       struct_padding_alignment.cpp)

# multi-file executable
add_executable(header_demo   header.cpp adder.h)
After adding a new target, re-run 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:
# Windows — clear and reconfigure with MinGW
rmdir /s /q build
mkdir build
cd build
cmake .. -G "MinGW Makefiles"
cmake --build .
A clean configure shows the compiler being detected:
-- The CXX compiler identification is GNU 13.2.0
-- Detecting CXX compile features - done
-- Configuring done
-- Build files have been written to: C:/path/to/build

Quick Reference

ActionCommand
First-time configure (Linux/Mac)cmake ..
Configure with MinGW (Windows)cmake .. -G "MinGW Makefiles"
Compile after source editscmake --build .
Clean rebuildDelete build/ folder, then reconfigure
Add a new source fileEdit CMakeLists.txt, re-run cmake .., then cmake --build .

Single-File Compilation (Without CMake)

For quick one-off tests, compile a single file directly with g++:
g++ -std=c++20 concepts.cpp -o concepts && ./concepts
g++ -std=c++20 stl.cpp -o stl && ./stl
g++ -std=c++20 move_constructor.cpp -o move_ctor && ./move_ctor
Use CMake for anything involving more than one source file, or when you need consistent flags across all files in the project.

Build docs developers (and LLMs) love