From 81fb4ba47136c1d03075b1ef1af6ebe47a29fd25 Mon Sep 17 00:00:00 2001 From: Yaroslav Dynnikov Date: Thu, 6 Jun 2019 20:26:25 +0300 Subject: [PATCH] Handle cmake properly --- .gitignore | 4 +++- CMakeLists.txt | 18 ++++++++++++++++-- cmake/buildRdKafka.cmake | 10 ---------- kafka/CMakeLists.txt | 11 +++-------- 4 files changed, 22 insertions(+), 21 deletions(-) delete mode 100644 cmake/buildRdKafka.cmake diff --git a/.gitignore b/.gitignore index 252708f..752a634 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .idea +.rocks tests/venv tests/.pytest_cache tests/__* -cmake-build-debug \ No newline at end of file +cmake-build-debug +build.luarocks/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f3b9bc..11469c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR) project(kafka C) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE) # Set CFLAGS set(MY_C_FLAGS "-Wall -Wextra -Werror -std=gnu11 -fno-strict-aliasing -Wno-deprecated-declarations") @@ -18,8 +19,21 @@ if(${tntver} VERSION_LESS 1.7.4.291) endif() if("${STATIC_BUILD}" STREQUAL "ON" OR "$ENV{STATIC_BUILD}" STREQUAL "ON") - include(buildRdKafka) - buildrdkafka() + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/librdkafka/lib/librdkafka.a + COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/librdkafka + COMMAND make -j + COMMAND make install + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/librdkafka + COMMENT "Building librdkafka" + VERBATIM + ) + add_custom_target(librdkafka.a ALL + DEPENDS ${CMAKE_BINARY_DIR}/librdkafka/lib/librdkafka.a + ) + + set(RDKAFKA_LIBRARY ${CMAKE_BINARY_DIR}/librdkafka/lib/librdkafka.a) + set(RDKAFKA_INCLUDE_DIR ${CMAKE_BINARY_DIR}/librdkafka/include) else() set(RDKAFKA_FIND_REQUIRED ON) find_package(RdKafka) diff --git a/cmake/buildRdKafka.cmake b/cmake/buildRdKafka.cmake deleted file mode 100644 index 7afbabc..0000000 --- a/cmake/buildRdKafka.cmake +++ /dev/null @@ -1,10 +0,0 @@ -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 9531471..349df4c 100644 --- a/kafka/CMakeLists.txt +++ b/kafka/CMakeLists.txt @@ -1,4 +1,5 @@ -include_directories(${CMAKE_SOURCE_DIR}/kafka) +include_directories(${RDKAFKA_INCLUDE_DIR}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_library(tntkafka SHARED tnt_kafka.c callbacks.c consumer.c consumer_msg.c producer.c queue.c common.c) @@ -9,13 +10,7 @@ endif(APPLE) target_link_libraries(tntkafka pthread) -if("${STATIC_BUILD}" STREQUAL "ON" OR "$ENV{STATIC_BUILD}" STREQUAL "ON") - add_dependencies(tntkafka rdkafka) - target_link_libraries(tntkafka ${CMAKE_SOURCE_DIR}/librdkafka/src/librdkafka.a) -else() - target_link_libraries(tntkafka ${RDKAFKA_LIBRARY}) -endif() - +target_link_libraries(tntkafka ${RDKAFKA_LIBRARY}) set_target_properties(tntkafka PROPERTIES PREFIX "" OUTPUT_NAME "tntkafka") install(TARGETS tntkafka LIBRARY DESTINATION ${TARANTOOL_INSTALL_LIBDIR}/kafka)