CMake is a tool to manage building of source code.
The top-level CMakeLists.txt is the entry point of our project.There can be several CMakeLists.txt files in subdirectories (for example, libraries or other executables associated with the project). Example:
cmake_minimum_required(VERSION 3.22.2)
# set the project name and version
project(cmake_learn VERSION 1.0)
# Build
add_executable(${PROJECT_NAME} main.cpp)The first line is the version of CMake, which is required to process the file, the second is the project name and its versions.The next line specifies which binary to build and their related source files.
mkdir build
cd build
cmake ..
makeThis method is cleaner and more cross-platform-friendly:
mkdir build
cmake -S . -B build
cmake --build build- Basics of cmake
- Build and run
- Libraries
- Submodules
- Variables