Introduction to cmake
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Time Travel Interface Library
A CMake project is typically organized as a tree in a folder structure.
With command add_subdirectory
a CMakeLists.txt
adds a sub-folders to the project.
Each directory sub-folders must contain a CMakeLists.txt
.
A library is added with command add_library
.
It is good practice to add an alias target for the library.
The name of the alias library should use a namespace.
Example:
add_library(apple INTERFACE)
add_library(fruit::apple ALIAS apple)
Exercise 2
Add an interface library called time_travel
and with an alias time_machine::time_travel
.
The library is in sub-folder time_travel_interface
.
The library shall provide the include path include
to its dependants by using command target_include_directories
.
[project]/
+--- CMakeLists.txt
+--- time_travel_interface/
| +--- CMakeLists.txt
| +--- include/
| +--- time_travel/
| +--- time_travel.h
+--- ...
Run CMake
1
2
3
4
5
# [project]/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project("TimeMachine" VERSION 1.0.2 LANGUAGES CXX)
Enter to Rename, Shift+Enter to Preview
1
# [project]/time_travel_interface/CMakeLists.txt
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content