From 557aea8e914d7994b64c53ec764a4414de895328 Mon Sep 17 00:00:00 2001 From: ditsuke Date: Sun, 27 Aug 2023 13:07:21 +0530 Subject: [PATCH 1/4] build(cmake): Avoid overwriting include directories - Adds guard-checks against overwriting include directories passed as flags/inherited by cmake. - Also adds find_files hints for linuxbrex directories (homebrew for linux) --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11f81aae..4cf8f99a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,10 +41,10 @@ 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) @@ -52,10 +52,10 @@ if (NOT BUILD_OPTION_DOC_ONLY) 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 () @@ -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!") From 3c97ebe6408e3e3d07c81a23a60aa4b498cb7915 Mon Sep 17 00:00:00 2001 From: ditsuke Date: Sun, 27 Aug 2023 14:24:37 +0530 Subject: [PATCH 2/4] build(cmake): Decouple gtest lib/headers and avoid overwriting --- tests/CMakeLists.txt | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4b069a6e..dc00c080 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,7 +23,7 @@ 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") @@ -31,20 +31,35 @@ else () 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!") 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!") 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(${CMAKE_LIBRARY_DIR} ${GTEST_ROOT}/bin) #--------------------------- From 60e72028a0120905b1d7b43061f5363e932c5d70 Mon Sep 17 00:00:00 2001 From: ditsuke Date: Sun, 27 Aug 2023 15:43:40 +0530 Subject: [PATCH 3/4] build(cmake): Avoid overwriting rapidjson's include dir --- tests/unit/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index e4c8a0a7..09744d21 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -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) From a0b5ec08315759097ce656813be57b2c38d79091 Mon Sep 17 00:00:00 2001 From: ditsuke Date: Sun, 27 Aug 2023 15:47:12 +0530 Subject: [PATCH 4/4] build(cmake): Add path match messages for gtest dirs --- tests/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dc00c080..4de5e248 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -41,6 +41,8 @@ else () 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 ((EXISTS "${GTEST_ROOT}/lib/libgtest_main.a" @@ -54,12 +56,14 @@ else () 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_INCLUDE_DIR}) -link_directories(${CMAKE_LIBRARY_DIR} ${GTEST_ROOT}/bin) +link_directories(${GTEST_LIBRARY_DIR} ${GTEST_ROOT}/bin) #---------------------------