Build Project with CMake
Posted by binglongx on July 10, 2024
While some projects use traditional configure and make approach, a lot of projects now use CMake to help building.
CMake is a meta build system. CMake itself does not build your project.
- Projects using CMake would store project settings in CMakeLists.txt files.
- You can run
cmaketo create actual project files suitable for concrete build tools to build. Examples are:cmakegenerates Makefile, to be consumed bymaketo build the project;cmakegenerates Xcode project files, to be consumed by Xcode to build the project on macOS;cmakegenerates Visual Studio project files, to be consumed by Visual Studio/C++ to build the project on Windows;
As you can see, CMake enables you to create projects with build portability.

The diagram above is generated from Mermaid:
%% Mermaid drawing, view with https://mermaid.live/
flowchart LR
classDef Executable fill:#411,stroke-width:2px;
classDef File fill:#141,stroke-width:2px;
src[source code]:::File
cmake_list[CMakeLists.txt]:::File
cmake([cmake]):::Executable
cmakex([cmake -G Xcode]):::Executable
makefile[Makefile]
xproj[Xcode project]
make([make]):::Executable
make_c([cmake --build]):::Executable
xcode([Xcode]):::Executable
exe[executable]
exe_x[executable]
cmake_list --> cmake --> makefile
cmake_list --> cmakex --> xproj
makefile --> make --> exe
makefile --> make_c --> exe
xproj --> xcode --> exe_x
src --> make
src --> make_c
src --> xcode
subgraph source code repo
cmake_list
src
end
subgraph cmake stage
cmake
cmakex
makefile
xproj
end
subgraph build stage
make
make_c
xcode
exe
exe_x
end
Unix project: configure and make « Binglong's space said
[…] Build Project with CMake […]