Specific linking option for rdkafka library (#94)

This commit is contained in:
Alex Damian
2018-06-25 10:03:11 -04:00
committed by Matias Fontanini
parent c5aca985b8
commit 069ea3df8e
3 changed files with 33 additions and 5 deletions

View File

@@ -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.
@@ -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)

View File

@@ -77,13 +77,16 @@ 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}/
@@ -91,6 +94,8 @@ ${RDKAFKA_ROOT_DIR}/
+ include/librdkafka/rdkafka.h
|
+ lib/librdkafka.a
|
+ lib64/librdkafka.a (optional)
```
# Using

View File

@@ -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
)
@@ -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)
@@ -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})