# Introduction to cmake

raphaelmeyer
11.7K views

## Solution Exercise 2

Here is a sample solution of the CMakeLists.txt for the time travel interface library.

# [project]/time_travel_interface/CMakeLists.txt

target_include_directories(time_travel INTERFACE include)


### Project settings

Interface libraries can also be used to define project settings. For example the required C++ standard or additional compiler flags.

Attention: Only define compiler flags if you have a really good reason. Adding compiler flags will break the portability and compatibility of your project.

Example:

[project]/
+--- CMakeLists.txt
+--- settings/
|    +--- CMakeLists.txt
+--- ...

# [project]/settings/CMakeLists.txt

target_compile_features(settings INTERFACE cxx_std_17)

target_compile_options(settings
INTERFACE
"-Wall"
"-Wextra"
"-Werror"
)


In addition to CMake commands target_compile_features and target_compile_options from the example, there is also a command target_compile_definitions.

Open Source Your Knowledge: become a Contributor and help others learn.