Skip to content

Commit

Permalink
Merge pull request #5 from tarantool/build-rdkafka-inplace
Browse files Browse the repository at this point in the history
Builtin rdkafka library with cmake option STATIC_BUILD
  • Loading branch information
RepentantGopher authored May 24, 2019
2 parents 36f10a8 + 1984c62 commit f407532
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "librdkafka"]
path = librdkafka
url = https://github.com/edenhill/librdkafka.git
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions cmake/FindRdKafka.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cmake/buildRdKafka.cmake
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 9 additions & 1 deletion kafka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions librdkafka
Submodule librdkafka added at 8695b9
6 changes: 2 additions & 4 deletions rockspecs/kafka-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ dependencies = {
external_dependencies = {
TARANTOOL = {
header = 'tarantool/module.h'
},
RDKAFKA = {
header = 'librdkafka/rdkafka.h'
}
}
build = {
Expand All @@ -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)"
}
}

0 comments on commit f407532

Please sign in to comment.