# Cmake

An introduction to modern Cmake

# A basic starting point

The most basic project is an executable built from source code files. For simple projects, a three line CMakeLists.txt file is all that is required. This will be the starting point for our tutorial. Create a CMakeLists.txt file in the Step1 directory that looks like:

cmake_minimum_required(VERSION 3.10)

# set the project name
project(Tutorial)

# add the executable
add_executable(Tutorial tutorial.cxx)
1
2
3
4
5
6
7

Note that this example uses lower case commands in the CMakeLists.txt file. Upper, lower, and mixed case commands are supported by CMake. The source code for tutorial.cxx is provided in the Step1 directory and can be used to compute the square root of a number.

# Introduction to Cmake - Florent Castelli

# Hello CMake

CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(hello-world)

add_excutable(hello-world
    hello.cpp
)
1
2
3
4
5
6

to build:

mkdir -p out

cd out

cmake ..

cmake --build .

./hello-world

Hello world!

Interpreter mode

cmake -P script.cmake

# CMake and CTest

CMake and CTest