2020-08-12 20:29:56 +02:00
|
|
|
# CMake simple example
|
|
|
|
|
2019-02-22 17:54:10 +01:00
|
|
|
## [main]
|
|
|
|
|
2019-02-21 22:28:07 +01:00
|
|
|
# Almost all CMake files should start with this
|
|
|
|
# You should always specify a range with the newest
|
|
|
|
# and oldest tested versions of CMake. This will ensure
|
|
|
|
# you pick up the best policies.
|
2020-11-18 17:52:58 +01:00
|
|
|
cmake_minimum_required(VERSION 3.1...3.19)
|
2019-02-21 22:28:07 +01:00
|
|
|
|
|
|
|
# This is your project statement. You should always list languages;
|
|
|
|
# Listing the version is nice here since it sets lots of useful variables
|
2020-08-04 00:16:52 +02:00
|
|
|
project(
|
|
|
|
ModernCMakeExample
|
|
|
|
VERSION 1.0
|
|
|
|
LANGUAGES CXX)
|
2019-02-21 22:28:07 +01:00
|
|
|
|
|
|
|
# If you set any CMAKE_ variables, that can go here.
|
|
|
|
# (But usually don't do this, except maybe for C++ standard)
|
|
|
|
|
|
|
|
# Find packages go here.
|
|
|
|
|
|
|
|
# You should usually split this into folders, but this is a simple example
|
|
|
|
|
|
|
|
# This is a "default" library, and will match the *** variable setting.
|
|
|
|
# Other common choices are STATIC, SHARED, and MODULE
|
|
|
|
# Including header files here helps IDEs but is not required.
|
|
|
|
# Output libname matches target name, with the usual extensions on your system
|
|
|
|
add_library(MyLibExample simple_lib.cpp simple_lib.hpp)
|
|
|
|
|
|
|
|
# Link each target with other targets or add options, etc.
|
|
|
|
|
|
|
|
# Adding something we can run - Output name matches target name
|
|
|
|
add_executable(MyExample simple_example.cpp)
|
|
|
|
|
|
|
|
# Make sure you link your targets with this command. It can also link libraries and
|
|
|
|
# even flags, so linking a target that does not exist will not give a configure-time error.
|
|
|
|
target_link_libraries(MyExample PRIVATE MyLibExample)
|
|
|
|
|
2019-02-22 17:54:10 +01:00
|
|
|
## [main]
|
|
|
|
|
2019-02-21 22:28:07 +01:00
|
|
|
# This part is so the Modern CMake book can verify this example builds. For your code,
|
|
|
|
# you'll probably want tests too
|
|
|
|
enable_testing()
|
|
|
|
add_test(NAME MyExample COMMAND MyExample)
|