@@ -2,6 +2,15 @@ cmake_minimum_required(VERSION 3.14)
2
2
3
3
#set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
4
4
5
+ # determine whether it's main/root project
6
+ # or being built under another project.
7
+ 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 ()
12
+ endif ()
13
+
5
14
project (
6
15
boost_redis
7
16
VERSION 1.4.1
@@ -10,6 +19,12 @@ project(
10
19
LANGUAGES CXX
11
20
)
12
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} )
27
+
13
28
add_library (boost_redis INTERFACE )
14
29
add_library (Boost::redis ALIAS boost_redis )
15
30
target_include_directories (boost_redis INTERFACE
@@ -34,185 +49,181 @@ target_compile_features(boost_redis INTERFACE cxx_std_17)
34
49
# Asio bases C++ feature detection on __cplusplus. Make MSVC
35
50
# define it correctly
36
51
if (MSVC )
37
- target_compile_options (boost_redis INTERFACE /Zc:__cplusplus )
52
+ target_compile_options (boost_redis INTERFACE /Zc:__cplusplus )
38
53
endif ()
39
54
40
- include (CMakePackageConfigHelpers )
41
- write_basic_package_version_file (
42
- "${PROJECT_BINARY_DIR} /BoostRedisConfigVersion.cmake"
43
- COMPATIBILITY AnyNewerVersion
44
- )
45
-
46
55
find_package (Boost 1.80 REQUIRED )
47
56
48
- # We test the protobuf example only on gcc.
49
- if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
50
- find_package (Protobuf ) # For the protobuf example.
51
- endif ()
52
-
53
57
include_directories (${Boost_INCLUDE_DIRS} )
54
58
55
59
find_package (OpenSSL REQUIRED )
56
60
57
- enable_testing ()
58
61
include_directories (include )
59
62
63
+ # Common
60
64
#=======================================================================
61
65
62
- set (libs_common boost_redis_src )
63
- set (libs_cpp17 tests_common )
64
- set (libs_cpp20 examples_main )
65
-
66
- foreach (lib IN LISTS libs_cpp20 libs_cpp17 libs_common )
67
- add_library (${lib} STATIC )
68
- endforeach ()
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 ()
69
72
70
- target_sources (boost_redis_src PRIVATE examples/boost_redis.cpp )
71
- target_sources ( tests_common PRIVATE tests/common.cpp )
72
- target_sources ( examples_main PRIVATE examples/main.cpp )
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 )
73
76
74
77
# Executables
75
78
#=======================================================================
76
79
77
- set (benchmakrs echo_server_client echo_server_direct )
78
- add_executable (echo_server_client benchmarks/cpp/asio/echo_server_client.cpp )
79
- add_executable (echo_server_direct benchmarks/cpp/asio/echo_server_direct.cpp )
80
-
81
- set (tests_cpp17
82
- test_conn_quit
83
- test_conn_tls
84
- test_low_level
85
- test_conn_exec_retry
86
- test_conn_exec_error
87
- test_request
88
- test_run
89
- test_low_level_sync
90
- test_conn_check_health
91
- )
92
-
93
- set (tests_cpp20
94
- test_conn_exec
95
- test_conn_push
96
- test_conn_reconnect
97
- test_conn_exec_cancel
98
- test_conn_exec_cancel2
99
- test_conn_echo_stress
100
- test_low_level_async
101
- test_conn_run_cancel
102
- test_issue_50
103
- )
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 )
104
85
105
- set (examples_cpp17
106
- cpp17_intro
107
- cpp17_intro_sync )
108
-
109
- set (examples_cpp20
110
- cpp20_intro
111
- cpp20_streams
112
- cpp20_containers
113
- cpp20_echo_server
114
- cpp20_json
115
- cpp20_subscriber
116
- cpp20_intro_tls
117
- cpp20_resolve_with_sentinel
118
- )
86
+ add_executable (echo_server_client benchmarks/cpp/asio/echo_server_client.cpp )
87
+ target_link_libraries (echo_server_client PRIVATE benchmarks_options )
119
88
120
- if ( Protobuf_FOUND )
121
- list ( APPEND examples_cpp20 cpp20_protobuf )
89
+ add_executable ( echo_server_direct benchmarks/cpp/asio/echo_server_direct.cpp )
90
+ target_link_libraries ( echo_server_direct PRIVATE benchmarks_options )
122
91
endif ()
123
92
124
- if (NOT MSVC )
125
- list (APPEND examples_cpp20 cpp20_chat_room )
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 ()
136
+ endif ()
137
+
138
+ if (NOT MSVC )
139
+ make_example (cpp20_chat_room 20 )
140
+ endif ()
126
141
endif ()
127
142
128
- foreach (exe IN LISTS examples_cpp17 examples_cpp20 )
129
- add_executable (${exe} examples/${exe}.cpp )
130
- endforeach ()
131
-
132
- foreach (exe IN LISTS examples_cpp20 )
133
- target_link_libraries (${exe} PRIVATE examples_main )
134
- endforeach ()
135
-
136
- foreach (exe IN LISTS tests_cpp17 tests_cpp20 )
137
- add_executable (${exe} tests/${exe}.cpp )
138
- target_link_libraries (${exe} PRIVATE tests_common )
139
- endforeach ()
140
-
141
- foreach (exe IN LISTS tests_cpp17 tests_cpp20 examples_cpp17 examples_cpp20 libs_cpp17 libs_cpp20 libs_common benchmakrs )
142
- target_link_libraries (${exe} PRIVATE OpenSSL::Crypto OpenSSL::SSL )
143
- if (MSVC )
144
- target_compile_options (${exe} PRIVATE /bigobj )
145
- target_compile_definitions (${exe} PRIVATE _WIN32_WINNT=0x0601 )
146
- endif ()
147
- endforeach ()
148
-
149
- foreach (exe IN LISTS tests_cpp17 tests_cpp20 examples_cpp17 examples_cpp20 libs_cpp17 libs_cpp20 benchmakrs )
150
- target_link_libraries (${exe} PRIVATE boost_redis_src )
151
- endforeach ()
152
-
153
- foreach (exe IN LISTS tests_cpp20 examples_cpp20 libs_cpp20 benchmarks )
154
- target_compile_features (${exe} PUBLIC cxx_std_20 )
155
- endforeach ()
156
-
157
- foreach (exe IN LISTS tests_cpp17 examples_cpp17 libs_cpp17 libs_common )
158
- target_compile_features (${exe} PUBLIC cxx_std_17 )
159
- endforeach ()
160
-
161
- if (Protobuf_FOUND )
162
- protobuf_generate_cpp (PROTO_SRCS PROTO_HDRS examples/person.proto )
163
- target_sources (cpp20_protobuf PUBLIC ${PROTO_SRCS} ${PROTO_HDRS} )
164
- target_link_libraries (cpp20_protobuf PRIVATE ${Protobuf_LIBRARIES} )
165
- target_include_directories (cpp20_protobuf PUBLIC ${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} )
166
- add_test (cpp20_protobuf cpp20_protobuf )
143
+ if (BOOST_REDIS_TESTS )
144
+ enable_testing ()
145
+
146
+ add_library (tests_common STATIC tests/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} tests/${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 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_low_level_async 20 )
175
+ make_test (test_conn_run_cancel 20 )
176
+ make_test (test_issue_50 20 )
167
177
endif ()
168
178
169
- add_test (cpp17_intro cpp17_intro )
170
- add_test (cpp17_intro_sync cpp17_intro_sync )
171
- add_test (cpp20_intro cpp20_intro )
172
- add_test (cpp20_containers cpp20_containers )
173
- add_test (cpp20_json cpp20_json )
174
- add_test (cpp20_intro_tls cpp20_intro_tls )
175
-
176
- foreach (exe IN LISTS tests_cpp17 tests_cpp20 )
177
- add_test (${exe} ${exe} )
178
- endforeach ()
179
-
180
179
# Install
181
180
#=======================================================================
182
181
183
- install (TARGETS boost_redis
184
- EXPORT boost_redis
185
- PUBLIC_HEADER DESTINATION include COMPONENT Development
186
- )
187
-
188
- include (CMakePackageConfigHelpers )
189
-
190
- configure_package_config_file (
191
- "${PROJECT_SOURCE_DIR} /cmake/BoostRedisConfig.cmake.in"
192
- "${PROJECT_BINARY_DIR} /BoostRedisConfig.cmake"
193
- INSTALL_DESTINATION lib/cmake/boost/redis
194
- )
195
-
196
- install (EXPORT boost_redis DESTINATION lib/cmake/boost/redis )
197
- install (FILES "${PROJECT_BINARY_DIR} /BoostRedisConfigVersion.cmake"
198
- "${PROJECT_BINARY_DIR} /BoostRedisConfig.cmake"
199
- DESTINATION lib/cmake/boost/redis )
182
+ if (BOOST_REDIS_INSTALL )
183
+ install (TARGETS boost_redis
184
+ EXPORT boost_redis
185
+ PUBLIC_HEADER DESTINATION include COMPONENT Development
186
+ )
187
+
188
+ include (CMakePackageConfigHelpers )
189
+
190
+ configure_package_config_file (
191
+ "${PROJECT_SOURCE_DIR} /cmake/BoostRedisConfig.cmake.in"
192
+ "${PROJECT_BINARY_DIR} /BoostRedisConfig.cmake"
193
+ INSTALL_DESTINATION lib/cmake/boost/redis
194
+ )
195
+
196
+ install (EXPORT boost_redis DESTINATION lib/cmake/boost/redis )
197
+ install (FILES "${PROJECT_BINARY_DIR} /BoostRedisConfigVersion.cmake"
198
+ "${PROJECT_BINARY_DIR} /BoostRedisConfig.cmake"
199
+ DESTINATION lib/cmake/boost/redis )
200
+
201
+ install (DIRECTORY ${PROJECT_SOURCE_DIR} /include/ DESTINATION include )
202
+
203
+ include (CMakePackageConfigHelpers )
204
+ write_basic_package_version_file (
205
+ "${PROJECT_BINARY_DIR} /BoostRedisConfigVersion.cmake"
206
+ COMPATIBILITY AnyNewerVersion
207
+ )
200
208
201
- install (DIRECTORY ${PROJECT_SOURCE_DIR} /include/ DESTINATION include )
209
+ include (CPack )
210
+ endif ()
202
211
203
212
# Doxygen
204
213
#=======================================================================
205
214
206
- set (DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR} /doc" )
207
- configure_file (doc /Doxyfile.in doc /Doxyfile @ONLY )
208
-
209
- add_custom_target (
210
- doc
211
- COMMAND doxygen "${PROJECT_BINARY_DIR} /doc/Doxyfile"
212
- COMMENT "Building documentation using Doxygen"
213
- WORKING_DIRECTORY "${PROJECT_SOURCE_DIR} "
214
- VERBATIM
215
- )
215
+ if (BOOST_REDIS_DOC )
216
+ set (DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR} /doc" )
217
+ configure_file (doc /Doxyfile.in doc /Doxyfile @ONLY )
218
+
219
+ add_custom_target (
220
+ doc
221
+ COMMAND doxygen "${PROJECT_BINARY_DIR} /doc/Doxyfile"
222
+ COMMENT "Building documentation using Doxygen"
223
+ WORKING_DIRECTORY "${PROJECT_SOURCE_DIR} "
224
+ VERBATIM
225
+ )
226
+ endif ()
216
227
217
228
# Coverage
218
229
#=======================================================================
@@ -241,11 +252,6 @@ add_custom_target(
241
252
VERBATIM
242
253
)
243
254
244
- # Distribution
245
- #=======================================================================
246
-
247
- include (CPack )
248
-
249
255
# TODO
250
256
#=======================================================================
251
257
0 commit comments