CMake is a “metabuilder”. It doesn’t actually run the build itself, it just generates the right commands to be able to use it with other generators like Unix Makefiles, ninja, etc.

It is configured using the CMakeLists.txt

The Plumbing

This is required for every CML

cmake_minimum_required(VERSION 3.15)

Some people use the 3.15...4.1 for shit

Then, you need a line for project

project(MyProject VERSION 1.0
					DESCRIPTION "cool proj"
					LANGUAGES CXX)

When CMake sees the project() command it performs various checks to ensure the environment is suitable for building software; such as checking for compilers and other build tooling, and discovering properties like the endianness of the host and target machines. [Cmake](https://cmake.org/cmake/help/latest/guide/tutorial/Getting%20Started%20with%20CMake.htm

Syntax

CMake operates on “commands”. Every way of configuring is done by calling FUNCTION_NAME()

Targets

In CMake, targets is a name the developer gives to a set of properties. For example some possible targets are:

  • \libraries
  • executables
  • custom

you tell cmake that using

add_executable(one two.cpp three.h)

one is executable generated and name of Target, then list of source file lists

add_library(one STATIC two.cpp three.h)

pick between STATIC SHARED MODULE

you can ask directories

target_include_directories(one PUBLIC include)

PUBLIC for library: any targets link it also need to include this, PRIVATE only affects current target, not deps, and INTERFACE is needed for consumers, not by the lib itself

taget_link_libraries(another PUBLIC one)

takes a target (target) and adds a dependency if a target is given. if no target of the name (one) exist, adds a link to a library called one on your path. or give it path to a library. or linker flag.

https://cmake.org/cmake/help/latest/command/target_link_libraries.html
https://cliutils.gitlab.io/modern-cmake/README.html

PRIVATE = I need it. Don’t tell anyone else.
INTERFACE = I don’t need it. Tell everyone else.
PUBLIC = I need it. AND tell everyone else.

https://www.youtube.com/watch?v=bsXLMQ6WgIk

Options

use -D to activate, -LH for human readable