Skip to content

Specific linking option for rdkafka library #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project(cppkafka)
set(CPPKAFKA_VERSION_MAJOR 0)
set(CPPKAFKA_VERSION_MINOR 1)
set(CPPKAFKA_VERSION "${CPPKAFKA_VERSION_MAJOR}.${CPPKAFKA_VERSION_MINOR}")
set(RDKAFKA_MIN_VERSION 0x00090400)

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

# Disable output from find_package macro
if (NOT CPPKAFKA_CMAKE_VERBOSE)
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,25 @@ The following cmake options can be specified:
* `CPPKAFKA_DISABLE_EXAMPLES` : Disable build of cppkafka examples. Default is `OFF`.
* `CPPKAFKA_BOOST_STATIC_LIBS` : Link with Boost static libraries. Default is `ON`.
* `CPPKAFKA_BOOST_USE_MULTITHREADED` : Use Boost multi-threaded libraries. Default is `ON`.
* `CPPKAFKA_RDKAFKA_STATIC_LIB` : Link to Rdkafka static library. Default is `OFF`.

Example:
```Shell
cmake -DRDKAFKA_ROOT_DIR=/some/other/dir -DCPPKAFKA_BUILD_SHARED=OFF ...
```

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

```Shell
${RDKAFKA_ROOT_DIR}/
|
+ include/librdkafka/rdkafka.h
|
+ lib/librdkafka.a
|
+ lib64/librdkafka.a (optional)
```

# Using
Expand Down
29 changes: 25 additions & 4 deletions cmake/FindRdKafka.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Override default CMAKE_FIND_LIBRARY_SUFFIXES
if (CPPKAFKA_RDKAFKA_STATIC_LIB)
if (MSVC)
set(RDKAFKA_SUFFIX lib)
else()
set(RDKAFKA_SUFFIX a)
endif()
else()
if (MSVC)
set(RDKAFKA_SUFFIX dll)
else()
set(RDKAFKA_SUFFIX so)
endif()
endif()

find_path(RDKAFKA_ROOT_DIR
NAMES include/librdkafka/rdkafka.h
)
Expand All @@ -7,11 +22,17 @@ find_path(RDKAFKA_INCLUDE_DIR
HINTS ${RDKAFKA_ROOT_DIR}/include
)

set(HINT_DIR ${RDKAFKA_ROOT_DIR}/lib)
# Check lib paths
if (CPPKAFKA_CMAKE_VERBOSE)
get_property(FIND_LIBRARY_32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
get_property(FIND_LIBRARY_64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
MESSAGE(STATUS "RDKAFKA search 32-bit library paths: ${FIND_LIBRARY_32}")
MESSAGE(STATUS "RDKAFKA search 64-bit library paths: ${FIND_LIBRARY_64}")
endif()

find_library(RDKAFKA_LIBRARY
NAMES rdkafka librdkafka
HINTS ${HINT_DIR}
NAMES rdkafka.${RDKAFKA_SUFFIX} librdkafka.${RDKAFKA_SUFFIX} rdkafka
HINTS ${RDKAFKA_ROOT_DIR}/lib
)

include(FindPackageHandleStandardArgs)
Expand All @@ -20,7 +41,7 @@ find_package_handle_standard_args(RDKAFKA DEFAULT_MSG
RDKAFKA_INCLUDE_DIR
)

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

Expand Down