|
1 |
| -cmake_minimum_required(VERSION 3.14) |
2 |
| - |
3 |
| -#set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time") |
| 1 | +cmake_minimum_required(VERSION 3.8...3.20) |
4 | 2 |
|
5 | 3 | # determine whether it's main/root project
|
6 | 4 | # or being built under another project.
|
7 | 5 | if (NOT DEFINED BOOST_REDIS_MAIN_PROJECT)
|
8 |
| - set(BOOST_REDIS_MAIN_PROJECT OFF) |
9 |
| - if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
10 |
| - set(BOOST_REDIS_MAIN_PROJECT ON) |
11 |
| - endif() |
| 6 | + set(BOOST_REDIS_MAIN_PROJECT OFF) |
| 7 | + if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
| 8 | + set(BOOST_REDIS_MAIN_PROJECT ON) |
| 9 | + endif() |
12 | 10 | endif()
|
13 | 11 |
|
14 |
| -project( |
15 |
| - boost_redis |
16 |
| - VERSION 1.4.2 |
17 |
| - DESCRIPTION "A redis client library" |
18 |
| - HOMEPAGE_URL "https://boostorg.github.io/redis/" |
19 |
| - LANGUAGES CXX |
20 |
| -) |
21 |
| - |
22 |
| -option(BOOST_REDIS_INSTALL "Generate install targets." ${BOOST_REDIS_MAIN_PROJECT}) |
23 |
| -option(BOOST_REDIS_TESTS "Build tests." ${BOOST_REDIS_MAIN_PROJECT}) |
24 |
| -option(BOOST_REDIS_EXAMPLES "Build examples." ${BOOST_REDIS_MAIN_PROJECT}) |
25 |
| -option(BOOST_REDIS_BENCHMARKS "Build benchmarks." ${BOOST_REDIS_MAIN_PROJECT}) |
26 |
| -option(BOOST_REDIS_DOC "Generate documentations." ${BOOST_REDIS_MAIN_PROJECT}) |
| 12 | +project(boost_redis VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) |
27 | 13 |
|
| 14 | +# Library |
28 | 15 | add_library(boost_redis INTERFACE)
|
29 | 16 | add_library(Boost::redis ALIAS boost_redis)
|
30 |
| -target_include_directories(boost_redis INTERFACE |
31 |
| - $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
32 |
| - $<INSTALL_INTERFACE:include> |
33 |
| -) |
34 |
| - |
35 |
| -target_link_libraries( |
36 |
| - boost_redis |
37 |
| - INTERFACE |
38 |
| - Boost::asio |
39 |
| - Boost::assert |
40 |
| - Boost::config |
41 |
| - Boost::core |
42 |
| - Boost::mp11 |
43 |
| - Boost::system |
44 |
| - Boost::utility |
45 |
| -) |
46 |
| - |
| 17 | +target_include_directories(boost_redis INTERFACE include) |
47 | 18 | target_compile_features(boost_redis INTERFACE cxx_std_17)
|
48 | 19 |
|
49 |
| -# Asio bases C++ feature detection on __cplusplus. Make MSVC |
50 |
| -# define it correctly |
51 |
| -if (MSVC) |
52 |
| - target_compile_options(boost_redis INTERFACE /Zc:__cplusplus) |
53 |
| -endif() |
54 |
| - |
55 |
| -find_package(Boost 1.80 REQUIRED) |
56 |
| - |
57 |
| -include_directories(${Boost_INCLUDE_DIRS}) |
58 |
| - |
59 |
| -find_package(OpenSSL REQUIRED) |
60 |
| - |
61 |
| -include_directories(include) |
62 |
| - |
63 |
| -# Common |
64 |
| -#======================================================================= |
65 |
| - |
66 |
| -add_library(boost_redis_project_options INTERFACE) |
67 |
| -target_link_libraries(boost_redis_project_options INTERFACE OpenSSL::Crypto OpenSSL::SSL) |
68 |
| -if (MSVC) |
69 |
| - target_compile_options(boost_redis_project_options INTERFACE /bigobj) |
70 |
| - target_compile_definitions(boost_redis_project_options INTERFACE _WIN32_WINNT=0x0601) |
71 |
| -endif() |
72 |
| - |
73 |
| -add_library(boost_redis_src STATIC examples/boost_redis.cpp) |
74 |
| -target_compile_features(boost_redis_src PRIVATE cxx_std_17) |
75 |
| -target_link_libraries(boost_redis_src PRIVATE boost_redis_project_options) |
76 |
| - |
77 |
| -# Executables |
78 |
| -#======================================================================= |
79 |
| - |
80 |
| -if (BOOST_REDIS_BENCHMARKS) |
81 |
| - add_library(benchmarks_options INTERFACE) |
82 |
| - target_link_libraries(benchmarks_options INTERFACE boost_redis_src) |
83 |
| - target_link_libraries(benchmarks_options INTERFACE boost_redis_project_options) |
84 |
| - target_compile_features(benchmarks_options INTERFACE cxx_std_20) |
85 |
| - |
86 |
| - add_executable(echo_server_client benchmarks/cpp/asio/echo_server_client.cpp) |
87 |
| - target_link_libraries(echo_server_client PRIVATE benchmarks_options) |
88 |
| - |
89 |
| - add_executable(echo_server_direct benchmarks/cpp/asio/echo_server_direct.cpp) |
90 |
| - target_link_libraries(echo_server_direct PRIVATE benchmarks_options) |
91 |
| -endif() |
92 |
| - |
93 |
| -if (BOOST_REDIS_EXAMPLES) |
94 |
| - add_library(examples_main STATIC examples/main.cpp) |
95 |
| - target_compile_features(examples_main PRIVATE cxx_std_20) |
96 |
| - target_link_libraries(examples_main PRIVATE boost_redis_project_options) |
97 |
| - |
98 |
| - macro(make_example EXAMPLE_NAME STANDARD) |
99 |
| - add_executable(${EXAMPLE_NAME} examples/${EXAMPLE_NAME}.cpp) |
100 |
| - target_link_libraries(${EXAMPLE_NAME} PRIVATE boost_redis_src) |
101 |
| - target_link_libraries(${EXAMPLE_NAME} PRIVATE boost_redis_project_options) |
102 |
| - target_compile_features(${EXAMPLE_NAME} PRIVATE cxx_std_${STANDARD}) |
103 |
| - if (${STANDARD} STREQUAL "20") |
104 |
| - target_link_libraries(${EXAMPLE_NAME} PRIVATE examples_main) |
105 |
| - endif() |
106 |
| - endmacro() |
107 |
| - |
108 |
| - macro(make_testable_example EXAMPLE_NAME STANDARD) |
109 |
| - make_example(${EXAMPLE_NAME} ${STANDARD}) |
110 |
| - add_test(${EXAMPLE_NAME} ${EXAMPLE_NAME}) |
111 |
| - endmacro() |
112 |
| - |
113 |
| - make_testable_example(cpp17_intro 17) |
114 |
| - make_testable_example(cpp17_intro_sync 17) |
115 |
| - |
116 |
| - make_testable_example(cpp20_intro 20) |
117 |
| - make_testable_example(cpp20_containers 20) |
118 |
| - make_testable_example(cpp20_json 20) |
119 |
| - make_testable_example(cpp20_intro_tls 20) |
120 |
| - |
121 |
| - make_example(cpp20_subscriber 20) |
122 |
| - make_example(cpp20_streams 20) |
123 |
| - make_example(cpp20_echo_server 20) |
124 |
| - make_example(cpp20_resolve_with_sentinel 20) |
125 |
| - |
126 |
| - # We test the protobuf example only on gcc. |
127 |
| - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
128 |
| - find_package(Protobuf) |
129 |
| - if (Protobuf_FOUND) |
130 |
| - protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS examples/person.proto) |
131 |
| - make_testable_example(cpp20_protobuf 20) |
132 |
| - target_sources(cpp20_protobuf PUBLIC ${PROTO_SRCS} ${PROTO_HDRS}) |
133 |
| - target_link_libraries(cpp20_protobuf PRIVATE ${Protobuf_LIBRARIES}) |
134 |
| - target_include_directories(cpp20_protobuf PUBLIC ${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) |
135 |
| - endif() |
| 20 | +# Dependencies |
| 21 | +if (BOOST_REDIS_MAIN_PROJECT) |
| 22 | + # If we're the root project, error if a dependency is not found |
| 23 | + find_package(Boost 1.83 REQUIRED COMPONENTS headers) |
| 24 | + find_package(Threads REQUIRED) |
| 25 | + find_package(OpenSSL REQUIRED) |
| 26 | + target_link_libraries(boost_redis |
| 27 | + INTERFACE |
| 28 | + Boost::headers |
| 29 | + Threads::Threads |
| 30 | + OpenSSL::Crypto |
| 31 | + OpenSSL::SSL |
| 32 | + ) |
| 33 | +else() |
| 34 | + # If we're in the superproject or called from add_subdirectory, |
| 35 | + # Boost dependencies should be already available. |
| 36 | + # If other dependencies are not found, we bail out |
| 37 | + find_package(Threads) |
| 38 | + if(NOT Threads_FOUND) |
| 39 | + message(STATUS "Boost.Redis has been disabled, because the required package Threads hasn't been found") |
| 40 | + return() |
136 | 41 | endif()
|
137 |
| - |
138 |
| - if (NOT MSVC) |
139 |
| - make_example(cpp20_chat_room 20) |
| 42 | + find_package(OpenSSL) |
| 43 | + if(NOT OpenSSL_FOUND) |
| 44 | + message(STATUS "Boost.Redis has been disabled, because the required package OpenSSL hasn't been found") |
| 45 | + return() |
140 | 46 | endif()
|
141 |
| -endif() |
142 |
| - |
143 |
| -if (BOOST_REDIS_TESTS) |
144 |
| - enable_testing() |
145 |
| - |
146 |
| - add_library(tests_common STATIC test/common.cpp) |
147 |
| - target_compile_features(tests_common PRIVATE cxx_std_17) |
148 |
| - target_link_libraries(tests_common PRIVATE boost_redis_project_options) |
149 |
| - |
150 |
| - macro(make_test TEST_NAME STANDARD) |
151 |
| - add_executable(${TEST_NAME} test/${TEST_NAME}.cpp) |
152 |
| - target_link_libraries(${TEST_NAME} PRIVATE boost_redis_src tests_common) |
153 |
| - target_link_libraries(${TEST_NAME} PRIVATE boost_redis_project_options) |
154 |
| - target_compile_features(${TEST_NAME} PRIVATE cxx_std_${STANDARD}) |
155 |
| - add_test(${TEST_NAME} ${TEST_NAME}) |
156 |
| - endmacro() |
157 |
| - |
158 |
| - make_test(test_conn_quit 17) |
159 |
| - make_test(test_conn_tls 17) |
160 |
| - make_test(test_low_level 17) |
161 |
| - make_test(test_conn_exec_retry 17) |
162 |
| - make_test(test_conn_exec_error 17) |
163 |
| - make_test(test_request 17) |
164 |
| - make_test(test_run 17) |
165 |
| - make_test(test_low_level_sync_sans_io 17) |
166 |
| - make_test(test_conn_check_health 17) |
167 |
| - |
168 |
| - make_test(test_conn_exec 20) |
169 |
| - make_test(test_conn_push 20) |
170 |
| - make_test(test_conn_reconnect 20) |
171 |
| - make_test(test_conn_exec_cancel 20) |
172 |
| - make_test(test_conn_exec_cancel2 20) |
173 |
| - make_test(test_conn_echo_stress 20) |
174 |
| - make_test(test_conn_run_cancel 20) |
175 |
| - make_test(test_issue_50 20) |
176 |
| -endif() |
177 |
| - |
178 |
| -# Install |
179 |
| -#======================================================================= |
180 | 47 |
|
181 |
| -if (BOOST_REDIS_INSTALL) |
182 |
| - install(TARGETS boost_redis |
183 |
| - EXPORT boost_redis |
184 |
| - PUBLIC_HEADER DESTINATION include COMPONENT Development |
| 48 | + # This is generated by boostdep |
| 49 | + target_link_libraries(boost_redis |
| 50 | + INTERFACE |
| 51 | + Boost::asio |
| 52 | + Boost::assert |
| 53 | + Boost::core |
| 54 | + Boost::mp11 |
| 55 | + Boost::system |
| 56 | + Boost::throw_exception |
| 57 | + Threads::Threads |
| 58 | + OpenSSL::Crypto |
| 59 | + OpenSSL::SSL |
185 | 60 | )
|
186 |
| - |
187 |
| - include(CMakePackageConfigHelpers) |
188 |
| - |
189 |
| - configure_package_config_file( |
190 |
| - "${PROJECT_SOURCE_DIR}/cmake/BoostRedisConfig.cmake.in" |
191 |
| - "${PROJECT_BINARY_DIR}/BoostRedisConfig.cmake" |
192 |
| - INSTALL_DESTINATION lib/cmake/boost/redis |
193 |
| - ) |
194 |
| - |
195 |
| - install(EXPORT boost_redis DESTINATION lib/cmake/boost/redis) |
196 |
| - install(FILES "${PROJECT_BINARY_DIR}/BoostRedisConfigVersion.cmake" |
197 |
| - "${PROJECT_BINARY_DIR}/BoostRedisConfig.cmake" |
198 |
| - DESTINATION lib/cmake/boost/redis) |
199 |
| - |
200 |
| - install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include) |
201 |
| - |
202 |
| - include(CMakePackageConfigHelpers) |
203 |
| - write_basic_package_version_file( |
204 |
| - "${PROJECT_BINARY_DIR}/BoostRedisConfigVersion.cmake" |
205 |
| - COMPATIBILITY AnyNewerVersion |
206 |
| - ) |
207 |
| - |
208 |
| - include(CPack) |
209 | 61 | endif()
|
210 | 62 |
|
211 |
| -# Doxygen |
212 |
| -#======================================================================= |
213 |
| - |
214 |
| -if (BOOST_REDIS_DOC) |
215 |
| - set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/doc") |
216 |
| - configure_file(doc/Doxyfile.in doc/Doxyfile @ONLY) |
217 |
| - |
218 |
| - add_custom_target( |
219 |
| - doc |
220 |
| - COMMAND doxygen "${PROJECT_BINARY_DIR}/doc/Doxyfile" |
221 |
| - COMMENT "Building documentation using Doxygen" |
222 |
| - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" |
223 |
| - VERBATIM |
224 |
| - ) |
| 63 | +# Enable testing. If we're being called from the superproject, this has already been done |
| 64 | +if (BOOST_REDIS_MAIN_PROJECT) |
| 65 | + include(CTest) |
225 | 66 | endif()
|
226 | 67 |
|
227 |
| -# Coverage |
228 |
| -#======================================================================= |
| 68 | +# Most tests require a running Redis server, so we only run them if we're the main project |
| 69 | +if(BOOST_REDIS_MAIN_PROJECT AND BUILD_TESTING) |
| 70 | + # Tests and common utilities |
| 71 | + add_subdirectory(test) |
229 | 72 |
|
230 |
| -set( |
231 |
| - COVERAGE_TRACE_COMMAND |
232 |
| - lcov --capture |
233 |
| - -output-file "${PROJECT_BINARY_DIR}/coverage.info" |
234 |
| - --directory "${PROJECT_BINARY_DIR}" |
235 |
| - --include "${PROJECT_SOURCE_DIR}/include/*" |
236 |
| -) |
237 |
| - |
238 |
| -set( |
239 |
| - COVERAGE_HTML_COMMAND |
240 |
| - genhtml --legend -f -q |
241 |
| - "${PROJECT_BINARY_DIR}/coverage.info" |
242 |
| - --prefix "${PROJECT_SOURCE_DIR}" |
243 |
| - --output-directory "${PROJECT_BINARY_DIR}/coverage_html" |
244 |
| -) |
245 |
| - |
246 |
| -add_custom_target( |
247 |
| - coverage |
248 |
| - COMMAND ${COVERAGE_TRACE_COMMAND} |
249 |
| - COMMAND ${COVERAGE_HTML_COMMAND} |
250 |
| - COMMENT "Generating coverage report" |
251 |
| - VERBATIM |
252 |
| -) |
253 |
| - |
254 |
| -# TODO |
255 |
| -#======================================================================= |
256 |
| - |
257 |
| -#.PHONY: bench |
258 |
| -#bench: |
259 |
| -# pdflatex --jobname=echo-f0 benchmarks/benchmarks.tex |
260 |
| -# pdflatex --jobname=echo-f1 benchmarks/benchmarks.tex |
261 |
| -# pdftoppm {input.pdf} {output.file} -png |
| 73 | + # Benchmarks. Build them with tests to prevent code rotting |
| 74 | + add_subdirectory(benchmarks) |
262 | 75 |
|
| 76 | + # Examples |
| 77 | + add_subdirectory(examples) |
| 78 | +endif() |
0 commit comments