Skip to content

Commit 6213cd3

Browse files
committed
Modified message.cpp to use the new feature.
1 parent 77f0ea1 commit 6213cd3

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

CMakeLists.txt

+38-27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ set(CPPKAFKA_VERSION "${CPPKAFKA_VERSION_MAJOR}.${CPPKAFKA_VERSION_MINOR}.${CPPK
1616
set(RDKAFKA_MIN_VERSION "0.9.4")
1717
set(RDKAFKA_MIN_VERSION_HEX 0x00090400)
1818

19+
option(USE_CPP17 "Use C++17 features instead of Boost (still, if you don't have boost you can't build examples" OFF)
20+
1921
if (NOT CMAKE_CXX_FLAGS)
2022
# Set default compile flags for the project
2123
if(MSVC)
@@ -31,8 +33,13 @@ if (NOT CMAKE_CXX_FLAGS)
3133
set(CMAKE_CXX_FLAGS "-Wall")
3234
endif()
3335
endif()
34-
# Use C++17
35-
set(CMAKE_CXX_STANDARD 17)
36+
37+
if(USE_CPP17)
38+
set(CMAKE_CXX_STANDARD 17)
39+
add_definitions("-D_USE_CPP17")
40+
else()
41+
set(CMAKE_CXX_STANDARD 11)
42+
endif()
3643

3744
# Set output directories
3845
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
@@ -104,32 +111,11 @@ if (NOT CPPKAFKA_PKGCONFIG_DIR)
104111
set(CPPKAFKA_PKGCONFIG_DIR share/pkgconfig)
105112
endif()
106113

107-
# Try to find the RdKafka configuration file if present.
108-
# This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified.
109-
find_package(RdKafka ${FIND_PACKAGE_QUIET} CONFIG)
110-
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
111-
if (NOT RdKafka_FOUND)
112-
message(STATUS "RdKafkaConfig.cmake not found. Attempting to find module instead...")
113-
find_package(RdKafka REQUIRED ${FIND_PACKAGE_QUIET} MODULE)
114-
if (NOT RdKafka_FOUND)
115-
message(FATAL_ERROR "RdKafka module not found. Please set RDKAFKA_ROOT to the install path or RDKAFKA_DIR pointing to the RdKafka configuration file location.")
116-
else()
117-
message(STATUS "RdKafka module found.")
118-
endif()
119-
else()
120-
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
121-
endif()
122-
123-
add_subdirectory(src)
124-
add_subdirectory(include/cppkafka)
125-
126-
# Examples target
127-
if (NOT CPPKAFKA_DISABLE_EXAMPLES)
114+
if(NOT USE_CPP17 OR NOT CPPKAFKA_DISABLE_EXAMPLES OR NOT CPPKAFKA_DISABLE_TESTS)
128115
# Look for Boost (just need boost.optional headers here)
129-
find_package(Boost ${FIND_PACKAGE_QUIET} CONFIG)
116+
find_package(Boost REQUIRED ${FIND_PACKAGE_QUIET})
117+
130118
if (Boost_FOUND)
131-
option(CPPKAFKA_BOOST_STATIC_LIBS "Link with Boost static libraries." ON)
132-
option(CPPKAFKA_BOOST_USE_MULTITHREADED "Use Boost multithreaded libraries." ON)
133119
find_package(Boost COMPONENTS program_options ${FIND_PACKAGE_QUIET})
134120
set(Boost_USE_STATIC_LIBS ${CPPKAFKA_BOOST_STATIC_LIBS})
135121
set(Boost_USE_MULTITHREADED ${CPPKAFKA_BOOST_USE_MULTITHREADED})
@@ -142,12 +128,37 @@ if (NOT CPPKAFKA_DISABLE_EXAMPLES)
142128
message(STATUS "Boost is multi-threaded: ${CPPKAFKA_BOOST_USE_MULTITHREADED}")
143129
message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
144130
endif()
131+
endif()
132+
133+
# Examples target
134+
if (Boost_PROGRAM_OPTIONS_FOUND)
145135
add_subdirectory(examples)
146136
else()
147137
message(STATUS "Disabling examples")
148138
endif()
149139
endif()
150140

141+
# Try to find the RdKafka configuration file if present.
142+
# This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified.
143+
find_package(RdKafka ${FIND_PACKAGE_QUIET} CONFIG)
144+
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
145+
if (NOT RdKafka_FOUND)
146+
message(STATUS "RdKafkaConfig.cmake not found. Attempting to find module instead...")
147+
find_package(RdKafka REQUIRED ${FIND_PACKAGE_QUIET} MODULE)
148+
if (NOT RdKafka_FOUND)
149+
message(FATAL_ERROR "RdKafka module not found. Please set RDKAFKA_ROOT to the install path or RDKAFKA_DIR pointing to the RdKafka configuration file location.")
150+
else()
151+
message(STATUS "RdKafka module found.")
152+
endif()
153+
else()
154+
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
155+
endif()
156+
157+
add_subdirectory(src)
158+
add_subdirectory(include/cppkafka)
159+
160+
161+
151162
# Add a target to generate API documentation using Doxygen
152163
find_package(Doxygen ${FIND_PACKAGE_QUIET})
153164
if(DOXYGEN_FOUND)
@@ -188,4 +199,4 @@ if(NOT TARGET uninstall)
188199
# Add uninstall target
189200
add_custom_target(uninstall
190201
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
191-
endif()
202+
endif()

include/cppkafka/cppkafka.h

+2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@
5757
#include <cppkafka/topic_configuration.h>
5858
#include <cppkafka/topic_partition.h>
5959
#include <cppkafka/topic_partition_list.h>
60+
#include <cppkafka/utils/any.h>
6061
#include <cppkafka/utils/backoff_committer.h>
6162
#include <cppkafka/utils/backoff_performer.h>
6263
#include <cppkafka/utils/buffered_producer.h>
6364
#include <cppkafka/utils/compacted_topic_processor.h>
6465
#include <cppkafka/utils/consumer_dispatcher.h>
66+
#include <cppkafka/utils/optional.h>
6567
#include <cppkafka/utils/poll_interface.h>
6668
#include <cppkafka/utils/poll_strategy_base.h>
6769
#include <cppkafka/utils/roundrobin_poll_strategy.h>

include/cppkafka/message.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <cstdint>
3535
#include <chrono>
3636
#include <cassert>
37-
#include <optional>
37+
#include "utils/optional.h"
3838
#include <librdkafka/rdkafka.h>
3939
#include "buffer.h"
4040
#include "macros.h"
@@ -189,7 +189,7 @@ class CPPKAFKA_API Message {
189189
*
190190
* If calling rd_kafka_message_timestamp returns -1, then boost::none_t will be returned.
191191
*/
192-
std::optional<MessageTimestamp> get_timestamp() const;
192+
optional<MessageTimestamp> get_timestamp() const;
193193

194194
#if RD_KAFKA_VERSION >= RD_KAFKA_MESSAGE_LATENCY_SUPPORT_VERSION
195195
/**

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES
4949
# In CMake >= 3.15 Boost::boost == Boost::headers
5050
target_link_libraries(${TARGET_NAME} PUBLIC RdKafka::rdkafka)
5151

52-
if(NOT CPPKAFKA_DISABLE_EXAMPLES)
52+
if(NOT USE_CPP17 OR NOT CPPKAFKA_DISABLE_EXAMPLES OR NOT CPPKAFKA_DISABLE_TESTS)
5353
target_link_libraries(${TARGET_NAME} PUBLIC Boost::boost)
5454
endif()
5555

src/message.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Message& Message::load_internal() {
8484
return *this;
8585
}
8686

87-
std::optional<MessageTimestamp> Message::get_timestamp() const {
87+
optional<MessageTimestamp> Message::get_timestamp() const {
8888
rd_kafka_timestamp_type_t type = RD_KAFKA_TIMESTAMP_NOT_AVAILABLE;
8989
int64_t timestamp = rd_kafka_message_timestamp(handle_.get(), &type);
9090
if (timestamp == -1 || type == RD_KAFKA_TIMESTAMP_NOT_AVAILABLE) {

0 commit comments

Comments
 (0)