Fixes per code review

This commit is contained in:
Alexander Damian
2019-06-30 19:24:27 -04:00
parent 40e8559158
commit c4b6a95438
7 changed files with 20 additions and 21 deletions

View File

@@ -123,15 +123,14 @@ endif()
find_package(RdKafka ${FIND_PACKAGE_QUIET} CONFIG)
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
if (NOT RdKafka_FOUND)
message(STATUS "RdKafkaConfig.cmake not found. Please set RDKAFKA_ROOT or RDKAFKA_DIR if a config file is installed. Attempting to find module instead...")
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.")
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()
set(RdKafka_DEPENDENCIES RdKafka::rdkafka)
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
endif()

View File

@@ -54,7 +54,7 @@ int main() {
In order to compile _cppkafka_ you need:
* _librdkafka >= 0.9.4_
* _CMake >= 3.10_
* _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)

View File

@@ -3,14 +3,16 @@
# - 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_DEPENDENCIES : Libs needed to link with RdKafka
# - 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()
set(RdKafka_LIBNAME ${RDKAFKA_PREFIX}rdkafka${RDKAFKA_SUFFIX})
@@ -60,13 +62,13 @@ try_compile(RdKafka_FOUND ${CMAKE_CURRENT_BINARY_DIR}
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${RdKafka_INCLUDE_DIR}")
if (RdKafka_FOUND)
if (CPPKAFKA_RDKAFKA_STATIC_LIB)
set(RdKafka_DEPENDENCIES ${RdKafka_LIBNAME} pthread rt ssl crypto dl z)
else()
set(RdKafka_DEPENDENCIES ${RdKafka_LIBNAME} pthread)
endif()
include_directories(SYSTEM ${RdKafka_INCLUDE_DIR})
link_directories(${RdKafka_LIBRARY_DIR})
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_LIBRARIES "${RDKAFKA_DEPENDENCIES}")
message(STATUS "Found valid rdkafka version")
mark_as_advanced(
RDKAFKA_LIBRARY

View File

@@ -13,15 +13,14 @@ find_dependency(Boost REQUIRED)
find_dependency(RdKafka QUIET CONFIG)
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
if (NOT RdKafka_FOUND)
message(STATUS "RdKafkaConfig.cmake not found. Please set RDKAFKA_ROOT or RDKAFKA_DIR if a config file is installed. Attempting to find module instead...")
message(STATUS "RdKafkaConfig.cmake not found. Attempting to find module instead...")
find_dependency(RdKafka REQUIRED QUIET MODULE)
if (NOT RdKafka_FOUND)
message(FATAL_ERROR "RdKafka module not found. Please set RDKAFKA_ROOT to the install path.")
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()
set(RdKafka_DEPENDENCIES RdKafka::rdkafka)
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
endif()

View File

@@ -4,7 +4,7 @@ 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_DEPENDENCIES} Boost::boost Boost::program_options)
target_link_libraries(${sanitized_name} cppkafka RdKafka::rdkafka Boost::boost Boost::program_options)
add_dependencies(examples ${sanitized_name})
endmacro()

View File

@@ -27,7 +27,7 @@ set(SOURCES
)
set(TARGET_NAME cppkafka)
set(PKG_DIR "${PROJECT_SOURCE_DIR}/package")
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")
@@ -42,12 +42,11 @@ add_library(${TARGET_NAME} ${CPPKAFKA_LIBRARY_TYPE} ${SOURCES})
set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${CPPKAFKA_VERSION}
SOVERSION ${CPPKAFKA_VERSION})
# In CMake >= 3.15 Boost::boost == Boost::headers
set(DEPENDENCIES ${RdKafka_DEPENDENCIES})
target_link_libraries(${TARGET_NAME} PRIVATE 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} PRIVATE ws2_32.lib)
endif()
target_link_libraries(${TARGET_NAME} PRIVATE ${DEPENDENCIES})
# Install cppkafka target and specify all properties needed for the exported file
install(

View File

@@ -25,6 +25,6 @@ add_executable(cppkafka_tests
)
# In CMake >= 3.15 Boost::boost == Boost::headers
target_link_libraries(cppkafka_tests cppkafka ${RdKafka_DEPENDENCIES} Boost::boost Boost::program_options )
target_link_libraries(cppkafka_tests cppkafka RdKafka::rdkafka Boost::boost Boost::program_options )
add_dependencies(tests cppkafka_tests)
add_test(cppkafka cppkafka_tests)