diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ef0f337..28b9d155 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index a2947a2b..2b0ecdac 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmake/FindRdKafka.cmake b/cmake/FindRdKafka.cmake index 220cc752..2687a461 100644 --- a/cmake/FindRdKafka.cmake +++ b/cmake/FindRdKafka.cmake @@ -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 \n #if RD_KAFKA_VERSION >= 0x00090400\n int main() { }\n #endif") +set(CONTENTS "#include \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})