Skip to content

Commit 19d750a

Browse files
author
accelerated
committed
Specific linking option for rdkafka library
1 parent c5aca98 commit 19d750a

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

Diff for: CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ project(cppkafka)
55
set(CPPKAFKA_VERSION_MAJOR 0)
66
set(CPPKAFKA_VERSION_MINOR 1)
77
set(CPPKAFKA_VERSION "${CPPKAFKA_VERSION_MAJOR}.${CPPKAFKA_VERSION_MINOR}")
8+
set(RDKAFKA_MIN_VERSION 0x00090400)
89

910
if(MSVC)
1011
# Don't always use Wall, since VC's /Wall is ridiculously verbose.
@@ -30,6 +31,7 @@ option(CPPKAFKA_DISABLE_TESTS "Disable build of cppkafka tests." OFF)
3031
option(CPPKAFKA_DISABLE_EXAMPLES "Disable build of cppkafka examples." OFF)
3132
option(CPPKAFKA_BOOST_STATIC_LIBS "Link with Boost static libraries." ON)
3233
option(CPPKAFKA_BOOST_USE_MULTITHREADED "Use Boost multithreaded libraries." ON)
34+
option(CPPKAFKA_RDKAFKA_STATIC_LIB "Link with Rdkafka static library." OFF)
3335

3436
# Disable output from find_package macro
3537
if (NOT CPPKAFKA_CMAKE_VERBOSE)

Diff for: README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,25 @@ The following cmake options can be specified:
7777
* `CPPKAFKA_DISABLE_EXAMPLES` : Disable build of cppkafka examples. Default is `OFF`.
7878
* `CPPKAFKA_BOOST_STATIC_LIBS` : Link with Boost static libraries. Default is `ON`.
7979
* `CPPKAFKA_BOOST_USE_MULTITHREADED` : Use Boost multi-threaded libraries. Default is `ON`.
80+
* `CPPKAFKA_RDKAFKA_STATIC_LIB` : Link to Rdkafka static library. Default is `OFF`.
8081

8182
Example:
8283
```Shell
8384
cmake -DRDKAFKA_ROOT_DIR=/some/other/dir -DCPPKAFKA_BUILD_SHARED=OFF ...
8485
```
8586

86-
Note that the `RDKAFKA_ROOT_DIR` must contain the following structure:
87+
The `RDKAFKA_ROOT_DIR` must contain the following structure. If the system
88+
architecture is 64-bit and both `lib` and `lib64` folders are available, the `lib64`
89+
folder location will be selected by cmake.
8790

8891
```Shell
8992
${RDKAFKA_ROOT_DIR}/
9093
|
9194
+ include/librdkafka/rdkafka.h
9295
|
9396
+ lib/librdkafka.a
97+
|
98+
+ lib64/librdkafka.a (optional)
9499
```
95100

96101
# Using

Diff for: cmake/FindRdKafka.cmake

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Override default CMAKE_FIND_LIBRARY_SUFFIXES
2+
if (CPPKAFKA_RDKAFKA_STATIC_LIB)
3+
if (MSVC)
4+
set(RDKAFKA_SUFFIX lib)
5+
else()
6+
set(RDKAFKA_SUFFIX a)
7+
endif()
8+
else()
9+
if (MSVC)
10+
set(RDKAFKA_SUFFIX dll)
11+
else()
12+
set(RDKAFKA_SUFFIX so)
13+
endif()
14+
endif()
15+
116
find_path(RDKAFKA_ROOT_DIR
217
NAMES include/librdkafka/rdkafka.h
318
)
@@ -7,11 +22,17 @@ find_path(RDKAFKA_INCLUDE_DIR
722
HINTS ${RDKAFKA_ROOT_DIR}/include
823
)
924

10-
set(HINT_DIR ${RDKAFKA_ROOT_DIR}/lib)
25+
# Check lib paths
26+
if (CPPKAFKA_CMAKE_VERBOSE)
27+
get_property(FIND_LIBRARY_32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
28+
get_property(FIND_LIBRARY_64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
29+
MESSAGE(STATUS "RDKAFKA search 32-bit library paths: ${FIND_LIBRARY_32}")
30+
MESSAGE(STATUS "RDKAFKA search 64-bit library paths: ${FIND_LIBRARY_64}")
31+
endif()
1132

1233
find_library(RDKAFKA_LIBRARY
13-
NAMES rdkafka librdkafka
14-
HINTS ${HINT_DIR}
34+
NAMES rdkafka.${RDKAFKA_SUFFIX} librdkafka.${RDKAFKA_SUFFIX} rdkafka
35+
HINTS ${RDKAFKA_ROOT_DIR}/lib
1536
)
1637

1738
include(FindPackageHandleStandardArgs)
@@ -20,7 +41,7 @@ find_package_handle_standard_args(RDKAFKA DEFAULT_MSG
2041
RDKAFKA_INCLUDE_DIR
2142
)
2243

23-
set(CONTENTS "#include <librdkafka/rdkafka.h>\n #if RD_KAFKA_VERSION >= 0x00090400\n int main() { }\n #endif")
44+
set(CONTENTS "#include <librdkafka/rdkafka.h>\n #if RD_KAFKA_VERSION >= ${RDKAFKA_MIN_VERSION}\n int main() { }\n #endif")
2445
set(FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/rdkafka_version_test.c)
2546
file(WRITE ${FILE_NAME} ${CONTENTS})
2647

0 commit comments

Comments
 (0)