11include_directories (${CMAKE_CURRENT_SOURCE_DIR} /../include /)
22include_directories (SYSTEM ${CATCH_INCLUDE} )
33
4- set (KAFKA_TEST_INSTANCE "kafka-vm:9092"
4+ if (NOT KAFKA_TEST_INSTANCE)
5+ set (KAFKA_TEST_INSTANCE kafka-vm:9092
56 CACHE STRING "The kafka instance to which to connect to run tests" )
7+ endif ()
8+ if (NOT KAFKA_NUM_PARTITIONS)
9+ set (KAFKA_NUM_PARTITIONS 3 CACHE STRING "Kafka Number of partitions" )
10+ endif ()
11+ if (NOT KAFKA_TOPICS)
12+ set (KAFKA_TOPICS "cppkafka_test1;cppkafka_test2" CACHE STRING "Kafka topics" )
13+ endif ()
14+
15+ # Convert list of topics into a C++ initializer list
16+ FOREACH (TOPIC ${KAFKA_TOPICS} )
17+ if (NOT TOPIC_LIST)
18+ set (TOPIC_LIST "\" ${TOPIC} \" " )
19+ else ()
20+ set (TOPIC_LIST "${TOPIC_LIST} ,\" ${TOPIC} \" " )
21+ endif ()
22+ ENDFOREACH ()
23+
624add_custom_target (tests)
725
826include_directories (${CMAKE_CURRENT_SOURCE_DIR} )
9- add_definitions ("-DKAFKA_TEST_INSTANCE=\" ${KAFKA_TEST_INSTANCE} \" " )
27+ add_definitions (
28+ "-DKAFKA_TEST_INSTANCE=\" ${KAFKA_TEST_INSTANCE} \" "
29+ -DKAFKA_NUM_PARTITIONS=${KAFKA_NUM_PARTITIONS}
30+ -DKAFKA_TOPIC_NAMES=${TOPIC_LIST}
31+ )
1032
1133add_executable (cppkafka_tests
1234 buffer_test.cpp
@@ -25,6 +47,6 @@ add_executable(cppkafka_tests
2547)
2648
2749# In CMake >= 3.15 Boost::boost == Boost::headers
28- target_link_libraries (cppkafka_tests cppkafka RdKafka::rdkafka Boost::boost Boost::program_options )
50+ target_link_libraries (cppkafka_tests cppkafka RdKafka::rdkafka Boost::boost Boost::program_options)
2951add_dependencies (tests cppkafka_tests)
3052add_test (cppkafka cppkafka_tests)
0 commit comments