| 1 |
# Almost all CMake files should start with this |
| 2 |
# You should always specify a range with the newest |
| 3 |
# and oldest tested versions of CMake. This will ensure |
| 4 |
# you pick up the best policies. |
| 5 |
cmake_minimum_required(VERSION 3.1...3.23) |
| 6 |
|
| 7 |
# This is your project statement. You should always list languages; |
| 8 |
# Listing the version is nice here since it sets lots of useful variables |
| 9 |
project( |
| 10 |
ModernCMakeExample |
| 11 |
VERSION 1.0 |
| 12 |
LANGUAGES CXX) |
| 13 |
|
| 14 |
# If you set any CMAKE_ variables, that can go here. |
| 15 |
# (But usually don't do this, except maybe for C++ standard) |
| 16 |
|
| 17 |
# Find packages go here. |
| 18 |
|
| 19 |
# You should usually split this into folders, but this is a simple example |
| 20 |
|
| 21 |
# This is a "default" library, and will match the *** variable setting. |
| 22 |
# Other common choices are STATIC, SHARED, and MODULE |
| 23 |
# Including header files here helps IDEs but is not required. |
| 24 |
# Output libname matches target name, with the usual extensions on your system |
| 25 |
add_library(MyLibExample simple_lib.cpp simple_lib.hpp) |
| 26 |
|
| 27 |
# Link each target with other targets or add options, etc. |
| 28 |
|
| 29 |
# Adding something we can run - Output name matches target name |
| 30 |
add_executable(MyExample simple_example.cpp) |
| 31 |
|
| 32 |
# Make sure you link your targets with this command. It can also link libraries and |
| 33 |
# even flags, so linking a target that does not exist will not give a configure-time error. |
| 34 |
target_link_libraries(MyExample PRIVATE MyLibExample) |
| 35 |
|
| 36 |
# From https://cliutils.gitlab.io/modern-cmake/chapters/basics/example.html |