CMake : A Quick Primer
Introduction
CMake is a build system generator that allows you to create build scripts (like Makefiles, Visual Studio projects, etc.) in a platform-independent way. It helps manage the build process for C/C++ projects.
Key Concepts
- CMakeLists.txt: The main configuration file for CMake.
cmake
command: Used to generate build files.make
command: Used to compile the project (on Unix-like systems).
Code Sample
In this chapter, and beyond, we will be actively working with CMake
. Grab your favourite text editor, and C++
compiler and get ready to code.
- Create a file
main.cpp
:
- Create a
CMakeLists.txt
file in the same directory:
- Build and run the project:
- Output: