Skip to content

Commit b6eddbc

Browse files
lib: librdkafka: CMakeLists.txt: allow compilation without CXX support fluent#7741
e.g. fluent-bit is a c-only library, so allow compilation without cxx Upstream: confluentinc/librdkafka#4366 Signed-off-by: Thomas Devoogdt <[email protected]>
1 parent 600b5a9 commit b6eddbc

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

lib/librdkafka-2.4.0/CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ cmake_minimum_required(VERSION 3.2)
33
include("packaging/cmake/parseversion.cmake")
44
parseversion("src/rdkafka.h")
55

6-
project(RdKafka VERSION ${RDKAFKA_VERSION})
6+
project(RdKafka VERSION ${RDKAFKA_VERSION} LANGUAGES C)
7+
8+
option(RDKAFKA_BUILD_CXX "Enable CXX support" ON)
9+
if(RDKAFKA_BUILD_CXX)
10+
enable_language(CXX)
11+
endif()
712

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

@@ -181,7 +186,11 @@ endif()
181186

182187
option(RDKAFKA_BUILD_STATIC "Build static rdkafka library" OFF)
183188
option(RDKAFKA_BUILD_EXAMPLES "Build examples" ON)
184-
option(RDKAFKA_BUILD_TESTS "Build tests" ON)
189+
190+
if(RDKAFKA_BUILD_CXX)
191+
option(RDKAFKA_BUILD_TESTS "Build tests" ON)
192+
endif()
193+
185194
if(WIN32)
186195
option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON)
187196
endif(WIN32)
@@ -279,7 +288,10 @@ install(
279288
)
280289

281290
add_subdirectory(src)
282-
add_subdirectory(src-cpp)
291+
292+
if(RDKAFKA_BUILD_CXX)
293+
add_subdirectory(src-cpp)
294+
endif()
283295

284296
if(RDKAFKA_BUILD_EXAMPLES)
285297
add_subdirectory(examples)

lib/librdkafka-2.4.0/examples/CMakeLists.txt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,31 @@ endif(WIN32)
55
add_executable(producer producer.c ${win32_sources})
66
target_link_libraries(producer PUBLIC rdkafka)
77

8-
add_executable(producer_cpp producer.cpp ${win32_sources})
9-
target_link_libraries(producer_cpp PUBLIC rdkafka++)
8+
if(RDKAFKA_BUILD_CXX)
9+
add_executable(producer_cpp producer.cpp ${win32_sources})
10+
target_link_libraries(producer_cpp PUBLIC rdkafka++)
11+
endif()
1012

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

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

17-
add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources})
18-
target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++)
19+
if(RDKAFKA_BUILD_CXX)
20+
add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources})
21+
target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++)
22+
endif()
1923

20-
add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources})
21-
target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++)
24+
if(RDKAFKA_BUILD_CXX)
25+
add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources})
26+
target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++)
27+
endif()
2228

23-
add_executable(openssl_engine_example_cpp openssl_engine_example.cpp ${win32_sources})
24-
target_link_libraries(openssl_engine_example_cpp PUBLIC rdkafka++)
29+
if(RDKAFKA_BUILD_CXX)
30+
add_executable(openssl_engine_example_cpp openssl_engine_example.cpp ${win32_sources})
31+
target_link_libraries(openssl_engine_example_cpp PUBLIC rdkafka++)
32+
endif()
2533

2634
add_executable(misc misc.c ${win32_sources})
2735
target_link_libraries(misc PUBLIC rdkafka)
@@ -70,7 +78,8 @@ if(NOT WIN32)
7078
add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c)
7179
target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka)
7280

73-
add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp)
74-
target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++)
75-
81+
if(RDKAFKA_BUILD_CXX)
82+
add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp)
83+
target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++)
84+
endif()
7685
endif(NOT WIN32)

0 commit comments

Comments
 (0)