forked from confluentinc/librdkafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
223 lines (190 loc) · 4.99 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
cmake_minimum_required(VERSION 3.2)
include("packaging/cmake/parseversion.cmake")
parseversion("src/rdkafka.h")
project(RdKafka VERSION ${RDKAFKA_VERSION})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/packaging/cmake/Modules/")
# Options. No 'RDKAFKA_' prefix to match old C++ code. {
# This option doesn't affect build in fact, only C code
# (see 'rd_kafka_version_str'). In CMake the build type feature usually used
# (like Debug, Release, etc.).
option(WITHOUT_OPTIMIZATION "Disable optimization" OFF)
option(ENABLE_DEVEL "Enable development asserts, checks, etc" OFF)
option(ENABLE_REFCNT_DEBUG "Enable refcnt debugging" OFF)
option(ENABLE_SHAREDPTR_DEBUG "Enable sharedptr debugging" OFF)
set(TRYCOMPILE_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/packaging/cmake/try_compile")
# ZLIB {
find_package(ZLIB QUIET)
if(ZLIB_FOUND)
set(with_zlib_default ON)
else()
set(with_zlib_default OFF)
endif()
option(WITH_ZLIB "With ZLIB" ${with_zlib_default})
# }
# ZSTD {
if (WITH_BUNDLED_ZSTD)
set(with_zstd_default ON)
else ()
find_library (ZSTD zstd)
if(ZSTD)
set(with_zstd_default ON)
else()
set(with_zstd_default OFF)
endif()
endif()
option(WITH_ZSTD "With ZSTD" ${with_zstd_default})
# }
# LibDL {
try_compile(
WITH_LIBDL
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${TRYCOMPILE_SRC_DIR}/dlopen_test.c"
LINK_LIBRARIES "${CMAKE_DL_LIBS}"
)
# }
# WITH_PLUGINS {
if(WITH_LIBDL)
set(with_plugins_default ON)
else()
set(with_plugins_default OFF)
endif()
option(WITH_PLUGINS "With plugin support" ${with_plugins_default})
# }
# OpenSSL {
if(WITH_BUNDLED_SSL) # option from 'h2o' parent project
set(with_ssl_default ON)
else()
find_package(OpenSSL QUIET)
if(OpenSSL_FOUND)
set(with_ssl_default ON)
else()
set(with_ssl_default OFF)
endif()
endif()
option(WITH_SSL "With SSL" ${with_ssl_default})
# }
# SASL {
if(WIN32)
set(with_sasl_default ON)
else()
include(FindPkgConfig)
pkg_check_modules(SASL libsasl2)
if(SASL_FOUND)
set(with_sasl_default ON)
else()
try_compile(
WITH_SASL_CYRUS_BOOL
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${TRYCOMPILE_SRC_DIR}/libsasl2_test.c"
LINK_LIBRARIES "-lsasl2"
)
if(WITH_SASL_CYRUS_BOOL)
set(with_sasl_default ON)
set(SASL_LIBRARIES "-lsasl2")
else()
set(with_sasl_default OFF)
endif()
endif()
endif()
option(WITH_SASL "With SASL" ${with_sasl_default})
if(WITH_SASL)
if(WITH_SSL)
set(WITH_SASL_SCRAM ON)
endif()
if(NOT WIN32)
set(WITH_SASL_CYRUS ON)
endif()
endif()
# }
# LZ4 {
option(ENABLE_LZ4_EXT "Enable external LZ4 library support" ON)
set(WITH_LZ4_EXT OFF)
if(ENABLE_LZ4_EXT)
find_package(LZ4)
if(LZ4_FOUND)
set(WITH_LZ4_EXT ON)
else()
message(STATUS "Using bundled LZ4 implementation.")
endif()
endif()
# }
# }
option(RDKAFKA_BUILD_STATIC "Build static rdkafka library" OFF)
option(RDKAFKA_BUILD_EXAMPLES "Build examples" ON)
option(RDKAFKA_BUILD_TESTS "Build tests" ON)
if(WIN32)
option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON)
endif(WIN32)
# In:
# * TRYCOMPILE_SRC_DIR
# Out:
# * HAVE_ATOMICS_32
# * HAVE_ATOMICS_32_SYNC
# * HAVE_ATOMICS_64
# * HAVE_ATOMICS_64_SYNC
# * HAVE_REGEX
# * HAVE_STRNDUP
# * WITH_C11THREADS
# * LINK_ATOMIC
include("packaging/cmake/try_compile/rdkafka_setup.cmake")
set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
# In:
# * WITHOUT_OPTIMIZATION
# * ENABLE_DEVEL
# * ENABLE_REFCNT_DEBUG
# * ENABLE_SHAREDPTR_DEBUG
# * HAVE_ATOMICS_32
# * HAVE_ATOMICS_32_SYNC
# * HAVE_ATOMICS_64
# * HAVE_ATOMICS_64_SYNC
# * WITH_ZLIB
# * WITH_SSL
# * WITH_SASL
# * HAVE_REGEX
# * HAVE_STRNDUP
configure_file("packaging/cmake/config.h.in" "${GENERATED_DIR}/config.h")
# Installation (https://github.com/forexample/package-example) {
include(GNUInstallDirs)
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(project_version "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
# In:
# * targets_export_name
# * PROJECT_NAME
configure_package_config_file(
"packaging/cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
write_basic_package_version_file(
"${project_version}"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES "${project_config}" "${project_version}" "packaging/cmake/Modules/FindLZ4.cmake"
DESTINATION "${config_install_dir}"
)
install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
install(
FILES LICENSES.txt
DESTINATION "share/licenses/librdkafka"
)
# }
add_subdirectory(src)
add_subdirectory(src-cpp)
if(RDKAFKA_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(RDKAFKA_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()