-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
127 lines (109 loc) · 3.7 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
cmake_minimum_required(VERSION 3.16)
project(hydra VERSION 0.0.1 LANGUAGES C CXX
DESCRIPTION "A convenience networking library for modern C++")
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(vendor/noa/cmake/noa.cmake)
# Options
option(HYDRA_CRYPTO "Build the Hydra crypto library" ON)
option(HYDRA_HTTPCLIENT "Build the Hydra HTTP client library" ON)
if(WIN32)
# TODO: Make it work on Windows. Main challenge is that uSockets
# relies on libuv for that platform.
option(HYDRA_HTTPSERVER "Build the Hydra HTTP server library" OFF)
else()
option(HYDRA_HTTPSERVER "Build the Hydra HTTP server library" ON)
endif()
option(HYDRA_BUCKET "Build the Hydra bucket library" ON)
option(HYDRA_TESTS "Build the Hydra tests" OFF)
option(HYDRA_DOCS "Build the Hydra docs" OFF)
option(HYDRA_INSTALL "Install the Hydra library" ON)
option(HYDRA_ADDRESS_SANITIZER "Build Hydra with an address sanitizer" OFF)
option(HYDRA_UNDEFINED_SANITIZER "Build Hydra with an undefined behavior sanitizer" OFF)
if(HYDRA_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
configure_package_config_file(
config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
COMPATIBILITY SameMajorVersion)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
COMPONENT sourcemeta_hydra_dev)
endif()
if(HYDRA_HTTPCLIENT OR HYDRA_HTTPSERVER OR HYDRA_BUCKET)
add_subdirectory(src/http)
endif()
if(HYDRA_CRYPTO OR HYDRA_HTTPCLIENT OR HYDRA_BUCKET)
find_package(BearSSL REQUIRED)
endif()
if(HYDRA_CRYPTO OR HYDRA_HTTPSERVER OR HYDRA_BUCKET)
add_subdirectory(src/crypto)
endif()
if(HYDRA_HTTPCLIENT OR HYDRA_BUCKET)
find_package(ZLIB REQUIRED)
find_package(CURL REQUIRED)
add_subdirectory(src/httpclient)
endif()
if(HYDRA_HTTPSERVER)
find_package(ZLIB REQUIRED)
find_package(uSockets REQUIRED)
find_package(uWebSockets REQUIRED)
add_subdirectory(src/httpserver)
endif()
if(HYDRA_BUCKET)
find_package(JSONToolkit REQUIRED COMPONENTS json uri)
add_subdirectory(src/bucket)
endif()
if(HYDRA_ADDRESS_SANITIZER)
noa_sanitizer(TYPE address)
elseif(HYDRA_UNDEFINED_SANITIZER)
noa_sanitizer(TYPE undefined)
endif()
if(HYDRA_DOCS)
noa_target_doxygen(CONFIG "${PROJECT_SOURCE_DIR}/doxygen/Doxyfile.in"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/website")
endif()
if(PROJECT_IS_TOP_LEVEL)
noa_target_clang_format(SOURCES
src/*.cc src/*.h test/*.cc test/*.h)
noa_target_clang_tidy(SOURCES
src/*.h src/*.cc)
endif()
# Testing
if(HYDRA_TESTS)
find_package(GoogleTest REQUIRED)
enable_testing()
if(HYDRA_HTTPCLIENT OR HYDRA_HTTPSERVER OR HYDRA_BUCKET)
add_subdirectory(test/unit/http)
endif()
if(HYDRA_CRYPTO)
add_subdirectory(test/unit/crypto)
endif()
if(HYDRA_HTTPCLIENT)
add_subdirectory(test/e2e/httpclient)
endif()
if(HYDRA_HTTPSERVER)
add_subdirectory(test/unit/httpserver)
find_package(JSONToolkit REQUIRED COMPONENTS json)
# Because we need to test with an HTTP client
if(HYDRA_HTTPCLIENT)
add_subdirectory(test/e2e/httpserver)
endif()
endif()
if(HYDRA_BUCKET)
add_subdirectory(test/unit/bucket)
add_subdirectory(test/e2e/bucket)
endif()
if(PROJECT_IS_TOP_LEVEL)
# Otherwise we need the child project to link
# against the sanitizers too.
if(NOT HYDRA_ADDRESS_SANITIZER AND NOT HYDRA_UNDEFINED_SANITIZER)
add_subdirectory(test/packaging)
endif()
endif()
endif()