Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/pr-compile-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y bison cmake flex gcc libssl-dev libyaml-dev
sudo apt-get install -y libzstd-dev librdkafka-dev
sudo apt-get install -y libzstd-dev

- name: Install cmake
uses: jwlawson/actions-setup-cmake@v2
Expand All @@ -149,6 +149,6 @@ jobs:
run: |
export CXX=/bin/false
export nparallel=$(( $(getconf _NPROCESSORS_ONLN) > 8 ? 8 : $(getconf _NPROCESSORS_ONLN) ))
cmake -DFLB_PREFER_SYSTEM_LIB_ZSTD=ON -DFLB_PREFER_SYSTEM_LIB_KAFKA=ON ../
cmake -DFLB_PREFER_SYSTEM_LIB_ZSTD=ON ../
make -j $nparallel
working-directory: build
22 changes: 19 additions & 3 deletions lib/librdkafka-2.10.1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ cmake_minimum_required(VERSION 3.5)
include("packaging/cmake/parseversion.cmake")
parseversion("src/rdkafka.h")

project(RdKafka VERSION ${RDKAFKA_VERSION})
project(RdKafka VERSION ${RDKAFKA_VERSION} LANGUAGES C)

# Check for CXX support
include(CheckLanguage)
check_language(CXX)
if(CMAKE_CXX_COMPILER)
enable_language(CXX)
else()
message(STATUS "C++ compiler not found, skipping C++ support")
endif()
Comment on lines +9 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Handle bogus CXX values before calling enable_language

When CXX is preset to something non-working (e.g. our no-C++ workflow exports /bin/false), check_language(CXX) still leaves CMAKE_CXX_COMPILER pointing at that path instead of *-NOTFOUND. The current if (CMAKE_CXX_COMPILER) conditional therefore fires and enable_language(CXX) aborts configuration, defeating the “C-only” fallback we’re trying to enable. Please tighten the guard so we only enable C++ when CMAKE_CXX_COMPILER is both defined and not *-NOTFOUND. One way is:

-check_language(CXX)
-if(CMAKE_CXX_COMPILER)
+check_language(CXX)
+if(CMAKE_CXX_COMPILER AND NOT CMAKE_CXX_COMPILER MATCHES "-NOTFOUND$")
   enable_language(CXX)
 else()
   message(STATUS "C++ compiler not found, skipping C++ support")
 endif()
🤖 Prompt for AI Agents
In lib/librdkafka-2.10.1/CMakeLists.txt around lines 9-15, the current guard
uses if(CMAKE_CXX_COMPILER) which can be true for bogus values like /bin/false
left by check_language(CXX), causing enable_language(CXX) to abort; change the
conditional to only enable C++ when the compiler is both defined and not a
NOTFOUND marker, e.g. use if(DEFINED CMAKE_CXX_COMPILER AND NOT
CMAKE_CXX_COMPILER MATCHES "-NOTFOUND$") then enable_language(CXX) else emit the
existing status message.


set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/packaging/cmake/Modules/")

Expand Down Expand Up @@ -181,7 +190,11 @@ endif()

option(RDKAFKA_BUILD_STATIC "Build static rdkafka library" OFF)
option(RDKAFKA_BUILD_EXAMPLES "Build examples" ON)
option(RDKAFKA_BUILD_TESTS "Build tests" ON)

if(CMAKE_CXX_COMPILER)
option(RDKAFKA_BUILD_TESTS "Build tests" ON)
endif()

if(WIN32)
option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON)
endif(WIN32)
Expand Down Expand Up @@ -279,7 +292,10 @@ install(
)

add_subdirectory(src)
add_subdirectory(src-cpp)

if(CMAKE_CXX_COMPILER)
add_subdirectory(src-cpp)
endif()

if(RDKAFKA_BUILD_EXAMPLES)
add_subdirectory(examples)
Expand Down
31 changes: 20 additions & 11 deletions lib/librdkafka-2.10.1/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@ endif(WIN32)
add_executable(producer producer.c ${win32_sources})
target_link_libraries(producer PUBLIC rdkafka)

add_executable(producer_cpp producer.cpp ${win32_sources})
target_link_libraries(producer_cpp PUBLIC rdkafka++)
if(CMAKE_CXX_COMPILER)
add_executable(producer_cpp producer.cpp ${win32_sources})
target_link_libraries(producer_cpp PUBLIC rdkafka++)
endif()

add_executable(consumer consumer.c ${win32_sources})
target_link_libraries(consumer PUBLIC rdkafka)

add_executable(rdkafka_performance rdkafka_performance.c ${win32_sources})
target_link_libraries(rdkafka_performance PUBLIC rdkafka)

add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources})
target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++)
if(CMAKE_CXX_COMPILER)
add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources})
target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++)
endif()

add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources})
target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++)
if(CMAKE_CXX_COMPILER)
add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources})
target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++)
endif()

add_executable(openssl_engine_example_cpp openssl_engine_example.cpp ${win32_sources})
target_link_libraries(openssl_engine_example_cpp PUBLIC rdkafka++)
if(CMAKE_CXX_COMPILER)
add_executable(openssl_engine_example_cpp openssl_engine_example.cpp ${win32_sources})
target_link_libraries(openssl_engine_example_cpp PUBLIC rdkafka++)
endif()

add_executable(misc misc.c ${win32_sources})
target_link_libraries(misc PUBLIC rdkafka)
Expand Down Expand Up @@ -73,7 +81,8 @@ if(NOT WIN32)
add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c)
target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka)

add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp)
target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++)

if(CMAKE_CXX_COMPILER)
add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp)
target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++)
endif()
endif(NOT WIN32)