Skip to content

Commit c4b6a95

Browse files
author
Alexander Damian
committed
Fixes per code review
1 parent 40e8559 commit c4b6a95

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,14 @@ endif()
123123
find_package(RdKafka ${FIND_PACKAGE_QUIET} CONFIG)
124124
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
125125
if (NOT RdKafka_FOUND)
126-
message(STATUS "RdKafkaConfig.cmake not found. Please set RDKAFKA_ROOT or RDKAFKA_DIR if a config file is installed. Attempting to find module instead...")
126+
message(STATUS "RdKafkaConfig.cmake not found. Attempting to find module instead...")
127127
find_package(RdKafka REQUIRED ${FIND_PACKAGE_QUIET} MODULE)
128128
if (NOT RdKafka_FOUND)
129-
message(FATAL_ERROR "RdKafka module not found. Please set RDKAFKA_ROOT to the install path.")
129+
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.")
130130
else()
131131
message(STATUS "RdKafka module found.")
132132
endif()
133133
else()
134-
set(RdKafka_DEPENDENCIES RdKafka::rdkafka)
135134
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
136135
endif()
137136

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int main() {
5454
In order to compile _cppkafka_ you need:
5555

5656
* _librdkafka >= 0.9.4_
57-
* _CMake >= 3.10_
57+
* _CMake >= 3.9.2_
5858
* A compiler with good C++11 support (e.g. gcc >= 4.8). This was tested successfully on _g++ 4.8.3_.
5959
* The boost library (for boost::optional)
6060

cmake/FindRdKafka.cmake

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
# - RdKafka_LIBNAME : The name of the library, i.e. librdkafka.a, librdkafka.so, etc.
44
# - RdKafka_LIBRARY_DIR : The directory where the library is located.
55
# - RdKafka_LIBRARY_PATH : The full library path i.e. ${RdKafka_LIBRARY_DIR}/${RdKafka_LIBNAME}
6-
# - RdKafka_DEPENDENCIES : Libs needed to link with RdKafka
6+
# - RdKafka::rdkafka : Imported library containing all above properties set.
77

88
if (CPPKAFKA_RDKAFKA_STATIC_LIB)
99
set(RDKAFKA_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
1010
set(RDKAFKA_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
11+
set(RDKAFKA_LIBRARY_TYPE STATIC)
1112
else()
1213
set(RDKAFKA_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
1314
set(RDKAFKA_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
15+
set(RDKAFKA_LIBRARY_TYPE SHARED)
1416
endif()
1517

1618
set(RdKafka_LIBNAME ${RDKAFKA_PREFIX}rdkafka${RDKAFKA_SUFFIX})
@@ -60,13 +62,13 @@ try_compile(RdKafka_FOUND ${CMAKE_CURRENT_BINARY_DIR}
6062
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${RdKafka_INCLUDE_DIR}")
6163

6264
if (RdKafka_FOUND)
63-
if (CPPKAFKA_RDKAFKA_STATIC_LIB)
64-
set(RdKafka_DEPENDENCIES ${RdKafka_LIBNAME} pthread rt ssl crypto dl z)
65-
else()
66-
set(RdKafka_DEPENDENCIES ${RdKafka_LIBNAME} pthread)
67-
endif()
68-
include_directories(SYSTEM ${RdKafka_INCLUDE_DIR})
69-
link_directories(${RdKafka_LIBRARY_DIR})
65+
add_library(RdKafka::rdkafka ${RDKAFKA_LIBRARY_TYPE} IMPORTED GLOBAL)
66+
set(RDKAFKA_DEPENDENCIES pthread rt ssl crypto dl z)
67+
set_target_properties(RdKafka::rdkafka PROPERTIES
68+
IMPORTED_NAME RdKafka
69+
IMPORTED_LOCATION "${RdKafka_LIBRARY_PATH}"
70+
INTERFACE_INCLUDE_DIRECTORIES "${RdKafka_INCLUDE_DIR}"
71+
INTERFACE_LINK_LIBRARIES "${RDKAFKA_DEPENDENCIES}")
7072
message(STATUS "Found valid rdkafka version")
7173
mark_as_advanced(
7274
RDKAFKA_LIBRARY

cmake/config.cmake.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ find_dependency(Boost REQUIRED)
1313
find_dependency(RdKafka QUIET CONFIG)
1414
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
1515
if (NOT RdKafka_FOUND)
16-
message(STATUS "RdKafkaConfig.cmake not found. Please set RDKAFKA_ROOT or RDKAFKA_DIR if a config file is installed. Attempting to find module instead...")
16+
message(STATUS "RdKafkaConfig.cmake not found. Attempting to find module instead...")
1717
find_dependency(RdKafka REQUIRED QUIET MODULE)
1818
if (NOT RdKafka_FOUND)
19-
message(FATAL_ERROR "RdKafka module not found. Please set RDKAFKA_ROOT to the install path.")
19+
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.")
2020
else()
2121
message(STATUS "RdKafka module found.")
2222
endif()
2323
else()
24-
set(RdKafka_DEPENDENCIES RdKafka::rdkafka)
2524
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
2625
endif()
2726

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ add_custom_target(examples)
44
macro(create_example example_name)
55
string(REPLACE "_" "-" sanitized_name ${example_name})
66
add_executable(${sanitized_name} EXCLUDE_FROM_ALL "${example_name}_example.cpp")
7-
target_link_libraries(${sanitized_name} cppkafka ${RdKafka_DEPENDENCIES} Boost::boost Boost::program_options)
7+
target_link_libraries(${sanitized_name} cppkafka RdKafka::rdkafka Boost::boost Boost::program_options)
88
add_dependencies(examples ${sanitized_name})
99
endmacro()
1010

src/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set(SOURCES
2727
)
2828

2929
set(TARGET_NAME cppkafka)
30-
set(PKG_DIR "${PROJECT_SOURCE_DIR}/package")
30+
set(PKG_DIR "${CMAKE_BINARY_DIR}/package")
3131
set(PKG_CONFIG_FILE "${PKG_DIR}/${TARGET_NAME}.pc")
3232
set(CONFIG_FILE "${PKG_DIR}/${PROJECT_NAME}Config.cmake")
3333
set(VERSION_FILE "${PKG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
@@ -42,12 +42,11 @@ add_library(${TARGET_NAME} ${CPPKAFKA_LIBRARY_TYPE} ${SOURCES})
4242
set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${CPPKAFKA_VERSION}
4343
SOVERSION ${CPPKAFKA_VERSION})
4444
# In CMake >= 3.15 Boost::boost == Boost::headers
45-
set(DEPENDENCIES ${RdKafka_DEPENDENCIES})
45+
target_link_libraries(${TARGET_NAME} PRIVATE RdKafka::rdkafka Boost::boost)
4646
if (WIN32)
4747
# On windows ntohs and related are in ws2_32
48-
set(DEPENDENCIES ${DEPENDENCIES} ws2_32.lib)
48+
target_link_libraries(${TARGET_NAME} PRIVATE ws2_32.lib)
4949
endif()
50-
target_link_libraries(${TARGET_NAME} PRIVATE ${DEPENDENCIES})
5150

5251
# Install cppkafka target and specify all properties needed for the exported file
5352
install(

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ add_executable(cppkafka_tests
2525
)
2626

2727
# In CMake >= 3.15 Boost::boost == Boost::headers
28-
target_link_libraries(cppkafka_tests cppkafka ${RdKafka_DEPENDENCIES} Boost::boost Boost::program_options )
28+
target_link_libraries(cppkafka_tests cppkafka RdKafka::rdkafka Boost::boost Boost::program_options )
2929
add_dependencies(tests cppkafka_tests)
3030
add_test(cppkafka cppkafka_tests)

0 commit comments

Comments
 (0)