Skip to content

Commit 7576aa6

Browse files
CMakeLists.txt: allow compilation without CXX support #4364
e.g. fluent-bit is a c-only library, so allow compilation without cxx Signed-off-by: Thomas Devoogdt <[email protected]>
1 parent 8c83a55 commit 7576aa6

File tree

4 files changed

+142
-50
lines changed

4 files changed

+142
-50
lines changed

CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ cmake_minimum_required(VERSION 3.5)
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+
# Check for CXX support
9+
include(CheckLanguage)
10+
check_language(CXX)
11+
if(CMAKE_CXX_COMPILER)
12+
enable_language(CXX)
13+
else()
14+
message(STATUS "C++ compiler not found, skipping C++ support")
15+
endif()
716

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

@@ -279,7 +288,10 @@ install(
279288
)
280289

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

284296
if(RDKAFKA_BUILD_EXAMPLES)
285297
add_subdirectory(examples)

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(CMAKE_CXX_COMPILER)
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(CMAKE_CXX_COMPILER)
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(CMAKE_CXX_COMPILER)
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(CMAKE_CXX_COMPILER)
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)
@@ -73,7 +81,8 @@ if(NOT WIN32)
7381
add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c)
7482
target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka)
7583

76-
add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp)
77-
target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++)
78-
84+
if(CMAKE_CXX_COMPILER)
85+
add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp)
86+
target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++)
87+
endif()
7988
endif(NOT WIN32)

