-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
179 lines (147 loc) · 5.65 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
cmake_minimum_required(VERSION 3.5)
# Disable defaulting the warning flags for MSVC
# this isn't bad, it's just inconvenient
cmake_policy(SET CMP0092 NEW)
if (PROJECT_NAME)
set(IS_SUBPROJECT TRUE)
endif ()
set(BACKPORT_CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(BACKPORT_CMAKE_TEMPLATE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/templates")
set(CMAKE_MODULE_PATH "${BACKPORT_CMAKE_MODULE_PATH}" "${CMAKE_MODULE_PATH}")
option(BACKPORT_COMPILE_UNIT_TESTS "Compile and run the unit tests for this library" OFF)
if (NOT CMAKE_TESTING_ENABLED AND BACKPORT_COMPILE_UNIT_TESTS)
enable_testing()
endif ()
project(Backport
VERSION "1.2.0"
LANGUAGES CXX
)
set(BACKPORT_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} CACHE INTERNAL "Major version of Backport")
set(BACKPORT_VERSION_MINOR ${PROJECT_VERSION_MINOR} CACHE INTERNAL "Minor version of Backport")
set(BACKPORT_VERSION_PATCH ${PROJECT_VERSION_PATCH} CACHE INTERNAL "Patch version of Backport")
set(BACKPORT_VERSION ${PROJECT_VERSION} CACHE INTERNAL "Version of Backport")
# If using conan, only set the find paths. This project is trying to be
# fully CMake
if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake")
conan_set_find_paths()
endif ()
##############################################################################
# Targets
##############################################################################
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(header_files
"include/bpstd/detail/nth_type.hpp"
"include/bpstd/detail/variant_fwds.hpp"
"include/bpstd/detail/variant_union.hpp"
"include/bpstd/detail/variant_base.hpp"
"include/bpstd/detail/variant_traits.hpp"
"include/bpstd/detail/variant_visitors.hpp"
"include/bpstd/detail/move.hpp"
"include/bpstd/detail/invoke.hpp"
"include/bpstd/detail/proxy_iterator.hpp"
"include/bpstd/detail/config.hpp"
"include/bpstd/type_traits.hpp"
"include/bpstd/complex.hpp"
"include/bpstd/exception.hpp"
"include/bpstd/functional.hpp"
"include/bpstd/memory.hpp"
"include/bpstd/utility.hpp"
"include/bpstd/tuple.hpp"
"include/bpstd/any.hpp"
"include/bpstd/cstddef.hpp"
"include/bpstd/string_view.hpp"
"include/bpstd/optional.hpp"
"include/bpstd/iterator.hpp"
"include/bpstd/span.hpp"
"include/bpstd/chrono.hpp"
"include/bpstd/string.hpp"
"include/bpstd/variant.hpp"
)
include(SourceGroup)
source_group_tree("include" PREFIX "Header Files" FILES ${header_files})
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
INTERFACE $<INSTALL_INTERFACE:include>
)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND
"${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
# clang-cl does not appear to implement '-pedantic' or 'pedantic-errors',
# so this case needs to be handled specifically
add_compile_options(-Wall -Werror -Wextra)
# Disable the ridiculous compatibility warnings, since it fails on files not
# ending in newlines
add_compile_options(-Wno-c++98-compat -Wno-c++98-compat-pedantic)
# This gives an unbelievable amount of false-positives spuriously. Ignore it.
add_compile_options(-Wno-unneeded-member-function)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
add_compile_options(-Wall -Werror -Wextra -pedantic -pedantic-errors)
elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" )
add_compile_options(/W4 /WX)
endif ()
# Header Self-Containment Tests
include(AddSelfContainmentTest)
if (BACKPORT_COMPILE_UNIT_TESTS)
add_self_containment_test(${PROJECT_NAME}.SelfContainmentTest
TARGET ${PROJECT_NAME}
HEADERS ${header_files}
)
add_subdirectory("test")
endif ()
##############################################################################
# Installation
##############################################################################
if (IS_SUBPROJECT)
return()
endif ()
include(CMakePackageConfigHelpers)
# The generated ConfigVersion is tied to the architecture it's generated on,
# denoted by the size of the pointer. Since this is a header-only library,
# this is an unnecessary and constricting check -- but CMake does not allow us
# to customize it.
#
# A simple workaround is to simply set the CMAKE_SIZEOF_VOID_P to an empty
# string in CMake so that the generated file does not fail to work on different
# architectures. This gets reset after we generate the file
set(TEMP_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
set(CMAKE_SIZEOF_VOID_P "")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY
SameMajorVersion
)
set(CMAKE_SIZEOF_VOID_P ${TEMP_CMAKE_SIZEOF_VOID_P})
configure_file(
"${BACKPORT_CMAKE_TEMPLATE_PATH}/PackageConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
@ONLY
)
#-----------------------------------------------------------------------------
include(GNUInstallDirs)
set(BACKPORT_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
# Includes
install(
DIRECTORY "include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
# Targets
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE "Backport::"
DESTINATION "${BACKPORT_CMAKE_CONFIG_DESTINATION}"
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${BACKPORT_CMAKE_CONFIG_DESTINATION}"
)