-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
115 lines (97 loc) · 2.91 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
cmake_minimum_required(VERSION 3.23)
project(
MyFibonacci
VERSION 0.0.0
DESCRIPTION "A starter C++ project for generating a Fibonacci sequence."
HOMEPAGE_URL https://github.com/threeal/cpp-starter
LANGUAGES CXX
)
option(MY_FIBONACCI_ENABLE_TESTS "Enable test targets.")
option(MY_FIBONACCI_ENABLE_INSTALL "Enable install targets."
"${PROJECT_IS_TOP_LEVEL}")
function(cpmaddpackage)
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.2/CPM.cmake
${CMAKE_BINARY_DIR}/_deps/CPM.cmake
EXPECTED_MD5 4d51aa9dab6104fad39c5b7a692d5e1c
)
include(${CMAKE_BINARY_DIR}/_deps/CPM.cmake)
cpmaddpackage(${ARGN})
endfunction()
if(MY_FIBONACCI_ENABLE_TESTS)
find_package(CheckWarning 3.2.0 QUIET)
if(NOT CheckWarning_FOUND)
cpmaddpackage(gh:threeal/[email protected])
endif()
add_check_warning(TREAT_WARNINGS_AS_ERRORS)
endif()
find_package(argparse QUIET)
if(NOT argparse_FOUND)
cpmaddpackage(gh:p-ranav/[email protected])
endif()
add_library(sequence src/sequence.cpp)
target_sources(
sequence PUBLIC
FILE_SET HEADERS
BASE_DIRS include
FILES include/my_fibonacci/sequence.hpp
)
target_compile_features(sequence PRIVATE cxx_std_11)
add_executable(generate_sequence src/main.cpp)
target_link_libraries(generate_sequence PUBLIC argparse::argparse sequence)
if(MY_FIBONACCI_ENABLE_TESTS)
enable_testing()
find_package(ut QUIET)
if(NOT ut_FOUND)
cpmaddpackage(
NAME ut
GITHUB_REPOSITORY boost-ext/ut
VERSION 2.1.0
OPTIONS "BOOST_UT_DISABLE_MODULE ON"
)
endif()
get_target_property(sequence_SOURCES sequence SOURCES)
get_target_property(sequence_HEADER_DIRS sequence HEADER_DIRS)
add_executable(sequence_test test/sequence_test.cpp ${sequence_SOURCES})
target_include_directories(sequence_test PRIVATE ${sequence_HEADER_DIRS})
target_link_libraries(sequence_test PRIVATE Boost::ut)
include(cmake/CheckCoverage.cmake)
target_check_coverage(sequence_test)
add_test(NAME "Sequence Test" COMMAND sequence_test)
endif()
if(MY_FIBONACCI_ENABLE_TESTS)
find_package(FixFormat QUIET)
if(NOT FixFormat_FOUND)
cpmaddpackage(gh:threeal/[email protected])
list(APPEND CMAKE_MODULE_PATH ${FixFormat_SOURCE_DIR}/cmake)
endif()
include(FixFormat)
add_fix_format()
endif()
if(MY_FIBONACCI_ENABLE_INSTALL)
install(
TARGETS generate_sequence sequence
EXPORT my_fibonacci_targets
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
FILE_SET HEADERS
)
install(
EXPORT my_fibonacci_targets
FILE MyFibonacciTargets.cmake
NAMESPACE my_fibonacci::
DESTINATION lib/cmake/MyFibonacci
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
MyFibonacciConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
install(
FILES
cmake/MyFibonacciConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/MyFibonacciConfigVersion.cmake
DESTINATION lib/cmake/MyFibonacci
)
endif()