-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
144 lines (123 loc) · 3.86 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
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
cmake_minimum_required(VERSION 3.25)
project(
beman.any_view
DESCRIPTION "A generalized type-erased view with customizable properties"
LANGUAGES CXX
)
# [CMAKE.SKIP_TESTS]
option(
BEMAN_ANY_VIEW_BUILD_TESTS
"Enable building tests and test infrastructure. Default: ON. Values: { ON, OFF }."
${PROJECT_IS_TOP_LEVEL}
)
# [CPP.NO_FLAG_FORKING]
set(BEMAN_ANY_VIEW_DESIGN
"FLAGS"
CACHE STRING
"Enable alternative design for any_view_options. Default: FLAGS. Values: { FLAGS, TRAITS, NAMED }."
)
set(BEMAN_ANY_VIEW_OPTION
"COPYABLE"
CACHE STRING
"Enable opt-in option for any_view. Default: COPYABLE. Values: { COPYABLE, MOVE_ONLY }."
)
set(BEMAN_ANY_VIEW_USE_FLAGS OFF)
set(BEMAN_ANY_VIEW_USE_TRAITS OFF)
set(BEMAN_ANY_VIEW_USE_NAMED OFF)
set(BEMAN_ANY_VIEW_USE_COPYABLE OFF)
set(BEMAN_ANY_VIEW_USE_MOVE_ONLY OFF)
if(BEMAN_ANY_VIEW_DESIGN STREQUAL "FLAGS")
set(BEMAN_ANY_VIEW_USE_FLAGS ON)
elseif(BEMAN_ANY_VIEW_DESIGN STREQUAL "TRAITS")
set(BEMAN_ANY_VIEW_USE_TRAITS ON)
elseif(BEMAN_ANY_VIEW_DESIGN STREQUAL "NAMED")
set(BEMAN_ANY_VIEW_USE_NAMED ON)
else()
message(
FATAL_ERROR
"BEMAN_ANY_VIEW_DESIGN must be one of { FLAGS, TRAITS, NAMED }; got ${BEMAN_ANY_VIEW_DESIGN}"
)
endif()
if(BEMAN_ANY_VIEW_OPTION STREQUAL "COPYABLE")
set(BEMAN_ANY_VIEW_USE_COPYABLE ON)
elseif(BEMAN_ANY_VIEW_OPTION STREQUAL "MOVE_ONLY")
set(BEMAN_ANY_VIEW_USE_MOVE_ONLY ON)
else()
message(
FATAL_ERROR
"BEMAN_ANY_VIEW_OPTION must be one of { COPYABLE, MOVE_ONLY }; got ${BEMAN_ANY_VIEW_OPTION}"
)
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/include/beman/any_view/config.hpp.in"
"${PROJECT_BINARY_DIR}/include/beman/any_view/config.hpp"
@ONLY
)
include(FetchContent)
include(GNUInstallDirs)
add_library(beman.any_view INTERFACE)
add_library(beman::any_view ALIAS beman.any_view)
set_target_properties(beman.any_view PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(beman.any_view INTERFACE cxx_std_20)
# TODO: implement non-template friend function and remove this suppression
target_compile_options(
beman.any_view
INTERFACE $<$<CXX_COMPILER_ID:GNU>:-Wno-non-template-friend>
)
target_include_directories(
beman.any_view
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
install(
TARGETS beman.any_view
EXPORT ${TARGETS_EXPORT_NAME}
DESTINATION
$<$<CONFIG:Debug>:debug/>${CMAKE_INSTALL_LIBDIR}
)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME}
FILES_MATCHING
PATTERN "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/any_view/*.hpp"
)
macro(beman_add_executable)
set(options)
set(oneValueArgs CATEGORY TARGET)
set(multiValueArgs SOURCES LIBRARIES)
cmake_parse_arguments(
beman_executable
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
set(target
"beman.any_view.${beman_executable_CATEGORY}.${beman_executable_TARGET}"
)
if(NOT beman_executable_SOURCES)
set(beman_executable_SOURCES "${beman_executable_TARGET}.cpp")
endif()
add_executable(${target})
target_sources(${target} PRIVATE ${beman_executable_SOURCES})
target_link_libraries(
${target}
PRIVATE beman::any_view ${beman_executable_LIBRARIES}
)
endmacro()
if(BEMAN_ANY_VIEW_BUILD_TESTS)
enable_testing()
# Fetch GoogleTest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
EXCLUDE_FROM_ALL
)
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
FetchContent_MakeAvailable(googletest)
add_subdirectory(tests/beman/any_view)
endif()