Skip to content

Commit

Permalink
Modified message.cpp to use the new feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSharpOwl committed Aug 10, 2021
1 parent 77f0ea1 commit 6213cd3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 31 deletions.
65 changes: 38 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ set(CPPKAFKA_VERSION "${CPPKAFKA_VERSION_MAJOR}.${CPPKAFKA_VERSION_MINOR}.${CPPK
set(RDKAFKA_MIN_VERSION "0.9.4")
set(RDKAFKA_MIN_VERSION_HEX 0x00090400)

option(USE_CPP17 "Use C++17 features instead of Boost (still, if you don't have boost you can't build examples" OFF)

if (NOT CMAKE_CXX_FLAGS)
# Set default compile flags for the project
if(MSVC)
Expand All @@ -31,8 +33,13 @@ if (NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "-Wall")
endif()
endif()
# Use C++17
set(CMAKE_CXX_STANDARD 17)

if(USE_CPP17)
set(CMAKE_CXX_STANDARD 17)
add_definitions("-D_USE_CPP17")
else()
set(CMAKE_CXX_STANDARD 11)
endif()

# Set output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
Expand Down Expand Up @@ -104,32 +111,11 @@ if (NOT CPPKAFKA_PKGCONFIG_DIR)
set(CPPKAFKA_PKGCONFIG_DIR share/pkgconfig)
endif()

# Try to find the RdKafka configuration file if present.
# This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified.
find_package(RdKafka ${FIND_PACKAGE_QUIET} CONFIG)
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
if (NOT RdKafka_FOUND)
message(STATUS "RdKafkaConfig.cmake not found. Attempting to find module instead...")
find_package(RdKafka REQUIRED ${FIND_PACKAGE_QUIET} MODULE)
if (NOT RdKafka_FOUND)
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.")
else()
message(STATUS "RdKafka module found.")
endif()
else()
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
endif()

add_subdirectory(src)
add_subdirectory(include/cppkafka)

# Examples target
if (NOT CPPKAFKA_DISABLE_EXAMPLES)
if(NOT USE_CPP17 OR NOT CPPKAFKA_DISABLE_EXAMPLES OR NOT CPPKAFKA_DISABLE_TESTS)
# Look for Boost (just need boost.optional headers here)
find_package(Boost ${FIND_PACKAGE_QUIET} CONFIG)
find_package(Boost REQUIRED ${FIND_PACKAGE_QUIET})

if (Boost_FOUND)
option(CPPKAFKA_BOOST_STATIC_LIBS "Link with Boost static libraries." ON)
option(CPPKAFKA_BOOST_USE_MULTITHREADED "Use Boost multithreaded libraries." ON)
find_package(Boost COMPONENTS program_options ${FIND_PACKAGE_QUIET})
set(Boost_USE_STATIC_LIBS ${CPPKAFKA_BOOST_STATIC_LIBS})
set(Boost_USE_MULTITHREADED ${CPPKAFKA_BOOST_USE_MULTITHREADED})
Expand All @@ -142,12 +128,37 @@ if (NOT CPPKAFKA_DISABLE_EXAMPLES)
message(STATUS "Boost is multi-threaded: ${CPPKAFKA_BOOST_USE_MULTITHREADED}")
message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
endif()
endif()

# Examples target
if (Boost_PROGRAM_OPTIONS_FOUND)
add_subdirectory(examples)
else()
message(STATUS "Disabling examples")
endif()
endif()

# Try to find the RdKafka configuration file if present.
# This will search default system locations as well as RdKafka_ROOT and RdKafka_Dir paths if specified.
find_package(RdKafka ${FIND_PACKAGE_QUIET} CONFIG)
set(RDKAFKA_TARGET_IMPORTS ${RdKafka_FOUND})
if (NOT RdKafka_FOUND)
message(STATUS "RdKafkaConfig.cmake not found. Attempting to find module instead...")
find_package(RdKafka REQUIRED ${FIND_PACKAGE_QUIET} MODULE)
if (NOT RdKafka_FOUND)
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.")
else()
message(STATUS "RdKafka module found.")
endif()
else()
message(STATUS "RdKafka configuration file found: ${RdKafka_CONFIG}")
endif()

add_subdirectory(src)
add_subdirectory(include/cppkafka)



# Add a target to generate API documentation using Doxygen
find_package(Doxygen ${FIND_PACKAGE_QUIET})
if(DOXYGEN_FOUND)
Expand Down Expand Up @@ -188,4 +199,4 @@ if(NOT TARGET uninstall)
# Add uninstall target
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
endif()
2 changes: 2 additions & 0 deletions include/cppkafka/cppkafka.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@
#include <cppkafka/topic_configuration.h>
#include <cppkafka/topic_partition.h>
#include <cppkafka/topic_partition_list.h>
#include <cppkafka/utils/any.h>
#include <cppkafka/utils/backoff_committer.h>
#include <cppkafka/utils/backoff_performer.h>
#include <cppkafka/utils/buffered_producer.h>
#include <cppkafka/utils/compacted_topic_processor.h>
#include <cppkafka/utils/consumer_dispatcher.h>
#include <cppkafka/utils/optional.h>
#include <cppkafka/utils/poll_interface.h>
#include <cppkafka/utils/poll_strategy_base.h>
#include <cppkafka/utils/roundrobin_poll_strategy.h>
Expand Down
4 changes: 2 additions & 2 deletions include/cppkafka/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <cstdint>
#include <chrono>
#include <cassert>
#include <optional>
#include "utils/optional.h"
#include <librdkafka/rdkafka.h>
#include "buffer.h"
#include "macros.h"
Expand Down Expand Up @@ -189,7 +189,7 @@ class CPPKAFKA_API Message {
*
* If calling rd_kafka_message_timestamp returns -1, then boost::none_t will be returned.
*/
std::optional<MessageTimestamp> get_timestamp() const;
optional<MessageTimestamp> get_timestamp() const;

#if RD_KAFKA_VERSION >= RD_KAFKA_MESSAGE_LATENCY_SUPPORT_VERSION
/**
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ set_target_properties(${TARGET_NAME} PROPERTIES
# In CMake >= 3.15 Boost::boost == Boost::headers
target_link_libraries(${TARGET_NAME} PUBLIC RdKafka::rdkafka)

if(NOT CPPKAFKA_DISABLE_EXAMPLES)
if(NOT USE_CPP17 OR NOT CPPKAFKA_DISABLE_EXAMPLES OR NOT CPPKAFKA_DISABLE_TESTS)
target_link_libraries(${TARGET_NAME} PUBLIC Boost::boost)
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Message& Message::load_internal() {
return *this;
}

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

0 comments on commit 6213cd3

Please sign in to comment.