mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-10-31 18:47:48 +00:00
Merge pull request #204 from accelerated/cmake
Add CMake configuration file and export installed targets
This commit is contained in:
@@ -37,7 +37,7 @@ script:
|
||||
- ./configure --prefix=./install && make libs && make install
|
||||
- cd ..
|
||||
- mkdir build && cd build
|
||||
- cmake .. -DRDKAFKA_ROOT_DIR=../librdkafka/install/ -DKAFKA_TEST_INSTANCE=localhost:9092
|
||||
- cmake .. -DCPPKAFKA_CMAKE_VERBOSE=ON -DRDKAFKA_ROOT=./librdkafka/install -DKAFKA_TEST_INSTANCE=localhost:9092
|
||||
- make examples
|
||||
- make tests
|
||||
- ./tests/cppkafka_tests
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
cmake_minimum_required(VERSION 2.8.1)
|
||||
project(cppkafka)
|
||||
cmake_minimum_required(VERSION 3.9.2)
|
||||
project(CppKafka)
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
|
||||
# Use <package>_ROOT variable to find configuration files
|
||||
cmake_policy(SET CMP0074 NEW)
|
||||
endif()
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
# Set the version number.
|
||||
set(CPPKAFKA_VERSION_MAJOR 0)
|
||||
set(CPPKAFKA_VERSION_MINOR 3)
|
||||
set(CPPKAFKA_VERSION_REVISION 1)
|
||||
set(CPPKAFKA_VERSION "${CPPKAFKA_VERSION_MAJOR}.${CPPKAFKA_VERSION_MINOR}.${CPPKAFKA_VERSION_REVISION}")
|
||||
set(RDKAFKA_MIN_VERSION 0x00090400)
|
||||
set(RDKAFKA_MIN_VERSION "0.9.4")
|
||||
set(RDKAFKA_MIN_VERSION_HEX 0x00090400)
|
||||
|
||||
if (NOT CMAKE_CXX_FLAGS)
|
||||
# Set default compile flags for the project
|
||||
@@ -23,7 +31,6 @@ if (NOT CMAKE_CXX_FLAGS)
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall")
|
||||
endif()
|
||||
endif()
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
||||
|
||||
# Set output directories
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
@@ -37,16 +44,35 @@ 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)
|
||||
option(CPPKAFKA_EXPORT_PKGCONFIG "Generate 'cppkafka.pc' file" ON)
|
||||
option(CPPKAFKA_EXPORT_CMAKE_CONFIG "Generate CMake config, target and version files." ON)
|
||||
|
||||
math(EXPR BITS "8*${CMAKE_SIZEOF_VOID_P}")
|
||||
# Add FindRdKafka.cmake
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
||||
|
||||
# Properly set the output directory
|
||||
#if (${BITS} EQUAL 64)
|
||||
# set(LIBDIR "lib64")
|
||||
#else()
|
||||
# set(LIBDIR "lib")
|
||||
#endif()
|
||||
set(LIBDIR "lib")
|
||||
if (NOT CPPKAFKA_CONFIG_DIR)
|
||||
set(CPPKAFKA_CONFIG_DIR lib/cmake/${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
# Maintain previous compatibility
|
||||
if (RDKAFKA_ROOT_DIR)
|
||||
set(RdKafka_ROOT ${RDKAFKA_ROOT_DIR})
|
||||
elseif (RDKAFKA_ROOT)
|
||||
set(RdKafka_ROOT ${RDKAFKA_ROOT})
|
||||
endif()
|
||||
|
||||
if (RdKafka_ROOT)
|
||||
if (NOT IS_ABSOLUTE ${RdKafka_ROOT})
|
||||
set(RdKafka_ROOT "${CMAKE_SOURCE_DIR}/${RdKafka_ROOT}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (RDKAFKA_DIR)
|
||||
set(RdKafka_DIR ${RDKAFKA_DIR}) # For older versions of find_package
|
||||
if (NOT IS_ABSOLUTE ${RdKafka_ROOT})
|
||||
set(RdKafka_DIR "${CMAKE_SOURCE_DIR}/${RdKafka_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Disable output from find_package macro
|
||||
if (NOT CPPKAFKA_CMAKE_VERBOSE)
|
||||
@@ -61,19 +87,23 @@ else()
|
||||
message(STATUS "Build will generate a static library.")
|
||||
set(CPPKAFKA_LIBRARY_TYPE STATIC)
|
||||
add_definitions("-DCPPKAFKA_STATIC=1")
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
if (CPPKAFKA_RDKAFKA_STATIC_LIB)
|
||||
add_definitions("-DLIBRDKAFKA_STATICLIB")
|
||||
endif()
|
||||
|
||||
if (NOT CPPKAFKA_CONFIG_DIR)
|
||||
set(CPPKAFKA_CONFIG_DIR lib/cmake/${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
if (NOT CPPKAFKA_PKGCONFIG_DIR)
|
||||
set(CPPKAFKA_PKGCONFIG_DIR share/pkgconfig)
|
||||
endif()
|
||||
|
||||
# Look for Boost (just need boost.optional headers here)
|
||||
find_package(Boost REQUIRED ${FIND_PACKAGE_QUIET})
|
||||
find_package(RdKafka REQUIRED ${FIND_PACKAGE_QUIET})
|
||||
|
||||
if (Boost_FOUND)
|
||||
find_package(Boost COMPONENTS program_options ${FIND_PACKAGE_QUIET})
|
||||
@@ -90,8 +120,24 @@ if (Boost_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Try to find the RdKafka configuration file if present.
|
||||
# This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified.
|
||||
find_package(RdKafka ${FIND_PACKAGE_QUIET} CONFIG)
|
||||
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
|
||||
if (NOT RdKafka_FOUND)
|
||||
message(STATUS "RdKafkaConfig.cmake not found. Attempting to find module instead...")
|
||||
find_package(RdKafka REQUIRED ${FIND_PACKAGE_QUIET} MODULE)
|
||||
if (NOT RdKafka_FOUND)
|
||||
message(FATAL_ERROR "RdKafka module not found. Please set RDKAFKA_ROOT to the install path or RDKAFKA_DIR pointing to the RdKafka configuration file location.")
|
||||
else()
|
||||
message(STATUS "RdKafka module found.")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(include)
|
||||
add_subdirectory(include/cppkafka)
|
||||
|
||||
# Examples target
|
||||
if (NOT CPPKAFKA_DISABLE_EXAMPLES AND Boost_PROGRAM_OPTIONS_FOUND)
|
||||
|
||||
37
README.md
37
README.md
@@ -54,10 +54,9 @@ int main() {
|
||||
In order to compile _cppkafka_ you need:
|
||||
|
||||
* _librdkafka >= 0.9.4_
|
||||
* _CMake_
|
||||
* A compiler with good C++11 support (e.g. gcc >= 4.8). This was tested successfully on
|
||||
_g++ 4.8.3_.
|
||||
* The boost library.
|
||||
* _CMake >= 3.9.2_
|
||||
* A compiler with good C++11 support (e.g. gcc >= 4.8). This was tested successfully on _g++ 4.8.3_.
|
||||
* The boost library (for boost::optional)
|
||||
|
||||
Now, in order to build, just run:
|
||||
|
||||
@@ -66,12 +65,14 @@ mkdir build
|
||||
cd build
|
||||
cmake <OPTIONS> ..
|
||||
make
|
||||
make install
|
||||
```
|
||||
|
||||
## CMake options
|
||||
|
||||
The following cmake options can be specified:
|
||||
* `RDKAFKA_ROOT_DIR` : Specify a different librdkafka install directory.
|
||||
* `RDKAFKA_ROOT` : Specify a different librdkafka install directory.
|
||||
* `RDKAFKA_DIR` : Specify a different directory where the RdKafkaConfig.cmake is installed.
|
||||
* `BOOST_ROOT` : Specify a different Boost install directory.
|
||||
* `CPPKAFKA_CMAKE_VERBOSE` : Generate verbose output. Default is `OFF`.
|
||||
* `CPPKAFKA_BUILD_SHARED` : Build cppkafka as a shared library. Default is `ON`.
|
||||
@@ -80,25 +81,14 @@ The following cmake options can be specified:
|
||||
* `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`.
|
||||
* `CPPKAFKA_CONFIG_DIR` : Install location of the cmake configuration files. Default is `lib/cmake/cppkafka`.
|
||||
* `CPPKAFKA_PKGCONFIG_DIR` : Install location of the .pc file. Default is `share/pkgconfig`.
|
||||
* `CPPKAFKA_EXPORT_PKGCONFIG` : Generate `cppkafka.pc` file. Default is `ON`.
|
||||
* `CPPKAFKA_EXPORT_CMAKE_CONFIG` : Generate CMake config, target and version files. Default is `ON`.
|
||||
|
||||
Example:
|
||||
```Shell
|
||||
cmake -DRDKAFKA_ROOT_DIR=/some/other/dir -DCPPKAFKA_BUILD_SHARED=OFF ...
|
||||
```
|
||||
|
||||
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}/
|
||||
|
|
||||
+ include/librdkafka/rdkafka.h
|
||||
|
|
||||
+ lib/librdkafka.a
|
||||
|
|
||||
+ lib64/librdkafka.a (optional)
|
||||
cmake -DRDKAFKA_ROOT=/some/other/dir -DCPPKAFKA_BUILD_SHARED=OFF ...
|
||||
```
|
||||
|
||||
# Using
|
||||
@@ -108,6 +98,13 @@ If you want to use _cppkafka_, you'll need to link your application with:
|
||||
* _cppkafka_
|
||||
* _rdkafka_
|
||||
|
||||
If using CMake, this is simplified by doing:
|
||||
```cmake
|
||||
find_package(CppKafka REQUIRED)
|
||||
|
||||
target_link_libraries(<YourLibrary> CppKafka::cppkafka)
|
||||
```
|
||||
|
||||
# Documentation
|
||||
|
||||
You can generate the documentation by running `make docs` inside the build directory. This requires
|
||||
|
||||
@@ -1,55 +1,80 @@
|
||||
# Override default CMAKE_FIND_LIBRARY_SUFFIXES
|
||||
# (Allows optional prioritization of static libraries during resolution)
|
||||
# This find module helps find the RdKafka module. It exports the following variables:
|
||||
# - RdKafka_INCLUDE_DIR : The directory where rdkafka.h is located.
|
||||
# - RdKafka_LIBNAME : The name of the library, i.e. librdkafka.a, librdkafka.so, etc.
|
||||
# - RdKafka_LIBRARY_DIR : The directory where the library is located.
|
||||
# - RdKafka_LIBRARY_PATH : The full library path i.e. ${RdKafka_LIBRARY_DIR}/${RdKafka_LIBNAME}
|
||||
# - RdKafka::rdkafka : Imported library containing all above properties set.
|
||||
|
||||
if (CPPKAFKA_RDKAFKA_STATIC_LIB)
|
||||
set(RDKAFKA_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
|
||||
set(RDKAFKA_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
set(RDKAFKA_LIBRARY_TYPE STATIC)
|
||||
else()
|
||||
set(RDKAFKA_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
|
||||
set(RDKAFKA_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
set(RDKAFKA_LIBRARY_TYPE SHARED)
|
||||
endif()
|
||||
|
||||
find_path(RDKAFKA_ROOT_DIR
|
||||
NAMES include/librdkafka/rdkafka.h
|
||||
set(RdKafka_LIBNAME ${RDKAFKA_PREFIX}rdkafka${RDKAFKA_SUFFIX})
|
||||
|
||||
find_path(RdKafka_INCLUDE_DIR
|
||||
NAMES librdkafka/rdkafka.h
|
||||
HINTS ${RdKafka_ROOT}/include
|
||||
)
|
||||
|
||||
find_path(RDKAFKA_INCLUDE_DIR
|
||||
NAMES librdkafka/rdkafka.h
|
||||
HINTS ${RDKAFKA_ROOT_DIR}/include
|
||||
find_path(RdKafka_LIBRARY_DIR
|
||||
NAMES ${RdKafka_LIBNAME} rdkafka
|
||||
HINTS ${RdKafka_ROOT}/lib ${RdKafka_ROOT}/lib64
|
||||
)
|
||||
|
||||
find_library(RdKafka_LIBRARY_PATH
|
||||
NAMES ${RdKafka_LIBNAME} rdkafka
|
||||
HINTS ${RdKafka_LIBRARY_DIR}
|
||||
)
|
||||
|
||||
# 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}")
|
||||
message(STATUS "RDKAFKA search 32-bit library paths: ${FIND_LIBRARY_32}")
|
||||
message(STATUS "RDKAFKA search 64-bit library paths: ${FIND_LIBRARY_64}")
|
||||
message(STATUS "RdKafka_ROOT = ${RdKafka_ROOT}")
|
||||
message(STATUS "RdKafka_INCLUDE_DIR = ${RdKafka_INCLUDE_DIR}")
|
||||
message(STATUS "RdKafka_LIBNAME = ${RdKafka_LIBNAME}")
|
||||
message(STATUS "RdKafka_LIBRARY_PATH = ${RdKafka_LIBRARY_PATH}")
|
||||
message(STATUS "RdKafka_LIBRARY_DIR = ${RdKafka_LIBRARY_DIR}")
|
||||
endif()
|
||||
|
||||
find_library(RDKAFKA_LIBRARY
|
||||
NAMES ${RDKAFKA_PREFIX}rdkafka${RDKAFKA_SUFFIX} rdkafka
|
||||
HINTS ${RDKAFKA_ROOT_DIR}/lib
|
||||
)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(RDKAFKA DEFAULT_MSG
|
||||
RDKAFKA_LIBRARY
|
||||
RDKAFKA_INCLUDE_DIR
|
||||
RdKafka_LIBNAME
|
||||
RdKafka_LIBRARY_DIR
|
||||
RdKafka_LIBRARY_PATH
|
||||
RdKafka_INCLUDE_DIR
|
||||
)
|
||||
|
||||
set(CONTENTS "#include <librdkafka/rdkafka.h>\n #if RD_KAFKA_VERSION >= ${RDKAFKA_MIN_VERSION}\n int main() { }\n #endif")
|
||||
set(FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/rdkafka_version_test.c)
|
||||
set(CONTENTS "#include <librdkafka/rdkafka.h>\n #if RD_KAFKA_VERSION >= ${RDKAFKA_MIN_VERSION_HEX}\n int main() { }\n #endif")
|
||||
set(FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/rdkafka_version_test.cpp)
|
||||
file(WRITE ${FILE_NAME} ${CONTENTS})
|
||||
|
||||
try_compile(HAVE_VALID_KAFKA_VERSION ${CMAKE_CURRENT_BINARY_DIR}
|
||||
try_compile(RdKafka_FOUND ${CMAKE_CURRENT_BINARY_DIR}
|
||||
SOURCES ${FILE_NAME}
|
||||
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${RDKAFKA_INCLUDE_DIR}")
|
||||
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${RdKafka_INCLUDE_DIR}")
|
||||
|
||||
if (HAVE_VALID_KAFKA_VERSION)
|
||||
if (RdKafka_FOUND)
|
||||
add_library(RdKafka::rdkafka ${RDKAFKA_LIBRARY_TYPE} IMPORTED GLOBAL)
|
||||
set(RDKAFKA_DEPENDENCIES pthread rt ssl crypto dl z)
|
||||
set_target_properties(RdKafka::rdkafka PROPERTIES
|
||||
IMPORTED_NAME RdKafka
|
||||
IMPORTED_LOCATION "${RdKafka_LIBRARY_PATH}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${RdKafka_INCLUDE_DIR}"
|
||||
INTERFACE_LINK_DIRECTORIES "${RdKafka_LIBRARY_DIR}"
|
||||
INTERFACE_LINK_LIBRARIES "${RDKAFKA_DEPENDENCIES}")
|
||||
message(STATUS "Found valid rdkafka version")
|
||||
mark_as_advanced(
|
||||
RDKAFKA_ROOT_DIR
|
||||
RDKAFKA_INCLUDE_DIR
|
||||
RDKAFKA_LIBRARY
|
||||
RdKafka_LIBRARY_DIR
|
||||
RdKafka_INCLUDE_DIR
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR "Failed to find valid rdkafka version")
|
||||
|
||||
33
cmake/config.cmake.in
Normal file
33
cmake/config.cmake.in
Normal file
@@ -0,0 +1,33 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
# Add FindRdKafka.cmake
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}")
|
||||
|
||||
set(RDKAFKA_MIN_VERSION_HEX "@RDKAFKA_MIN_VERSION_HEX@")
|
||||
|
||||
# Find boost optional
|
||||
find_dependency(Boost REQUIRED)
|
||||
|
||||
# Try to find the RdKafka configuration file if present.
|
||||
# This will search default system locations as well as RdKafka_ROOT and RdKafka_DIR paths if specified.
|
||||
find_package(RdKafka QUIET CONFIG)
|
||||
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
|
||||
if (NOT RdKafka_FOUND)
|
||||
find_dependency(RdKafka REQUIRED MODULE)
|
||||
endif()
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@TARGET_EXPORT_NAME@.cmake")
|
||||
|
||||
# Export 'CppKafka_ROOT'
|
||||
set_and_check(@PROJECT_NAME@_ROOT "@PACKAGE_CMAKE_INSTALL_PREFIX@")
|
||||
|
||||
# Export 'CppKafka_INSTALL_INCLUDE_DIR'
|
||||
set_and_check(@PROJECT_NAME@_INSTALL_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
|
||||
|
||||
# Export 'CppKafka_INSTALL_LIB_DIR'
|
||||
set_and_check(@PROJECT_NAME@_INSTALL_LIB_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
|
||||
|
||||
# Validate installed components
|
||||
check_required_components("@PROJECT_NAME@")
|
||||
@@ -1,7 +1,7 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${prefix}/@LIBDIR@
|
||||
sharedlibdir=${prefix}/@LIBDIR@
|
||||
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
sharedlibdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: cppkafka
|
||||
@@ -1,11 +1,10 @@
|
||||
link_libraries(cppkafka ${RDKAFKA_LIBRARY} ${Boost_LIBRARIES} pthread rt ssl crypto dl z)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
||||
include_directories(SYSTEM ${RDKAFKA_INCLUDE_DIR})
|
||||
|
||||
add_custom_target(examples)
|
||||
macro(create_example example_name)
|
||||
string(REPLACE "_" "-" sanitized_name ${example_name})
|
||||
add_executable(${sanitized_name} EXCLUDE_FROM_ALL "${example_name}_example.cpp")
|
||||
target_link_libraries(${sanitized_name} cppkafka RdKafka::rdkafka Boost::boost Boost::program_options)
|
||||
add_dependencies(examples ${sanitized_name})
|
||||
endmacro()
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
add_subdirectory(cppkafka)
|
||||
@@ -10,7 +10,7 @@ function(make_cppkafka_header)
|
||||
endforeach()
|
||||
|
||||
#create file from template
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cppkafka.h.in ${CPPKAFKA_HEADER} @ONLY)
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/cppkafka.h.in ${CPPKAFKA_HEADER} @ONLY)
|
||||
endfunction()
|
||||
|
||||
# Run file generation function
|
||||
|
||||
@@ -26,34 +26,82 @@ set(SOURCES
|
||||
utils/roundrobin_poll_strategy.cpp
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/cppkafka)
|
||||
include_directories(SYSTEM ${Boost_INCLUDE_DIRS} ${RDKAFKA_INCLUDE_DIR})
|
||||
set(TARGET_NAME cppkafka)
|
||||
set(PKG_DIR "${CMAKE_BINARY_DIR}/package")
|
||||
set(PKG_CONFIG_FILE "${PKG_DIR}/${TARGET_NAME}.pc")
|
||||
set(CONFIG_FILE "${PKG_DIR}/${PROJECT_NAME}Config.cmake")
|
||||
set(VERSION_FILE "${PKG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
||||
set(FIND_RDKAFKA_FILE "${PROJECT_SOURCE_DIR}/cmake/FindRdKafka.cmake")
|
||||
set(NAMESPACE "${PROJECT_NAME}::")
|
||||
set(TARGET_EXPORT_NAME ${PROJECT_NAME}Targets)
|
||||
|
||||
add_library(cppkafka ${CPPKAFKA_LIBRARY_TYPE} ${SOURCES})
|
||||
set_target_properties(cppkafka PROPERTIES VERSION ${CPPKAFKA_VERSION}
|
||||
add_library(${TARGET_NAME} ${CPPKAFKA_LIBRARY_TYPE} ${SOURCES})
|
||||
target_include_directories(${TARGET_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include/cppkafka>)
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}"
|
||||
ARCHIVE_OUTPUT_NAME "${TARGET_NAME}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_INSTALL_LIBDIR}"
|
||||
LIBRARY_OUTPUT_NAME "${TARGET_NAME}"
|
||||
INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}"
|
||||
INSTALL_RPATH_USE_LINK_PATH TRUE
|
||||
VERSION ${CPPKAFKA_VERSION}
|
||||
SOVERSION ${CPPKAFKA_VERSION})
|
||||
|
||||
set(DEPENDENCIES ${RDKAFKA_LIBRARY})
|
||||
# In CMake >= 3.15 Boost::boost == Boost::headers
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC RdKafka::rdkafka Boost::boost)
|
||||
if (WIN32)
|
||||
# On windows ntohs and related are in ws2_32
|
||||
set(DEPENDENCIES ${DEPENDENCIES} ws2_32.lib)
|
||||
target_link_libraries(${TARGET_NAME} PUBLIC ws2_32.lib)
|
||||
endif()
|
||||
target_link_libraries(cppkafka ${DEPENDENCIES})
|
||||
target_include_directories(cppkafka PUBLIC ${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
# Install cppkafka target and specify all properties needed for the exported file
|
||||
install(
|
||||
TARGETS cppkafka
|
||||
LIBRARY DESTINATION ${LIBDIR}
|
||||
ARCHIVE DESTINATION ${LIBDIR}
|
||||
COMPONENT dev
|
||||
TARGETS ${TARGET_NAME}
|
||||
EXPORT ${TARGET_EXPORT_NAME}
|
||||
COMPONENT binaries
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
)
|
||||
|
||||
# Generate package configuration file
|
||||
set(PKG_CONFIG ${PROJECT_SOURCE_DIR}/package/cppkafka.pc)
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cppkafka.pc.in ${PKG_CONFIG} @ONLY)
|
||||
if (CPPKAFKA_EXPORT_PKGCONFIG)
|
||||
# Generate and install pkgconfig file
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/cppkafka.pc.in ${PKG_CONFIG_FILE} @ONLY)
|
||||
|
||||
install(
|
||||
FILES ${PKG_CONFIG}
|
||||
DESTINATION ${CPPKAFKA_PKGCONFIG_DIR}
|
||||
install(
|
||||
FILES ${PKG_CONFIG_FILE}
|
||||
DESTINATION "${CPPKAFKA_PKGCONFIG_DIR}"
|
||||
COMPONENT pkgconfig
|
||||
)
|
||||
)
|
||||
endif()
|
||||
|
||||
if (CPPKAFKA_EXPORT_CMAKE_CONFIG)
|
||||
# Install the exported file
|
||||
install(
|
||||
EXPORT "${TARGET_EXPORT_NAME}"
|
||||
NAMESPACE "${NAMESPACE}"
|
||||
COMPONENT config
|
||||
DESTINATION "${CPPKAFKA_CONFIG_DIR}"
|
||||
)
|
||||
|
||||
# Generate CMAKE configuration file and exported targets
|
||||
configure_package_config_file(
|
||||
"${PROJECT_SOURCE_DIR}/cmake/config.cmake.in"
|
||||
"${CONFIG_FILE}"
|
||||
INSTALL_DESTINATION "${CPPKAFKA_CONFIG_DIR}"
|
||||
PATH_VARS RDKAFKA_MIN_VERSION_HEX CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
|
||||
)
|
||||
|
||||
# Generate version file
|
||||
write_basic_package_version_file(
|
||||
"${VERSION_FILE}"
|
||||
VERSION ${CPPKAFKA_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
install(
|
||||
FILES "${CONFIG_FILE}" "${VERSION_FILE}" "${FIND_RDKAFKA_FILE}"
|
||||
DESTINATION "${CPPKAFKA_CONFIG_DIR}"
|
||||
COMPONENT config
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include/)
|
||||
include_directories(SYSTEM ${CATCH_INCLUDE})
|
||||
include_directories(SYSTEM ${RDKAFKA_INCLUDE_DIR})
|
||||
|
||||
set(KAFKA_TEST_INSTANCE "kafka-vm:9092"
|
||||
CACHE STRING "The kafka instance to which to connect to run tests")
|
||||
@@ -24,6 +23,8 @@ add_executable(cppkafka_tests
|
||||
# Main file
|
||||
test_main.cpp
|
||||
)
|
||||
target_link_libraries(cppkafka_tests cppkafka ${RDKAFKA_LIBRARY} pthread rt ssl crypto dl z)
|
||||
|
||||
# In CMake >= 3.15 Boost::boost == Boost::headers
|
||||
target_link_libraries(cppkafka_tests cppkafka RdKafka::rdkafka Boost::boost Boost::program_options )
|
||||
add_dependencies(tests cppkafka_tests)
|
||||
add_test(cppkafka cppkafka_tests)
|
||||
|
||||
Reference in New Issue
Block a user