revision-id: a576082c763a6ffdb0479a18968b2fe2b8a80780 () parent(s): 5349b6d4a81fbc4661c83d722e55159ee9d39ee1 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2019-02-04 00:09:00 +0300 message: Add support for compiling with librdkafka and AWS C++ SDK -DUSE_KAFKA=1 assumes that librdkafka and librdkafka++ are installed system-wide. The library supports pkg-config but doesn't support CMake's find_package. -DUSE_AWS=1 -DAWS_INSTALL_PREFIX=... links with an already-installed AWS C++ SDK. The SDK supports CMake's find_package but one still has to work around some glitches. --- CMakeLists.txt | 60 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df5db6bf..131a62ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ option(WITH_SNAPPY "build with SNAPPY" OFF) option(WITH_LZ4 "build with lz4" OFF) option(WITH_ZLIB "build with zlib" OFF) option(WITH_ZSTD "build with zstd" OFF) +option(WITH_KAFKA "build with librdkafka" OFF) # find_package(snappy REQUIRED) @@ -56,39 +57,46 @@ option(WITH_ZSTD "build with zstd" OFF) # include_directories(${SNAPPY_INCLUDE_DIR}) # list(APPEND THIRDPARTY_LIBS ${SNAPPY_LIBRARIES}) -#find_package(rdkafka REQUIRED) -#add_definitions(-DUSE_KAFKA) -#include_directories(${RDKAFKA_INCLUDE_DIR}) -#list(APPEND THIRDPARTY_LIBS ${RDKAFKA_LIBRARIES}) -#CMAKE_LINK_LIBRARY_FLAG -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lrdkafka++") # [MS] Adding debug info set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -g") -# [MS] Adding librdkafka++ -# rdkafka uses pkgconfig instead of Findrdkafka.cmake -# https://stackoverflow.com/questions/29191855/what-is-the-proper-way-to-use-p... -add_definitions(-DUSE_KAFKA) -# Using system installed rdkafka -# find_package(PkgConfig REQUIRED) -# pkg_check_modules(RDKAFKA REQUIRED rdkafka++) -# include_directories(${RDKAFKA_INCLUDE_DIR}) -# list(APPEND THIRDPARTY_LIBS ${RDKAFKA_LIBRARIES}) -# use custom location for rdkafka -include_directories(/home/myrocks/Work/librdkafka/librdkafka-0.11.5/install/usr/local/include) -list(APPEND THIRDPARTY_LIBS rdkafka rdkafka++) -link_directories(/home/myrocks/Work/librdkafka/librdkafka-0.11.5/install/usr/local/lib) - -# [MS] Adding AWS libs -add_definitions(-DUSE_AWS) -include_directories(/home/myrocks/Work/aws/aws-sdk-cpp_master_2018-06-25/install/usr/local/include) -# -laws-cpp-sdk-s3 -laws-cpp-sdk-kinesis -laws-cpp-sdk-core -list(APPEND THIRDPARTY_LIBS aws-cpp-sdk-s3 aws-cpp-sdk-kinesis aws-cpp-sdk-core) -link_directories(/home/myrocks/Work/aws/aws-sdk-cpp_master_2018-06-25/install/usr/local/lib) +if(WITH_KAFKA) + # System lib used + # rdkafka uses pkgconfig instead of Findrdkafka.cmake + # https://stackoverflow.com/questions/29191855/what-is-the-proper-way-to-use-p... + find_package(PkgConfig REQUIRED) + pkg_check_modules(RDKAFKA REQUIRED rdkafka++) + add_definitions(-DUSE_KAFKA) + include_directories(${RDKAFKA_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${RDKAFKA_LIBRARIES}) +endif() + +if(WITH_AWS) + add_definitions(-DUSE_AWS) + # AWS_INSTALL_PREFIX should be the path that was used as CMAKE_INSTALL_PREFIX + # for the aws-cpp-sdk + message(STATUS " AWS_INSTALL_PREFIX=${AWS_INSTALL_PREFIX}") + + # I wasn't able to point find_package to a single location and have it find + # all components of the SDK. aws-cpp-* and aws-c-* seem to use different + # layout. + # Discussion here might be related: https://github.com/aws/aws-sdk-cpp/issues/1020 + # + set(CMAKE_PREFIX_PATH ${AWS_INSTALL_PREFIX}/lib ${AWS_INSTALL_PREFIX}/lib/cmake ${CMAKE_PREFIX_PATH}) + message(STATUS " Adjusted CMAKE_PREFIX_PATH to search for AWS SDK parts: ${CMAKE_PREFIX_PATH}") + + + find_package(AWSSDK REQUIRED COMPONENTS s3 kinesis PATHS ${WITH_AWS}) + message(STATUS "Got AWSSDK_LINK_LIBRARIES: ${AWSSDK_LINK_LIBRARIES}") + message(STATUS "Got AWSSDK_INCLUDE_DIRdir: ${AWSSDK_INCLUDE_DIR}") + + list(APPEND THIRDPARTY_LIBS ${AWSSDK_LINK_LIBRARIES}) + include_directories(${AWSSDK_INCLUDE_DIR}) +endif() if(MSVC) # Defaults currently different for GFLAGS.