Skip to content

Commit 98692ff

Browse files
committed
Improve CMakeLists for dependencies check
1 parent c3de6e4 commit 98692ff

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,22 @@ if (NOT BUILD_OPTION_DOC_ONLY)
4242
if (DEFINED ENV{LIBRDKAFKA_INCLUDE_DIR})
4343
set(LIBRDKAFKA_INCLUDE_DIR $ENV{LIBRDKAFKA_INCLUDE_DIR})
4444
else ()
45-
set(LIBRDKAFKA_INCLUDE_DIR /usr/local/include)
45+
find_file(LIBRDKAFKA_HEADER
46+
NAMES rdkafka.h
47+
HINTS /usr/include/librdkafka /usr/local/include/librdkafka /opt/homebrew/include/librdkafka)
48+
49+
cmake_path(GET LIBRDKAFKA_HEADER PARENT_PATH LIBRDKAFKA_INCLUDE_DIR)
50+
cmake_path(GET LIBRDKAFKA_INCLUDE_DIR PARENT_PATH LIBRDKAFKA_INCLUDE_DIR)
4651
endif ()
52+
4753
if (DEFINED ENV{LIBRDKAFKA_LIBRARY_DIR})
4854
set(LIBRDKAFKA_LIBRARY_DIR $ENV{LIBRDKAFKA_LIBRARY_DIR})
4955
else ()
50-
set(LIBRDKAFKA_LIBRARY_DIR /usr/local/lib)
56+
find_library(LIBRDKAFKA_LIB
57+
NAMES rdkafka
58+
HINTS /usr/lib /usr/local/lib /opt/homebrew/lib)
59+
60+
cmake_path(GET LIBRDKAFKA_LIB PARENT_PATH LIBRDKAFKA_LIBRARY_DIR)
5161
endif ()
5262

5363
if (EXISTS "${LIBRDKAFKA_INCLUDE_DIR}/librdkafka/rdkafka.h")

tests/unit/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ project("kafka-unit-test")
66
if (DEFINED ENV{RAPIDJSON_INCLUDE_DIRS})
77
set(RAPIDJSON_INCLUDE_DIRS $ENV{RAPIDJSON_INCLUDE_DIRS})
88
else ()
9-
set(RAPIDJSON_INCLUDE_DIRS /usr/include)
9+
find_file(RAPIDJSON_HEADER
10+
NAMES rapidjson.h
11+
HINTS /usr/include/rapidjson /usr/local/include/rapidjson /opt/homebrew/include/rapidjson)
12+
13+
cmake_path(GET RAPIDJSON_HEADER PARENT_PATH RAPIDJSON_INCLUDE_DIRS)
14+
cmake_path(GET RAPIDJSON_INCLUDE_DIRS PARENT_PATH RAPIDJSON_INCLUDE_DIRS)
1015
endif ()
1116

1217
if (EXISTS "${RAPIDJSON_INCLUDE_DIRS}/rapidjson/rapidjson.h")

0 commit comments

Comments
 (0)