forked from confluentinc/librdkafka
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
302 lines (272 loc) · 7.1 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
set(LIBVER 1)
set(
sources
crc32c.c
rdaddr.c
rdavl.c
rdbuf.c
rdcrc32.c
rdkafka.c
rdkafka_assignor.c
rdkafka_broker.c
rdkafka_buf.c
rdkafka_cgrp.c
rdkafka_conf.c
rdkafka_event.c
rdkafka_feature.c
rdkafka_lz4.c
rdkafka_metadata.c
rdkafka_metadata_cache.c
rdkafka_msg.c
rdkafka_msgset_reader.c
rdkafka_msgset_writer.c
rdkafka_offset.c
rdkafka_op.c
rdkafka_partition.c
rdkafka_pattern.c
rdkafka_queue.c
rdkafka_range_assignor.c
rdkafka_request.c
rdkafka_roundrobin_assignor.c
rdkafka_sasl.c
rdkafka_sasl_plain.c
rdkafka_subscription.c
rdkafka_timer.c
rdkafka_topic.c
rdkafka_transport.c
rdkafka_interceptor.c
rdkafka_header.c
rdkafka_admin.c
rdkafka_aux.c
rdkafka_background.c
rdkafka_idempotence.c
rdlist.c
rdlog.c
rdmurmur2.c
rdports.c
rdrand.c
rdregex.c
rdstring.c
rdunittest.c
rdvarint.c
snappy.c
tinycthread.c
tinycthread_extra.c
xxhash.c
)
if(WITH_HDRHISTOGRAM)
list(APPEND sources rdhdrhistogram.c)
endif()
if(WITH_LIBDL OR WIN32)
list(APPEND sources rddl.c)
endif()
if(WITH_PLUGINS)
list(APPEND sources rdkafka_plugin.c)
endif()
if(WIN32)
list(APPEND sources rdkafka_sasl_win32.c)
elseif(WITH_SASL_CYRUS)
list(APPEND sources rdkafka_sasl_cyrus.c)
endif()
if(WITH_SASL_SCRAM)
list(APPEND sources rdkafka_sasl_scram.c)
endif()
if(WITH_SASL_OAUTHBEARER)
list(APPEND sources rdkafka_sasl_oauthbearer.c)
endif()
if(WITH_ZLIB)
list(APPEND sources rdgz.c)
endif()
if(WITH_ZSTD)
list(APPEND sources rdkafka_zstd.c)
endif()
if(NOT WITH_LZ4_EXT)
list(APPEND sources lz4.c lz4frame.c lz4hc.c)
endif()
if(NOT HAVE_REGEX)
list(APPEND sources regexp.c)
endif()
# Define flags with cmake instead of by defining them on win32_config.h
if(WITHOUT_WIN32_CONFIG)
list(APPEND rdkafka_compile_definitions WITHOUT_WIN32_CONFIG)
if(WITH_SSL)
list(APPEND rdkafka_compile_definitions WITH_SSL)
endif(WITH_SSL)
if(WITH_ZLIB)
list(APPEND rdkafka_compile_definitions WITH_ZLIB)
endif(WITH_ZLIB)
if(WITH_SNAPPY)
list(APPEND rdkafka_compile_definitions WITH_SNAPPY)
endif(WITH_SNAPPY)
if(WITH_ZSTD)
list(APPEND rdkafka_compile_definitions WITH_ZSTD)
endif(WITH_ZSTD)
if(WITH_SASL_SCRAM)
list(APPEND rdkafka_compile_definitions WITH_SASL_SCRAM)
endif(WITH_SASL_SCRAM)
if(WITH_SASL_OAUTHBEARER)
list(APPEND rdkafka_compile_definitions WITH_SASL_OAUTHBEARER)
endif(WITH_SASL_OAUTHBEARER)
if(ENABLE_DEVEL)
list(APPEND rdkafka_compile_definitions ENABLE_DEVEL)
endif(ENABLE_DEVEL)
if(WITH_PLUGINS)
list(APPEND rdkafka_compile_definitions WITH_PLUGINS)
endif(WITH_PLUGINS)
endif()
if(RDKAFKA_BUILD_STATIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(RDKAFKA_BUILD_MODE STATIC)
else()
set(RDKAFKA_BUILD_MODE SHARED)
endif()
add_library(rdkafka ${RDKAFKA_BUILD_MODE} ${sources})
if(NOT RDKAFKA_BUILD_STATIC)
set_property(TARGET rdkafka PROPERTY SOVERSION ${LIBVER})
endif()
# Support '#include <rdkafka.h>'
target_include_directories(rdkafka PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>")
target_compile_definitions(rdkafka PUBLIC ${rdkafka_compile_definitions})
if(RDKAFKA_BUILD_STATIC)
target_compile_definitions(rdkafka PUBLIC LIBRDKAFKA_STATICLIB)
endif()
if(WIN32)
if(RDKAFKA_BUILD_STATIC)
target_link_libraries(rdkafka PUBLIC crypt32)
else()
target_compile_definitions(rdkafka PRIVATE LIBRDKAFKA_EXPORTS)
endif()
endif()
# We need 'dummy' directory to support `#include "../config.h"` path
set(dummy "${GENERATED_DIR}/dummy")
file(MAKE_DIRECTORY "${dummy}")
target_include_directories(rdkafka PUBLIC "$<BUILD_INTERFACE:${dummy}>")
if(WITH_HDRHISTOGRAM)
target_link_libraries(rdkafka PUBLIC m)
endif()
if(WITH_ZLIB)
find_package(ZLIB REQUIRED)
target_link_libraries(rdkafka PUBLIC ZLIB::ZLIB)
endif()
if(WITH_ZSTD)
find_library (ZSTD_LIBRARY zstd)
find_path (ZSTD_INCLUDE_DIR NAMES zstd.h)
target_link_libraries(rdkafka PUBLIC ${ZSTD_LIBRARY})
target_include_directories(rdkafka PUBLIC ${ZSTD_INCLUDE_DIR})
message(STATUS "Found ZSTD: ${ZSTD_LIBRARY}")
endif()
if(WITH_SSL)
if(WITH_BUNDLED_SSL) # option from 'h2o' parent project
if(NOT TARGET bundled-ssl)
message(FATAL_ERROR "bundled-ssl target not exist")
endif()
target_include_directories(rdkafka BEFORE PUBLIC ${BUNDLED_SSL_INCLUDE_DIR})
target_link_libraries(rdkafka PUBLIC ${BUNDLED_SSL_LIBRARIES})
add_dependencies(rdkafka bundled-ssl)
else()
find_package(OpenSSL REQUIRED)
target_link_libraries(rdkafka PUBLIC OpenSSL::SSL OpenSSL::Crypto)
endif()
endif()
if(LINK_ATOMIC)
target_link_libraries(rdkafka PUBLIC "-latomic")
endif()
find_package(Threads REQUIRED)
target_link_libraries(rdkafka PUBLIC Threads::Threads)
if(WITH_SASL_CYRUS)
target_link_libraries(rdkafka PUBLIC ${SASL_LIBRARIES})
endif()
if(WITH_LIBDL)
target_link_libraries(rdkafka PUBLIC ${CMAKE_DL_LIBS})
endif()
if(WITH_LZ4_EXT)
target_link_libraries(rdkafka PUBLIC LZ4::LZ4)
endif()
# Set up path to these sources for other sub-projects (tests, examples)
# to be able to reach them.
#set(rdkafka_SRC_DIR ${PROJECT_SOURCE_DIR}
# CACHE INTERNAL "${PROJECT_NAME} source dir" FORCE)
# Generate pkg-config file
set(PKG_CONFIG_NAME
"librdkafka"
)
set(PKG_CONFIG_DESCRIPTION
"The Apache Kafka C/C++ library"
)
set(PKG_CONFIG_VERSION
"${PROJECT_VERSION}"
)
set(PKG_CONFIG_REQUIRES "")
if(WITH_ZLIB)
string(APPEND PKG_CONFIG_REQUIRES "zlib ")
endif()
if(WITH_SSL)
string(APPEND PKG_CONFIG_REQUIRES "libssl ")
endif()
if(WITH_SASL_CYRUS)
string(APPEND PKG_CONFIG_REQUIRES "libsasl2 ")
endif()
if(WITH_ZSTD)
string(APPEND PKG_CONFIG_REQUIRES "libzstd ")
endif()
if(WITH_LZ4_EXT)
string(APPEND PKG_CONFIG_REQUIRES "liblz4 ")
endif()
set(PKG_CONFIG_CFLAGS
"-I\${includedir}"
)
set(PKG_CONFIG_LIBS
"-L\${libdir} -lrdkafka"
)
set(PKG_CONFIG_LIBS_PRIVATE
"-lpthread"
)
find_library(RT_LIBRARY rt)
if(RT_LIBRARY)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt")
endif()
if(WITH_PLUGINS)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl")
endif()
if(WITH_HDRHISTOGRAM)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm")
endif()
configure_file(
"../packaging/cmake/rdkafka.pc.in"
"${GENERATED_DIR}/rdkafka.pc"
@ONLY
)
install(FILES ${GENERATED_DIR}/rdkafka.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
if(RDKAFKA_BUILD_STATIC)
set(PKG_CONFIG_NAME
"librdkafka-static"
)
set(PKG_CONFIG_DESCRIPTION
"The Apache Kafka C/C++ library (static)"
)
set(PKG_CONFIG_LIBS
"-L\${libdir} \${libdir}/librdkafka.a"
)
configure_file(
"../packaging/cmake/rdkafka.pc.in"
"${GENERATED_DIR}/rdkafka-static.pc"
@ONLY
)
install(FILES ${GENERATED_DIR}/rdkafka.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
endif()
install(
TARGETS rdkafka
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
FILES "rdkafka.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka"
)