forked from glynos/url
-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMakeLists.txt
217 lines (183 loc) · 7.34 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Copyright (c) Glyn Matthews 2012-2021.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
cmake_minimum_required(VERSION 3.21)
get_directory_property(skyr_is_subproject PARENT_DIRECTORY)
if(NOT skyr_is_subproject)
set(skyr_IS_TOP_LEVEL_PROJECT YES)
else()
set(skyr_IS_TOP_LEVEL_PROJECT NO)
endif()
project(
skyr-url
VERSION 2.0.1
HOMEPAGE_URL https://cpp-netlib.github.io/url
DESCRIPTION "A C++ library that implements the WhatWG URL specification"
LANGUAGES CXX
)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
option(skyr_BUILD_TESTS "Build the URL tests." ON)
option(skyr_BUILD_DOCS "Build the URL documentation." OFF)
option(skyr_BUILD_EXAMPLES "Build the URL examples." OFF)
option(skyr_FULL_WARNINGS "Build the library with all warnings turned on." ON)
option(skyr_WARNINGS_AS_ERRORS "Treat warnings as errors." ON)
option(skyr_BUILD_WITHOUT_EXCEPTIONS "Build without exceptions." OFF)
option(skyr_BUILD_WITHOUT_RTTI "Build without RTTI." OFF)
option(skyr_USE_STATIC_CRT "Use static C Runtime library (/MT or MTd)." ON)
option(skyr_BUILD_WITH_LLVM_LIBCXX "Instruct Clang to use LLVM's implementation of C++ standard library" OFF)
option(skyr_ENABLE_FILESYSTEM_FUNCTIONS "Enable functions to convert URL to std::filesystem::path" ON)
option(skyr_ENABLE_JSON_FUNCTIONS "Enable functions to convert URL components to JSON" ON)
option(skyr_BUILD_V1 "Build v1" ON)
option(skyr_BUILD_V2 "Build v2, which uses C++20 features" OFF)
if (skyr_IS_TOP_LEVEL_PROJECT)
if(skyr_BUILD_V2)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
include(skyr-url-options)
include(skyr-url-env)
include(skyr-url-flags)
include(cmake/CPM.cmake)
CPMAddPackage(
NAME expected
GITHUB_REPOSITORY TartanLlama/expected
GIT_TAG v1.1.0
OPTIONS "EXPECTED_BUILD_TESTS OFF" #pulls is super old catch2
)
CPMAddPackage("gh:ericniebler/range-v3#0.12.0")
CPMAddPackage("gh:fmtlib/fmt#10.1.1")
if (skyr_ENABLE_JSON_FUNCTIONS)
CPMAddPackage(
NAME json
GITHUB_REPOSITORY nlohmann/json
GIT_TAG v3.11.3
OPTIONS "JSON_Install ON"
)
endif()
if (skyr_USE_STATIC_CRT AND (SKY_CXX_COMPILER_CLANGCL OR SKY_CXX_COMPILER_MSVC))
include(${PROJECT_SOURCE_DIR}/cmake/skyr-url-functions.cmake)
skyr_replace_dynamic_msvcrt_linker_flags()
endif()
set(full_warnings $<BOOL:${skyr_FULL_WARNINGS}>)
set(warnings_as_errors $<BOOL:${skyr_WARNINGS_AS_ERRORS}>)
set(no_exceptions $<BOOL:${skyr_BUILD_WITHOUT_EXCEPTIONS}>)
set(no_rtti $<BOOL:${skyr_BUILD_WITHOUT_RTTI}>)
set(gnu $<BOOL:${SKY_CXX_COMPILER_GCC}>)
set(clang $<BOOL:${SKY_CXX_COMPILER_CLANG}>)
set(libcxx $<AND:${clang},$<BOOL:${skyr_BUILD_WITH_LLVM_LIBCXX}>>)
set(clang_with_gnu_stdlib $<AND:${clang},$<NOT:$<BOOL:${skyr_BUILD_WITH_LLVM_LIBCXX}>>>)
set(msvc $<BOOL:${SKY_CXX_COMPILER_MSVC}>)
add_subdirectory(src)
# Testing
if (skyr_BUILD_TESTS)
message(STATUS "[skyr-url] Configuring tests")
CPMAddPackage("gh:catchorg/[email protected]")
enable_testing()
add_subdirectory(tests)
endif()
# Documentation
if (skyr_BUILD_DOCS)
message(STATUS "[skyr-url] Configuring documentation")
add_subdirectory(docs)
endif()
# Examples
if (skyr_BUILD_EXAMPLES)
message(STATUS "[skyr-url] Configuring examples")
add_subdirectory(examples)
endif()
if (skyr_BUILD_V1)
# Add an alias for projects that use skyr-url as a dependency
if (NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
add_library(skyr::skyr-url ALIAS skyr-url-v1)
add_library(skyr::url ALIAS skyr-url-v1)
if (skyr_ENABLE_FILESYSTEM_FUNCTIONS)
add_library(skyr::skyr-filesystem ALIAS skyr-filesystem-v1)
add_library(skyr::filesystem ALIAS skyr-filesystem-v1)
endif()
if (skyr_ENABLE_JSON_FUNCTIONS)
add_library(skyr::skyr-json ALIAS skyr-json-v1)
add_library(skyr::json ALIAS skyr-json-v1)
endif()
endif()
## Install
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "share/cmake/${PROJECT_NAME}")
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT)
set(skyr_TARGETS skyr-url-v1)
if (skyr_ENABLE_FILESYSTEM_FUNCTIONS)
list(APPEND skyr_TARGETS skyr-filesystem-v1)
endif()
if (skyr_ENABLE_JSON_FUNCTIONS)
list(APPEND skyr_TARGETS skyr-json-v1)
endif()
install(TARGETS ${skyr_TARGETS}
EXPORT ${PROJECT_NAME}-targets
INCLUDES DESTINATION "${CMAKE_INSTALL_DATADIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(EXPORT ${PROJECT_NAME}-targets
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}"
NAMESPACE skyr::
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
"${PROJECT_SOURCE_DIR}/include/skyr/core"
"${PROJECT_SOURCE_DIR}/include/skyr/domain"
"${PROJECT_SOURCE_DIR}/include/skyr/network"
"${PROJECT_SOURCE_DIR}/include/skyr/percent_encoding"
DESTINATION
include/skyr
)
install(
DIRECTORY
"${PROJECT_SOURCE_DIR}/include/skyr/v1/core"
"${PROJECT_SOURCE_DIR}/include/skyr/v1/domain"
"${PROJECT_SOURCE_DIR}/include/skyr/v1/network"
"${PROJECT_SOURCE_DIR}/include/skyr/v1/percent_encoding"
"${PROJECT_SOURCE_DIR}/include/skyr/v1/platform"
"${PROJECT_SOURCE_DIR}/include/skyr/v1/string"
"${PROJECT_SOURCE_DIR}/include/skyr/v1/traits"
"${PROJECT_SOURCE_DIR}/include/skyr/v1/unicode"
DESTINATION
include/skyr/v1
)
install(
FILES
"${PROJECT_BINARY_DIR}/include/skyr/version.hpp"
"${PROJECT_SOURCE_DIR}/include/skyr/config.hpp"
"${PROJECT_SOURCE_DIR}/include/skyr/url.hpp"
DESTINATION
include/skyr
)
install(
FILES
"${PROJECT_SOURCE_DIR}/include/skyr/v1/url.hpp"
"${PROJECT_SOURCE_DIR}/include/skyr/v1/url_search_parameters.hpp"
DESTINATION
include/skyr/v1
)
if (skyr_ENABLE_FILESYSTEM_FUNCTIONS)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/skyr/filesystem" DESTINATION include/skyr)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/skyr/v1/filesystem" DESTINATION include/skyr/v1)
endif()
if (skyr_ENABLE_JSON_FUNCTIONS)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/skyr/json" DESTINATION include/skyr)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/skyr/v1/json" DESTINATION include/skyr/v1)
endif()
endif()