Skip to content

Commit 85b7e57

Browse files
authored
Use CMAKE_STATIC_LIBRARY_* macros for FindRdKafka
In the current implementation, library suffixes are hard coded from a hand-maintained list. Instead of writing this list, we can use the CMake macros for platform specific library prefix/suffixes. E.g. https://cmake.org/cmake/help/v3.0/variable/CMAKE_STATIC_LIBRARY_SUFFIX.html This also resolves library resolution on Mac OSX, which does not currently work on the native `.dylib` suffix for shared libraries.
1 parent 4ba6b38 commit 85b7e57

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

cmake/FindRdKafka.cmake

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
# Override default CMAKE_FIND_LIBRARY_SUFFIXES
2+
# (Allows optional prioritization of static libraries during resolution)
23
if (CPPKAFKA_RDKAFKA_STATIC_LIB)
3-
if (MSVC)
4-
set(RDKAFKA_SUFFIX lib)
5-
else()
6-
set(RDKAFKA_SUFFIX a)
7-
endif()
4+
set(RDKAFKA_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
5+
set(RDKAFKA_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
86
else()
9-
if (MSVC)
10-
set(RDKAFKA_SUFFIX dll)
11-
else()
12-
set(RDKAFKA_SUFFIX so)
13-
endif()
7+
set(RDKAFKA_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
8+
set(RDKAFKA_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
149
endif()
1510

1611
find_path(RDKAFKA_ROOT_DIR
@@ -31,7 +26,7 @@ if (CPPKAFKA_CMAKE_VERBOSE)
3126
endif()
3227

3328
find_library(RDKAFKA_LIBRARY
34-
NAMES rdkafka.${RDKAFKA_SUFFIX} librdkafka.${RDKAFKA_SUFFIX} rdkafka
29+
NAMES ${RDKAFKA_PREFIX}rdkafka${RDKAFKA_SUFFIX} rdkafka
3530
HINTS ${RDKAFKA_ROOT_DIR}/lib
3631
)
3732

0 commit comments

Comments
 (0)