-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
147 lines (120 loc) · 4.37 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
cmake_minimum_required(VERSION 3.14)
project(tl-ranges
HOMEPAGE_URL https://tl.tartanllama.xyz
DESCRIPTION "Ranges that didn't make C++20"
VERSION 0.1.0
LANGUAGES CXX)
include(CMakePackageConfigHelpers)
include(CMakeDependentOption)
include(GNUInstallDirs)
include(FetchContent)
include(CTest)
find_program(DPKG_BUILDPACKAGE_FOUND dpkg-buildpackage)
find_program(RPMBUILD_FOUND rpmbuild)
option(RANGES_BUILD_PACKAGE "Build packages" ON)
cmake_dependent_option(RANGES_BUILD_TESTS
"Enable tl::ranges tests" ON
"BUILD_TESTING" OFF)
cmake_dependent_option(RANGES_BUILD_PACKAGE_DEB
"Create DEB Package (${PROJECT_NAME})" ON
"RANGES_BUILD_PACKAGE;DPKG_BUILDPACKAGE_FOUND" OFF)
cmake_dependent_option(RANGES_BUILD_PACKAGE_RPM
"Create RPM Package (${PROJECT_NAME})" ON
"RANGES_BUILD_PACKAGE;RPMBUILD_FOUND" OFF)
cmake_dependent_option(RANGES_BUILD_PACKAGE_MSI
"Create MSI (${PROJECT_NAME})" ON
"RANGES_BUILD_PACKAGE;CMAKE_HOST_WIN32" OFF)
add_library(ranges INTERFACE)
target_include_directories(ranges
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
add_library(tl::ranges ALIAS ranges)
endif()
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}")
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT)
install(TARGETS ranges EXPORT ${PROJECT_NAME}-targets)
install(EXPORT ${PROJECT_NAME}-targets
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
NAMESPACE tl::
FILE "${PROJECT_NAME}-targets.cmake")
install(FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}")
install(DIRECTORY "include/" TYPE INCLUDE)
if (RANGES_BUILD_TESTS)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(CATCH_INSTALL_HELPERS OFF)
set(CATCH_BUILD_TESTING OFF)
set(CATCH_INSTALL_DOCS OFF)
FetchContent_Declare(Catch2 URL
https://github.com/catchorg/Catch2/archive/v2.9.2.zip)
FetchContent_MakeAvailable(Catch2)
file(GENERATE OUTPUT catch.main.cpp
CONTENT [[
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
]])
set_property(SOURCE ${PROJECT_BINARY_DIR}/catch.main.cpp
PROPERTY
GENERATED ON)
add_library(${PROJECT_NAME}-catch-main OBJECT)
target_sources(${PROJECT_NAME}-catch-main PRIVATE
${PROJECT_BINARY_DIR}/catch.main.cpp)
target_compile_options(${PROJECT_NAME}-catch-main
PUBLIC
$<$<AND:$<CXX_COMPILER_ID:Clang>,$<BOOL:"$ENV{TRAVIS}">>:-stdlib=libc++>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra>)
target_link_options(${PROJECT_NAME}-catch-main
PUBLIC
$<$<AND:$<CXX_COMPILER_ID:Clang>,$<BOOL:"$ENV{TRAVIS}">>:-stdlib=libc++>)
target_link_libraries(${PROJECT_NAME}-catch-main
PUBLIC
Catch2::Catch2
ranges)
file(GLOB test-sources CONFIGURE_DEPENDS tests/*.cpp)
foreach (source IN LISTS test-sources)
get_filename_component(name "${source}" NAME_WE)
set(test "${PROJECT_NAME}-test-${name}")
add_executable(${test}
"${source}"
$<TARGET_OBJECTS:${PROJECT_NAME}-catch-main>)
if(MSVC)
set_target_properties(${test} PROPERTIES CXX_STANDARD 23)
else()
set_target_properties(${test} PROPERTIES CXX_STANDARD 20)
endif()
target_link_libraries(${test}
PRIVATE
${PROJECT_NAME}-catch-main)
add_test(NAME ${PROJECT_NAME}::test::${name} COMMAND ${test})
endforeach()
endif()
if (NOT RANGES_BUILD_PACKAGE)
return()
endif()
list(APPEND source-generators TBZ2 TGZ TXZ ZIP)
if (RANGES_BUILD_PACKAGE_MSI)
list(APPEND binary-generators "WIX")
endif()
if (RANGES_BUILD_PACKAGE_DEB)
list(APPEND binary-generators "DEB")
endif()
if (RANGES_BUILD_PACKAGE_RPM)
list(APPEND binary-generators "RPM")
endif()
set(CPACK_SOURCE_GENERATOR ${source-generators})
set(CPACK_GENERATOR ${binary-generators})
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILENAME}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sy Brand")
list(APPEND CPACK_SOURCE_IGNORE_FILES /.git/ /build/ .gitignore .DS_Store)
include(CPack)