Cmake Ninja
Cmake Ninja
Cmake Ninja
by István Papp
istvan.papp@ericsson.com
Hello & Disclaimer
Introduction
Definitions
CMake
Example
CMake as a language
Other command line tools
Ninja
Tying it all together
Definitions
110
</> 011
Requirements
Speed
Reliability
Flexibility
Requirements - Speed
Fast feedback
Catch errors ASAP
Avoid breaking stuff for others
Conserve resources
No effect on the compiler*
Avoid work
Parallel execution
Umbrella term
Deterministic
Stable
No unexpected behaviour
Requirements - Flexibility
Introduction
Definitions
CMake
Example
CMake as a language
Other command line tools
Ninja
Tying it all together
CMake
Executable/binary format
Path separators
Platform-dependent libraries
Capabilities – in-place & out-of-place
Introduction
Definitions
CMake
Example
CMake as a language
Other command line tools
Ninja
Tying it all together
A simple example
<project_root>
|--build
|--inc
| `--<header files>
`--src
|--main.cc
`--CMakeLists.txt
A simple example
<project_root>/src/CMakeLists.txt:
Adding a library
<project_root>
|--build
|--inc
| `--<header files>
|--src
| |--main.cc
| `--CMakeLists.txt
`--graphics
|--inc
| `--<library header files>
|--src
| |--bells.cc
| |--whistes.cc
| `--CMakeLists.txt
`--CMakeLists.txt
Adding a library
<project_root>/src/CMakeLists.txt:
Adding a library
<project_root>/graphics/CMakeLists.txt:
Adding a library
<project_root>/graphics/src/CMakeLists.txt:
Using the example
cd <project_root>/build
cmake ../src && make
Introduction
Definitions
CMake
Example
CMake as a language
Other command line tools
Ninja
Tying it all together
Variables
Variables
Lists
Lists
Conditionals
Conditionals
Formatting
Other rules
Everything else
Introduction
Definitions
CMake
Example
CMake as a language
Other command line tools
Ninja
Tying it all together
CTest
Introduction
Definitions
CMake
Example
CMake as a language
Other command line tools
Ninja
Tying it all together
Ninja
Generated input
Still human-readable
Prefer speed over convenience
Do one thing, and do it well
How?
Multiplatform
Very fast when there's nothing to do
Think “incremental build”
One environment variable: NINJA_STATUS
Controls the output’s format
Some more nice features
Don't
build.ninja syntax
cflags = -Wall
rule cc
command = gcc $cflags -c $in -o $out
Introduction
Definitions
CMake
Example
CMake as a language
Other command line tools
Ninja
Tying it all together
Tying it all together