Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(cmake): Avoid overwriting include directories #221

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ if (NOT BUILD_OPTION_DOC_ONLY)
#---------------------------
if (DEFINED ENV{LIBRDKAFKA_INCLUDE_DIR})
set(LIBRDKAFKA_INCLUDE_DIR $ENV{LIBRDKAFKA_INCLUDE_DIR})
else ()
elseif (NOT DEFINED LIBRDKAFKA_INCLUDE_DIR)
find_file(LIBRDKAFKA_HEADER
NAMES rdkafka.h
HINTS /usr/include/librdkafka /usr/local/include/librdkafka /opt/homebrew/include/librdkafka)
HINTS /usr/include/librdkafka /usr/local/include/librdkafka /opt/homebrew/include/librdkafka /home/linuxbrew/.linuxbrew/include/librdkafka)

cmake_path(GET LIBRDKAFKA_HEADER PARENT_PATH LIBRDKAFKA_INCLUDE_DIR)
cmake_path(GET LIBRDKAFKA_INCLUDE_DIR PARENT_PATH LIBRDKAFKA_INCLUDE_DIR)
endif ()

if (DEFINED ENV{LIBRDKAFKA_LIBRARY_DIR})
set(LIBRDKAFKA_LIBRARY_DIR $ENV{LIBRDKAFKA_LIBRARY_DIR})
else ()
elseif (NOT DEFINED LIBRDKAFKA_LIBRARY_DIR)
find_library(LIBRDKAFKA_LIB
NAMES rdkafka
HINTS /usr/lib /usr/local/lib /opt/homebrew/lib)
HINTS /usr/lib /usr/local/lib /opt/homebrew/lib /home/linuxbrew/.linuxbrew/lib)

cmake_path(GET LIBRDKAFKA_LIB PARENT_PATH LIBRDKAFKA_LIBRARY_DIR)
endif ()
Expand Down Expand Up @@ -106,7 +106,7 @@ if (NOT BUILD_OPTION_DOC_ONLY)
if (CMAKE_CXX_STANDARD EQUAL 14)
if (DEFINED ENV{BOOST_ROOT})
set(Boost_INCLUDE_DIRS $ENV{BOOST_ROOT}/include)
else ()
elseif (NOT DEFINED Boost_INCLUDE_DIRS)
find_package(Boost)
if (NOT Boost_FOUND)
message(FATAL_ERROR "Cound not find library: boost!")
Expand Down
29 changes: 24 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,47 @@ link_directories(${Boost_LIBRARY_DIRS})
#---------------------------
if (DEFINED ENV{GTEST_ROOT})
set(GTEST_ROOT $ENV{GTEST_ROOT})
else ()
elseif (NOT DEFINED GTEST_ROOT)
if (EXISTS "/usr/local/include/gtest/gtest.h")
set(GTEST_ROOT /usr/local)
elseif (EXISTS "/opt/homebrew/include/gtest/gtest.h")
set(GTEST_ROOT /opt/homebrew)
endif ()
endif ()

if (NOT EXISTS "${GTEST_ROOT}/include/gtest/gtest.h")
# include dir
if (EXISTS "${GTEST_ROOT}/include/gtest/gtest.h")
set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include)
else ()
if (NOT DEFINED GTEST_INCLUDE_DIR)
set(GTEST_INCLUDE_DIR ENV{GTEST_INCLUDE_DIR})
endif()
endif ()
if (NOT DEFINED GTEST_INCLUDE_DIR)
message(FATAL_ERROR "Could not find headers for gtest!")
else()
message(STATUS "gtest include directory: ${GTEST_INCLUDE_DIR}")
endif ()

if (NOT (EXISTS "${GTEST_ROOT}/lib/libgtest_main.a"
if ((EXISTS "${GTEST_ROOT}/lib/libgtest_main.a"
OR EXISTS "${GTEST_ROOT}/lib/libgtest_main.so"
OR EXISTS "${GTEST_ROOT}/lib/gtest_main.lib"))
set(GTEST_LIBRARY_DIR ${GTEST_ROOT}/lib)
else ()
if (NOT DEFINED GTEST_LIBRARY_DIR)
set(GTEST_LIBRARY_DIR ENV{GTEST_LIBRARY_DIR})
endif()
endif ()
if (NOT DEFINED GTEST_LIBRARY_DIR)
message(FATAL_ERROR "Could not find library for gtest!")
else()
message(STATUS "gtest library directory: ${GTEST_LIBRARY_DIR}")
endif ()

message(STATUS "googletest root directory: ${GTEST_ROOT}")

include_directories(SYSTEM ${GTEST_ROOT}/include)
link_directories(${GTEST_ROOT}/lib ${GTEST_ROOT}/bin)
include_directories(SYSTEM ${GTEST_INCLUDE_DIR})
link_directories(${GTEST_LIBRARY_DIR} ${GTEST_ROOT}/bin)


#---------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project("kafka-unit-test")
#---------------------------
if (DEFINED ENV{RAPIDJSON_INCLUDE_DIRS})
set(RAPIDJSON_INCLUDE_DIRS $ENV{RAPIDJSON_INCLUDE_DIRS})
else ()
elseif (NOT DEFINED RAPIDJSON_INCLUDE_DIRS)
find_file(RAPIDJSON_HEADER
NAMES rapidjson.h
HINTS /usr/include/rapidjson /usr/local/include/rapidjson /opt/homebrew/include/rapidjson)
Expand Down