tests/CMakeLists.txt

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,22 @@ set(
4848
0050-subscribe_adds.c
4949
0051-assign_adds.c
5050
0052-msg_timestamps.c
51-
0053-stats_cb.cpp
52-
0054-offset_time.cpp
5351
0055-producer_latency.c
5452
0056-balanced_group_mt.c
55-
0057-invalid_topic.cpp
56-
0058-log.cpp
57-
0059-bsearch.cpp
58-
0060-op_prio.cpp
59-
0061-consumer_lag.cpp
60-
0062-stats_event.c
61-
0063-clusterid.cpp
6253
0064-interceptors.c
63-
0065-yield.cpp
64-
0066-plugins.cpp
65-
0067-empty_topic.cpp
6654
0068-produce_timeout.c
6755
0069-consumer_add_parts.c
68-
0070-null_empty.cpp
6956
0072-headers_ut.c
7057
0073-headers.c
7158
0074-producev.c
7259
0075-retry.c
7360
0076-produce_retry.c
7461
0077-compaction.c
75-
0078-c_from_cpp.cpp
7662
0079-fork.c
7763
0080-admin_ut.c
7864
0081-admin.c
79-
0082-fetch_max_bytes.cpp
8065
0083-cb_event.c
8166
0084-destroy_flags.c
82-
0085-headers.cpp
8367
0086-purge.c
8468
0088-produce_metadata_timeout.c
8569
0089-max_poll_interval.c
@@ -88,50 +72,32 @@ set(
8872
0092-mixed_msgver.c
8973
0093-holb.c
9074
0094-idempotence_msg_timeout.c
91-
0095-all_brokers_down.cpp
92-
0097-ssl_verify.cpp
93-
0098-consumer-txn.cpp
94-
0099-commit_metadata.c
95-
0100-thread_interceptors.cpp
96-
0101-fetch-from-follower.cpp
9775
0102-static_group_rebalance.c
9876
0103-transactions.c
9977
0104-fetch_from_follower_mock.c
10078
0105-transactions_mock.c
10179
0106-cgrp_sess_timeout.c
10280
0107-topic_recreate.c
103-
0109-auto_create_topics.cpp
104-
0110-batch_size.cpp
105-
0111-delay_create_topics.cpp
10681
0112-assign_unknown_part.c
107-
0113-cooperative_rebalance.cpp
108-
0114-sticky_partitioning.cpp
109-
0115-producer_auth.cpp
110-
0116-kafkaconsumer_close.cpp
11182
0117-mock_errors.c
11283
0118-commit_rebalance.c
113-
0119-consumer_auth.cpp
11484
0120-asymmetric_subscription.c
11585
0121-clusterid.c
11686
0122-buffer_cleaning_after_rebalance.c
11787
0123-connections_max_idle.c
11888
0124-openssl_invalid_engine.c
11989
0125-immediate_flush.c
12090
0126-oauthbearer_oidc.c
121-
0127-fetch_queue_backoff.cpp
122-
0128-sasl_callback_queue.cpp
12391
0129-fetch_aborted_msgs.c
12492
0130-store_offsets.c
12593
0131-connect_timeout.c
12694
0132-strategy_ordering.c
12795
0133-ssl_keys.c
12896
0134-ssl_provider.c
129-
0135-sasl_credentials.cpp
13097
0136-resolve_cb.c
13198
0137-barrier_batch_consume.c
13299
0138-admin_mock.c
133100
0139-offset_validation_mock.c
134-
0140-commit_metadata.cpp
135101
0142-reauthentication.c
136102
0143-exponential_backoff_mock.c
137103
0144-idempotence_mock.c
@@ -144,21 +110,66 @@ set(
144110
0151-purge-brokers.c
145111
0152-rebootstrap.c
146112
0153-memberid.c
147-
8000-idle.cpp
148113
8001-fetch_from_follower_mock_manual.c
149114
test.c
150-
testcpp.cpp
151115
rusage.c
152116
)
153117

118+
if(CMAKE_CXX_COMPILER)
119+
add_compile_definitions(_CXX=1)
120+
list(APPEND sources
121+
0053-stats_cb.cpp
122+
0054-offset_time.cpp
123+
0057-invalid_topic.cpp
124+
0058-log.cpp
125+
0059-bsearch.cpp
126+
0060-op_prio.cpp
127+
0061-consumer_lag.cpp
128+
0062-stats_event.c
129+
0063-clusterid.cpp
130+
0065-yield.cpp
131+
0066-plugins.cpp
132+
0067-empty_topic.cpp
133+
0070-null_empty.cpp
134+
0078-c_from_cpp.cpp
135+
0082-fetch_max_bytes.cpp
136+
0085-headers.cpp
137+
0095-all_brokers_down.cpp
138+
0097-ssl_verify.cpp
139+
0098-consumer-txn.cpp
140+
0099-commit_metadata.c
141+
0100-thread_interceptors.cpp
142+
0101-fetch-from-follower.cpp
143+
0109-auto_create_topics.cpp
144+
0110-batch_size.cpp
145+
0111-delay_create_topics.cpp
146+
0113-cooperative_rebalance.cpp
147+
0114-sticky_partitioning.cpp
148+
0115-producer_auth.cpp
149+
0116-kafkaconsumer_close.cpp
150+
0119-consumer_auth.cpp
151+
0127-fetch_queue_backoff.cpp
152+
0128-sasl_callback_queue.cpp
153+
0135-sasl_credentials.cpp
154+
0140-commit_metadata.cpp
155+
8000-idle.cpp
156+
testcpp.cpp
157+
)
158+
endif()
159+
154160
if(NOT WIN32)
155161
list(APPEND sources sockem.c sockem_ctrl.c)
156162
else()
157163
list(APPEND sources ../src/tinycthread.c ../src/tinycthread_extra.c)
158164
endif()
159165

160166
add_executable(test-runner ${sources})
161-
target_link_libraries(test-runner PUBLIC rdkafka++)
167+
168+
if(CMAKE_CXX_COMPILER)
169+
target_link_libraries(test-runner PUBLIC rdkafka++)
170+
else()
171+
target_link_libraries(test-runner PUBLIC rdkafka)
172+
endif()
162173

163174
add_test(NAME RdKafkaTestInParallel COMMAND test-runner -p5)
164175
add_test(NAME RdKafkaTestSequentially COMMAND test-runner -p1)

0 commit comments

Comments
 (0)