From 9e5d71ed8cc5f0f45c5b38b76410598e6c2724f2 Mon Sep 17 00:00:00 2001 From: Matthew D Jones Date: Wed, 29 May 2019 09:44:25 +0100 Subject: [PATCH 01/12] Define target for asio and use the one now provided by the json library --- cmake/FindASIO.cmake | 11 +++++++++++ cmake/GraylogLoggerConfig.cmake.in | 6 +++++- src/CMakeLists.txt | 8 ++++++-- unit_tests/CMakeLists.txt | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmake/FindASIO.cmake b/cmake/FindASIO.cmake index b6d0559..4ee4b5b 100644 --- a/cmake/FindASIO.cmake +++ b/cmake/FindASIO.cmake @@ -18,3 +18,14 @@ mark_as_advanced( ASIO_ROOT_DIR ASIO_INCLUDE_DIR ) + +if(ASIO_FOUND) + set(ASIO_INCLUDE_DIRS ${ASIO_INCLUDE_DIR}) +endif() + +if(ASIO_FOUND AND NOT TARGET ASIO::ASIO) + add_library(ASIO::ASIO INTERFACE IMPORTED) + set_target_properties(ASIO::ASIO PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${ASIO_INCLUDE_DIR}" + ) +endif() diff --git a/cmake/GraylogLoggerConfig.cmake.in b/cmake/GraylogLoggerConfig.cmake.in index 5f98ef3..aecd48e 100644 --- a/cmake/GraylogLoggerConfig.cmake.in +++ b/cmake/GraylogLoggerConfig.cmake.in @@ -1,8 +1,12 @@ get_filename_component(GraylogLogger_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) include(CMakeFindDependencyMacro) +find_dependency(ASIO REQUIRED MODULE) +find_dependency(Threads REQUIRED) +find_dependency(nlohmann_json REQUIRED) + if(NOT TARGET GraylogLogger::graylog_logger) include("${GraylogLogger_CMAKE_DIR}/GraylogLoggerTargets.cmake") endif() -set(GraylogLogger_LIBRARIES GraylogLogger::graylog_logger) \ No newline at end of file +set(GraylogLogger_LIBRARIES GraylogLogger::graylog_logger) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d5112ef..2a368fd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,6 @@ find_package(Threads REQUIRED) +find_package(ASIO REQUIRED MODULE) +find_package(nlohmann_json REQUIRED) set(Graylog_SRC ConsoleInterface.cpp @@ -25,9 +27,11 @@ set(Graylog_INC ) set(common_libs + PUBLIC Threads::Threads - CONAN_PKG::asio - CONAN_PKG::jsonformoderncpp) + ASIO::ASIO + PRIVATE + nlohmann_json::nlohmann_json) add_library(graylog_logger SHARED ${Graylog_SRC} ${Graylog_INC}) add_library(GraylogLogger::graylog_logger ALIAS graylog_logger) diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 875bd8d..a9bff83 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -29,6 +29,7 @@ add_executable(unit_tests ${UnitTest_SRC} ${UnitTest_INC}) target_link_libraries(unit_tests GraylogLogger::graylog_logger_static + CONAN_PKG::jsonformoderncpp CONAN_PKG::gtest) add_test(TestAll unit_tests) From ba7cbb64dd96aa6a2e9be539aae16fdf2e446d62 Mon Sep 17 00:00:00 2001 From: Matthew D Jones Date: Wed, 29 May 2019 10:18:27 +0100 Subject: [PATCH 02/12] Use DIRECTORY rather than legacy PATH option in get_filename_component --- cmake/GraylogLoggerConfig.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/GraylogLoggerConfig.cmake.in b/cmake/GraylogLoggerConfig.cmake.in index aecd48e..050041e 100644 --- a/cmake/GraylogLoggerConfig.cmake.in +++ b/cmake/GraylogLoggerConfig.cmake.in @@ -1,4 +1,4 @@ -get_filename_component(GraylogLogger_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +get_filename_component(GraylogLogger_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) include(CMakeFindDependencyMacro) find_dependency(ASIO REQUIRED MODULE) From 10845e2a7fd7da318fe8613202771cdec5cd8933 Mon Sep 17 00:00:00 2001 From: Matthew D Jones Date: Wed, 29 May 2019 10:25:37 +0100 Subject: [PATCH 03/12] Include ASIO find module --- cmake/GraylogLoggerConfig.cmake.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/GraylogLoggerConfig.cmake.in b/cmake/GraylogLoggerConfig.cmake.in index 050041e..8256f89 100644 --- a/cmake/GraylogLoggerConfig.cmake.in +++ b/cmake/GraylogLoggerConfig.cmake.in @@ -1,6 +1,13 @@ get_filename_component(GraylogLogger_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) include(CMakeFindDependencyMacro) +install(FILES + FindASIO.cmake + DESTINATION + lib/cmake/GraylogLogger/cmake + ) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/") + find_dependency(ASIO REQUIRED MODULE) find_dependency(Threads REQUIRED) find_dependency(nlohmann_json REQUIRED) From d26a43de28fd6885dfa980c0b272c3898d3ad5b4 Mon Sep 17 00:00:00 2001 From: Matthew D Jones Date: Wed, 29 May 2019 10:29:00 +0100 Subject: [PATCH 04/12] Include ASIO find module --- cmake/GraylogLoggerConfig.cmake.in | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmake/GraylogLoggerConfig.cmake.in b/cmake/GraylogLoggerConfig.cmake.in index 8256f89..421f56c 100644 --- a/cmake/GraylogLoggerConfig.cmake.in +++ b/cmake/GraylogLoggerConfig.cmake.in @@ -1,12 +1,7 @@ get_filename_component(GraylogLogger_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY) include(CMakeFindDependencyMacro) -install(FILES - FindASIO.cmake - DESTINATION - lib/cmake/GraylogLogger/cmake - ) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/../cmake/") find_dependency(ASIO REQUIRED MODULE) find_dependency(Threads REQUIRED) From 14697267c541d0ca2076f45b925438fc2694ac2e Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Fri, 31 May 2019 02:10:51 +0200 Subject: [PATCH 05/12] Pimpl implementation for GraylogConnection. --- conanfile.txt | 2 +- include/graylog_logger/ConnectionStatus.hpp | 18 ++++++++ include/graylog_logger/GraylogInterface.hpp | 19 +++++++-- src/CMakeLists.txt | 4 +- src/GraylogConnection.cpp | 42 ++++++++++--------- .../GraylogConnection.hpp | 19 ++++----- src/GraylogInterface.cpp | 32 ++++++++++---- 7 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 include/graylog_logger/ConnectionStatus.hpp rename {include/graylog_logger => src}/GraylogConnection.hpp (83%) diff --git a/conanfile.txt b/conanfile.txt index 332ac05..08de515 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -4,7 +4,7 @@ asio/1.13.0@bincrafters/stable jsonformoderncpp/3.6.1@vthiery/stable [options] -gtest:shared=True +gtest:shared=False [generators] cmake diff --git a/include/graylog_logger/ConnectionStatus.hpp b/include/graylog_logger/ConnectionStatus.hpp new file mode 100644 index 0000000..b1c4f30 --- /dev/null +++ b/include/graylog_logger/ConnectionStatus.hpp @@ -0,0 +1,18 @@ +/* Copyright (C) 2019 European Spallation Source, ERIC. See LICENSE file */ +//===----------------------------------------------------------------------===// +/// +/// \file +/// +/// \brief Graylog connection status. +/// +//===----------------------------------------------------------------------===// +#pragma once + +namespace Log { +enum class Status { + ADDR_LOOKUP, + ADDR_RETRY_WAIT, + CONNECT, + SEND_LOOP, +}; +} // namespace Log diff --git a/include/graylog_logger/GraylogInterface.hpp b/include/graylog_logger/GraylogInterface.hpp index d96a8a3..7c30ae7 100644 --- a/include/graylog_logger/GraylogInterface.hpp +++ b/include/graylog_logger/GraylogInterface.hpp @@ -9,12 +9,25 @@ #pragma once -#include "graylog_logger/GraylogConnection.hpp" +#include "graylog_logger/ConnectionStatus.hpp" #include "graylog_logger/LogUtil.hpp" namespace Log { +class GraylogConnection { +public: + using Status = Log::Status; + GraylogConnection(std::string Host, int Port); + virtual ~GraylogConnection(); + virtual void sendMessage(std::string Msg); + virtual Status getConnectionStatus() const; + virtual bool messageQueueEmpty(); + virtual size_t messageQueueSize(); -class GraylogInterface : public BaseLogHandler, private GraylogConnection { +private: + class Impl; + std::unique_ptr Pimpl; +}; +class GraylogInterface : public BaseLogHandler, public GraylogConnection { public: GraylogInterface(const std::string &Host, int Port, size_t MaxQueueLength = 100); @@ -22,8 +35,6 @@ class GraylogInterface : public BaseLogHandler, private GraylogConnection { void addMessage(const LogMessage &Message) override; bool emptyQueue() override; size_t queueSize() override; - using GraylogConnection::Status; - using GraylogConnection::getConnectionStatus; protected: std::string logMsgToJSON(const LogMessage &Message); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a368fd..983392c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,14 +17,14 @@ set(Graylog_INC ../include/graylog_logger/ConcurrentQueue.hpp ../include/graylog_logger/ConsoleInterface.hpp ../include/graylog_logger/FileInterface.hpp - ../include/graylog_logger/GraylogConnection.hpp + GraylogConnection.hpp ../include/graylog_logger/GraylogInterface.hpp ../include/graylog_logger/Log.hpp ../include/graylog_logger/Logger.hpp ../include/graylog_logger/LoggingBase.hpp ../include/graylog_logger/LogUtil.hpp ../include/graylog_logger/ThreadedExecutor.hpp -) + ../include/graylog_logger/ConnectionStatus.hpp) set(common_libs PUBLIC diff --git a/src/GraylogConnection.cpp b/src/GraylogConnection.cpp index 1294a53..52a5c21 100644 --- a/src/GraylogConnection.cpp +++ b/src/GraylogConnection.cpp @@ -8,14 +8,14 @@ /// //===----------------------------------------------------------------------===// -#include "graylog_logger/GraylogConnection.hpp" +#include "GraylogConnection.hpp" #include #include #include namespace { #define UNUSED_ARG(x) (void)x; -} +} // namespace namespace Log { @@ -46,7 +46,7 @@ struct QueryResult { int NextEndpoint{0}; }; -void GraylogConnection::tryConnect(QueryResult AllEndpoints) { +void GraylogConnection::Impl::tryConnect(QueryResult AllEndpoints) { asio::ip::tcp::endpoint CurrentEndpoint = AllEndpoints.getNextEndpoint(); auto HandlerGlue = [this, AllEndpoints](auto &Err) { this->connectHandler(Err, AllEndpoints); @@ -55,15 +55,15 @@ void GraylogConnection::tryConnect(QueryResult AllEndpoints) { setState(Status::CONNECT); } -GraylogConnection::GraylogConnection(std::string Host, int Port) +GraylogConnection::Impl::Impl(std::string Host, int Port) : HostAddress(std::move(Host)), HostPort(std::to_string(Port)), Service(), Work(std::make_unique(Service)), Socket(Service), Resolver(Service), ReconnectTimeout(Service, 10s) { doAddressQuery(); - AsioThread = std::thread(&GraylogConnection::threadFunction, this); + AsioThread = std::thread(&GraylogConnection::Impl::threadFunction, this); } -void GraylogConnection::resolverHandler( +void GraylogConnection::Impl::resolverHandler( const asio::error_code &Error, asio::ip::tcp::resolver::iterator EndpointIter) { if (Error) { @@ -75,8 +75,8 @@ void GraylogConnection::resolverHandler( tryConnect(AllEndpoints); } -void GraylogConnection::connectHandler(const asio::error_code &Error, - const QueryResult &AllEndpoints) { +void GraylogConnection::Impl::connectHandler(const asio::error_code &Error, + const QueryResult &AllEndpoints) { if (!Error) { setState(Status::SEND_LOOP); auto HandlerGlue = [this](auto &Error, auto Size) { @@ -94,7 +94,7 @@ void GraylogConnection::connectHandler(const asio::error_code &Error, tryConnect(AllEndpoints); } -void GraylogConnection::reConnect(ReconnectDelay Delay) { +void GraylogConnection::Impl::reConnect(ReconnectDelay Delay) { auto HandlerGlue = [this](auto &Err) { this->doAddressQuery(); }; switch (Delay) { case ReconnectDelay::SHORT: @@ -109,8 +109,8 @@ void GraylogConnection::reConnect(ReconnectDelay Delay) { setState(Status::ADDR_RETRY_WAIT); } -void GraylogConnection::receiveHandler(const asio::error_code &Error, - std::size_t BytesReceived) { +void GraylogConnection::Impl::receiveHandler(const asio::error_code &Error, + std::size_t BytesReceived) { UNUSED_ARG(BytesReceived); if (Error) { Socket.close(); @@ -123,7 +123,7 @@ void GraylogConnection::receiveHandler(const asio::error_code &Error, Socket.async_receive(asio::buffer(InputBuffer), HandlerGlue); } -void GraylogConnection::trySendMessage() { +void GraylogConnection::Impl::trySendMessage() { if (not Socket.is_open()) { return; } @@ -149,8 +149,8 @@ void GraylogConnection::trySendMessage() { } } -void GraylogConnection::sentMessageHandler(const asio::error_code &Error, - std::size_t BytesSent) { +void GraylogConnection::Impl::sentMessageHandler(const asio::error_code &Error, + std::size_t BytesSent) { if (BytesSent == MessageBuffer.size()) { MessageBuffer.clear(); } else if (BytesSent > 0) { @@ -166,7 +166,7 @@ void GraylogConnection::sentMessageHandler(const asio::error_code &Error, trySendMessage(); } -void GraylogConnection::waitForMessage() { +void GraylogConnection::Impl::waitForMessage() { if (not Socket.is_open()) { return; } @@ -179,7 +179,7 @@ void GraylogConnection::waitForMessage() { Service.post([this]() { this->waitForMessage(); }); } -void GraylogConnection::doAddressQuery() { +void GraylogConnection::Impl::doAddressQuery() { setState(Status::ADDR_LOOKUP); asio::ip::tcp::resolver::query Query(HostAddress, HostPort); auto HandlerGlue = [this](auto &Error, auto EndpointIter) { @@ -188,7 +188,7 @@ void GraylogConnection::doAddressQuery() { Resolver.async_resolve(Query, HandlerGlue); } -GraylogConnection::~GraylogConnection() { +GraylogConnection::Impl::~Impl() { Service.stop(); AsioThread.join(); try { @@ -198,13 +198,15 @@ GraylogConnection::~GraylogConnection() { } } -GraylogConnection::Status GraylogConnection::getConnectionStatus() const { +GraylogConnection::Impl::Status +GraylogConnection::Impl::getConnectionStatus() const { return ConnectionState; } -void GraylogConnection::threadFunction() { Service.run(); } +void GraylogConnection::Impl::threadFunction() { Service.run(); } -void GraylogConnection::setState(GraylogConnection::Status NewState) { +void GraylogConnection::Impl::setState( + GraylogConnection::Impl::Status NewState) { ConnectionState = NewState; } diff --git a/include/graylog_logger/GraylogConnection.hpp b/src/GraylogConnection.hpp similarity index 83% rename from include/graylog_logger/GraylogConnection.hpp rename to src/GraylogConnection.hpp index cb169ab..ec0541f 100644 --- a/include/graylog_logger/GraylogConnection.hpp +++ b/src/GraylogConnection.hpp @@ -10,6 +10,8 @@ #pragma once #include "graylog_logger/ConcurrentQueue.hpp" +#include "graylog_logger/ConnectionStatus.hpp" +#include "graylog_logger/GraylogInterface.hpp" #include #include #include @@ -24,18 +26,15 @@ struct QueryResult; /// \todo Implement timeouts in the ASIO code in case we ever have problems with /// bad connections. -class GraylogConnection { +class GraylogConnection::Impl { public: - GraylogConnection(std::string Host, int Port); - virtual ~GraylogConnection(); - virtual void sendMessage(std::string msg) { LogMessages.push(msg); }; - enum class Status { - ADDR_LOOKUP, - ADDR_RETRY_WAIT, - CONNECT, - SEND_LOOP, - }; + using Status = Log::Status; + Impl(std::string Host, int Port); + virtual ~Impl(); + virtual void sendMessage(std::string Msg) { LogMessages.push(Msg); }; Status getConnectionStatus() const; + bool messageQueueEmpty() { return LogMessages.empty(); } + size_t messageQueueSize() { return LogMessages.size(); } protected: enum class ReconnectDelay { LONG, SHORT }; diff --git a/src/GraylogInterface.cpp b/src/GraylogInterface.cpp index b667a69..174c0b0 100644 --- a/src/GraylogInterface.cpp +++ b/src/GraylogInterface.cpp @@ -9,26 +9,44 @@ //===----------------------------------------------------------------------===// #include "graylog_logger/GraylogInterface.hpp" +#include "GraylogConnection.hpp" #include #include #include namespace Log { +GraylogConnection::GraylogConnection(std::string Host, int Port) + : Pimpl(std::make_unique(std::move(Host), Port)) {} + +void GraylogConnection::sendMessage(std::string Msg) { + Pimpl->sendMessage(Msg); +} + +Status GraylogConnection::getConnectionStatus() const { + return Pimpl->getConnectionStatus(); +} + +bool GraylogConnection::messageQueueEmpty() { + return Pimpl->messageQueueEmpty(); +} + +size_t GraylogConnection::messageQueueSize() { + return Pimpl->messageQueueSize(); +} + +GraylogConnection::~GraylogConnection() {} + GraylogInterface::GraylogInterface(const std::string &Host, const int Port, const size_t MaxQueueLength) : BaseLogHandler(MaxQueueLength), GraylogConnection(Host, Port) {} -bool GraylogInterface::emptyQueue() { - return GraylogConnection::LogMessages.empty(); -} +bool GraylogInterface::emptyQueue() { return messageQueueEmpty(); } -size_t GraylogInterface::queueSize() { - return GraylogConnection::LogMessages.size(); -} +size_t GraylogInterface::queueSize() { return messageQueueSize(); } void GraylogInterface::addMessage(const LogMessage &Message) { - if (GraylogConnection::LogMessages.size() < BaseLogHandler::QueueLength) { + if (messageQueueSize() < BaseLogHandler::QueueLength) { sendMessage(logMsgToJSON(Message)); } } From 84018f07e2e8649b2f510a8e7aa0c4d18e33a791 Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Fri, 31 May 2019 02:19:27 +0200 Subject: [PATCH 06/12] Missing header fix. --- unit_tests/QueueLengthTest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/unit_tests/QueueLengthTest.cpp b/unit_tests/QueueLengthTest.cpp index 4355de9..9902743 100644 --- a/unit_tests/QueueLengthTest.cpp +++ b/unit_tests/QueueLengthTest.cpp @@ -12,6 +12,7 @@ #include #include #include +#include using namespace Log; From cc5dbb6a230ef9a3e65a4d28977acf3a59720da9 Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Fri, 31 May 2019 02:23:15 +0200 Subject: [PATCH 07/12] Format fix. --- unit_tests/QueueLengthTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit_tests/QueueLengthTest.cpp b/unit_tests/QueueLengthTest.cpp index 9902743..1771369 100644 --- a/unit_tests/QueueLengthTest.cpp +++ b/unit_tests/QueueLengthTest.cpp @@ -9,10 +9,10 @@ #include "graylog_logger/ConsoleInterface.hpp" #include "graylog_logger/FileInterface.hpp" #include "graylog_logger/GraylogInterface.hpp" +#include #include #include #include -#include using namespace Log; From 06e84bea1940f043e8e2009ea3da1b56329997ce Mon Sep 17 00:00:00 2001 From: Matthew D Jones Date: Wed, 5 Jun 2019 14:01:49 +0100 Subject: [PATCH 08/12] Link ASIO target as private --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 3 +-- unit_tests/CMakeLists.txt | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19818aa..000625a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,8 @@ else() add_definitions(-D_WIN32_WINNT=0x0A00) endif(NOT WIN32) +find_package(ASIO REQUIRED MODULE) + add_subdirectory(src) option(BUILD_EVERYTHING "Build UnitTests & Console Logger" ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 983392c..8e6c4b9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,4 @@ find_package(Threads REQUIRED) -find_package(ASIO REQUIRED MODULE) find_package(nlohmann_json REQUIRED) set(Graylog_SRC @@ -29,8 +28,8 @@ set(Graylog_INC set(common_libs PUBLIC Threads::Threads - ASIO::ASIO PRIVATE + ASIO::ASIO nlohmann_json::nlohmann_json) add_library(graylog_logger SHARED ${Graylog_SRC} ${Graylog_INC}) diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index a9bff83..6a1d32e 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -30,6 +30,7 @@ add_executable(unit_tests ${UnitTest_SRC} ${UnitTest_INC}) target_link_libraries(unit_tests GraylogLogger::graylog_logger_static CONAN_PKG::jsonformoderncpp - CONAN_PKG::gtest) + CONAN_PKG::gtest + ASIO::ASIO) add_test(TestAll unit_tests) From dc9c66df5ad91219d832dc8bcd4e0737f726ecd6 Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Thu, 6 Jun 2019 14:04:36 +0200 Subject: [PATCH 09/12] Removed find_package statements. --- cmake/GraylogLoggerConfig.cmake.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmake/GraylogLoggerConfig.cmake.in b/cmake/GraylogLoggerConfig.cmake.in index 421f56c..16807cd 100644 --- a/cmake/GraylogLoggerConfig.cmake.in +++ b/cmake/GraylogLoggerConfig.cmake.in @@ -3,9 +3,7 @@ include(CMakeFindDependencyMacro) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/../cmake/") -find_dependency(ASIO REQUIRED MODULE) find_dependency(Threads REQUIRED) -find_dependency(nlohmann_json REQUIRED) if(NOT TARGET GraylogLogger::graylog_logger) include("${GraylogLogger_CMAKE_DIR}/GraylogLoggerTargets.cmake") From e855a71172d796b89553f7469501ffc21e89c300 Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Thu, 6 Jun 2019 15:45:42 +0200 Subject: [PATCH 10/12] Do not treat ASIO as library. --- src/CMakeLists.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8e6c4b9..b762b71 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,13 +24,7 @@ set(Graylog_INC ../include/graylog_logger/LogUtil.hpp ../include/graylog_logger/ThreadedExecutor.hpp ../include/graylog_logger/ConnectionStatus.hpp) - -set(common_libs - PUBLIC - Threads::Threads - PRIVATE - ASIO::ASIO - nlohmann_json::nlohmann_json) + add_library(graylog_logger SHARED ${Graylog_SRC} ${Graylog_INC}) add_library(GraylogLogger::graylog_logger ALIAS graylog_logger) @@ -41,6 +35,7 @@ target_include_directories(graylog_logger $ PRIVATE "." + ${ASIO_INCLUDE_DIR} ) add_library(graylog_logger_static STATIC ${Graylog_SRC} ${Graylog_INC} ${Graylog_private_INC}) @@ -52,6 +47,7 @@ target_include_directories(graylog_logger_static $ PRIVATE "." + ${ASIO_INCLUDE_DIR} ) set_target_properties(graylog_logger PROPERTIES VERSION ${PROJECT_VERSION}) From 4fe5788e989b854707aa4def898ba3eb440382ff Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Thu, 6 Jun 2019 15:47:43 +0200 Subject: [PATCH 11/12] Oopsie. --- src/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b762b71..639899b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,12 @@ set(Graylog_INC ../include/graylog_logger/ThreadedExecutor.hpp ../include/graylog_logger/ConnectionStatus.hpp) +set(common_libs + PUBLIC + Threads::Threads + PRIVATE + nlohmann_json::nlohmann_json + ) add_library(graylog_logger SHARED ${Graylog_SRC} ${Graylog_INC}) add_library(GraylogLogger::graylog_logger ALIAS graylog_logger) From da4ca26cde914c578151d9121a94a782c993b462 Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Thu, 6 Jun 2019 16:20:57 +0200 Subject: [PATCH 12/12] Do not treat nlohmann as a library. --- src/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 639899b..22c1428 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,10 +28,10 @@ set(Graylog_INC set(common_libs PUBLIC Threads::Threads - PRIVATE - nlohmann_json::nlohmann_json ) +get_target_property(JSON_INCLUDE_DIR nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) + add_library(graylog_logger SHARED ${Graylog_SRC} ${Graylog_INC}) add_library(GraylogLogger::graylog_logger ALIAS graylog_logger) target_link_libraries(graylog_logger ${common_libs}) @@ -42,6 +42,7 @@ target_include_directories(graylog_logger PRIVATE "." ${ASIO_INCLUDE_DIR} + ${JSON_INCLUDE_DIR} ) add_library(graylog_logger_static STATIC ${Graylog_SRC} ${Graylog_INC} ${Graylog_private_INC}) @@ -54,6 +55,7 @@ target_include_directories(graylog_logger_static PRIVATE "." ${ASIO_INCLUDE_DIR} + ${JSON_INCLUDE_DIR} ) set_target_properties(graylog_logger PROPERTIES VERSION ${PROJECT_VERSION})