diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0f9c2de --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "librdkafka"] + path = librdkafka + url = https://github.com/edenhill/librdkafka.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 6390d8a..0570cac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,13 @@ if(${tntver} VERSION_LESS 1.7.4.291) message(FATAL_ERROR "Tarantool >= 1.7.4-291 is required") endif() -set(RDKAFKA_FIND_REQUIRED ON) -find_package(RdKafka) +if(STATIC_BUILD) + include(buildRdKafka) + buildrdkafka() +else() + set(RDKAFKA_FIND_REQUIRED ON) + find_package(RdKafka) +endif() include_directories(${TARANTOOL_INCLUDE_DIRS}) diff --git a/README.md b/README.md index 7a76589..68c69d5 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,15 @@ non critical errors as strings which allows you to decide how to handle it. # Installation ```bash - tarantoolctl rocks install https://raw.githubusercontent.com/tarantool/tnt-kafka/master/rockspecs/kafka-scm-1.rockspec + tarantoolctl rocks install https://raw.githubusercontent.com/tarantool/kafka/master/rockspecs/kafka-scm-1.rockspec +``` + +## Build module with statically linked librdkafka + +To install kafka module with builtin librdkafka dependency, use option `STATIC_BUILD`: + +```bash +tarantoolctl rocks STATIC_BUILD=ON install https://raw.githubusercontent.com/tarantool/kafka/master/rockspecs/kafka-scm-1.rockspec ``` # Examples diff --git a/cmake/FindRdKafka.cmake b/cmake/FindRdKafka.cmake index 5ef53e5..653f1a5 100644 --- a/cmake/FindRdKafka.cmake +++ b/cmake/FindRdKafka.cmake @@ -6,11 +6,17 @@ find_path(RDKAFKA_INCLUDE_DIR NAMES librdkafka/rdkafka.h HINTS ${RDKAFKA_ROOT_DIR}/include ) + find_library(RDKAFKA_LIBRARY NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}rdkafka${CMAKE_SHARED_LIBRARY_SUFFIX} rdkafka HINTS ${RDKAFKA_ROOT_DIR}/lib ) +find_library(RDKAFKA_STATIC + NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}rdkafka${CMAKE_STATIC_LIBRARY_SUFFIX} rdkafka + HINTS ${RDKAFKA_ROOT_DIR}/lib + ) + include(FindPackageHandleStandardArgs) find_package_handle_standard_args(RDKAFKA DEFAULT_MSG RDKAFKA_LIBRARY diff --git a/cmake/buildRdKafka.cmake b/cmake/buildRdKafka.cmake new file mode 100644 index 0000000..7afbabc --- /dev/null +++ b/cmake/buildRdKafka.cmake @@ -0,0 +1,10 @@ +macro(buildrdkafka) + add_custom_target( + rdkafka + COMMAND ./configure + COMMAND make + COMMAND make install + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/librdkafka + VERBATIM + ) +endmacro() diff --git a/kafka/CMakeLists.txt b/kafka/CMakeLists.txt index effa4df..c4417f6 100644 --- a/kafka/CMakeLists.txt +++ b/kafka/CMakeLists.txt @@ -7,8 +7,16 @@ if (APPLE) -undefined suppress -flat_namespace") endif(APPLE) -target_link_libraries(tntkafka ${RDKAFKA_LIBRARY} pthread) +target_link_libraries(tntkafka pthread) + +if (STATIC_BUILD) + add_dependencies(tntkafka rdkafka) + target_link_libraries(tntkafka ${CMAKE_SOURCE_DIR}/librdkafka/src/librdkafka.a) +else() + target_link_libraries(tntkafka ${RDKAFKA_LIBRARY}) +endif() set_target_properties(tntkafka PROPERTIES PREFIX "" OUTPUT_NAME "tntkafka") + install(TARGETS tntkafka LIBRARY DESTINATION ${TARANTOOL_INSTALL_LIBDIR}/kafka) install(FILES init.lua DESTINATION ${TARANTOOL_INSTALL_LUADIR}/kafka) diff --git a/librdkafka b/librdkafka new file mode 160000 index 0000000..8695b9d --- /dev/null +++ b/librdkafka @@ -0,0 +1 @@ +Subproject commit 8695b9d63ac0fe1b891b511d5b36302ffc84d4e2 diff --git a/rockspecs/kafka-scm-1.rockspec b/rockspecs/kafka-scm-1.rockspec index 51a2e4d..94c3b84 100644 --- a/rockspecs/kafka-scm-1.rockspec +++ b/rockspecs/kafka-scm-1.rockspec @@ -15,9 +15,6 @@ dependencies = { external_dependencies = { TARANTOOL = { header = 'tarantool/module.h' - }, - RDKAFKA = { - header = 'librdkafka/rdkafka.h' } } build = { @@ -26,6 +23,7 @@ build = { CMAKE_BUILD_TYPE="RelWithDebInfo", TARANTOOL_DIR="$(TARANTOOL_DIR)", TARANTOOL_INSTALL_LIBDIR="$(LIBDIR)", - TARANTOOL_INSTALL_LUADIR="$(LUADIR)" + TARANTOOL_INSTALL_LUADIR="$(LUADIR)", + STATIC_BUILD="$(STATIC_BUILD)" } } \ No newline at end of file