From 56a9a700ff4a0cd1ff20eeaebd41a89d72992f3a Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Tue, 12 May 2020 11:45:01 +0200 Subject: [PATCH 1/4] Fixes cmake and namespace issues. --- CMakeLists.txt | 20 ++++++++++++---- cmake/FindASIO.cmake | 6 ++--- cmake/FindConcurrentQueue.cmake | 6 ++--- cmake/GraylogLoggerConfig.cmake.in | 6 ++--- include/graylog_logger/MinimalApply.hpp | 3 ++- src/CMakeLists.txt | 32 +++++++++++++++---------- unit_tests/CMakeLists.txt | 18 ++++++++++---- 7 files changed, 60 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4684f5b..c6e6c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project("graylog-logger" set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) # Conan - bring in dependencies with conan set(CONAN_PROFILE "default" CACHE STRING "Name of conan profile to use, uses default by default") @@ -40,14 +40,26 @@ else() add_definitions(-D_WIN32_WINNT=0x0A00) endif(NOT WIN32) -find_package(ASIO REQUIRED MODULE) -find_package(nlohmann_json REQUIRED) +find_package(asio REQUIRED) +find_package(nlohmann_json QUIET) +if (NOT nlohmann_json_FOUND) + message(STATUS "Unable to find system installed version of jsonformoderncpp. Attempting to find Conan provided version.") + find_package(jsonformoderncpp REQUIRED) +endif() + find_package(Threads REQUIRED) find_package(ConcurrentQueue REQUIRED) find_package(GTest) find_package(GMock) -find_package(fmt 6) +find_package(fmt CONFIG) +if (NOT fmt_FOUND) + message(STATUS "Unable to find fmt using config-module. Attempting again using built-in find-module.") + find_package(fmt MODULE) + if (NOT fmt_FOUND) + message(STATUS "Unable to find fmt using built-in find-module.") + endif() +endif() find_package(GoogleBenchmark) add_subdirectory(src) diff --git a/cmake/FindASIO.cmake b/cmake/FindASIO.cmake index 4ee4b5b..04cd627 100644 --- a/cmake/FindASIO.cmake +++ b/cmake/FindASIO.cmake @@ -23,9 +23,9 @@ 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 +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/FindConcurrentQueue.cmake b/cmake/FindConcurrentQueue.cmake index eaf50ab..2999878 100644 --- a/cmake/FindConcurrentQueue.cmake +++ b/cmake/FindConcurrentQueue.cmake @@ -16,9 +16,9 @@ if(ConcurrentQueue_FOUND) set(ConcurrentQueue_INCLUDE_DIRS ${ConcurrentQueue_INCLUDE_DIR}) endif() -if(ConcurrentQueue_FOUND AND NOT TARGET ConcurrentQueue::ConcurrentQueue) - add_library(ConcurrentQueue::ConcurrentQueue INTERFACE IMPORTED) - set_target_properties(ConcurrentQueue::ConcurrentQueue PROPERTIES +if(ConcurrentQueue_FOUND AND NOT TARGET concurrentqueue::concurrentqueue) + add_library(concurrentqueue::concurrentqueue INTERFACE IMPORTED) + set_target_properties(concurrentqueue::concurrentqueue PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ConcurrentQueue_INCLUDE_DIR}" ) endif() diff --git a/cmake/GraylogLoggerConfig.cmake.in b/cmake/GraylogLoggerConfig.cmake.in index 15e48e0..84ff286 100644 --- a/cmake/GraylogLoggerConfig.cmake.in +++ b/cmake/GraylogLoggerConfig.cmake.in @@ -4,14 +4,12 @@ include(CMakeFindDependencyMacro) list(APPEND CMAKE_MODULE_PATH ${GraylogLogger_CMAKE_DIR}) find_dependency(Threads REQUIRED) -find_dependency(ASIO REQUIRED MODULE) -find_dependency(nlohmann_json REQUIRED) -find_dependency(ConcurrentQueue REQUIRED) +find_dependency(concurrentqueue REQUIRED) set(WITH_FMT @fmt_FOUND@) if(WITH_FMT) - find_package(fmt 6 REQUIRED) + find_dependency(fmt REQUIRED) endif() if(NOT TARGET GraylogLogger::graylog_logger) diff --git a/include/graylog_logger/MinimalApply.hpp b/include/graylog_logger/MinimalApply.hpp index 99e82fc..fe2c3b3 100644 --- a/include/graylog_logger/MinimalApply.hpp +++ b/include/graylog_logger/MinimalApply.hpp @@ -20,7 +20,8 @@ namespace detail { template constexpr decltype(auto) apply_impl(F &&f, Tuple &&t, std::index_sequence) { - return invoke(std::forward(f), std::get(std::forward(t))...); + return minimal::invoke(std::forward(f), + std::get(std::forward(t))...); } } // namespace detail diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a32d438..a9d623f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1,22 @@ -set(common_libs PUBLIC +set(common_private_libs Threads::Threads - ConcurrentQueue::ConcurrentQueue - ASIO::ASIO - nlohmann_json::nlohmann_json - ) + asio::asio +) +if (nlohmann_json_FOUND) + list(APPEND common_private_libs nlohmann_json::nlohmann_json) +endif() + +if (jsonformoderncpp_FOUND) + list(APPEND common_private_libs jsonformoderncpp::jsonformoderncpp) +endif() + +set(common_public_libs + concurrentqueue::concurrentqueue +) if(fmt_FOUND) message(STATUS "Found fmtlib, adding support for threaded formatting.") - list(APPEND common_libs fmt::fmt) + list(APPEND common_public_libs fmt::fmt) else() message(STATUS "Unable to find fmtlib. There will be no support for threaded formatting.") endif() @@ -40,11 +49,10 @@ set(Graylog_INC ${CMAKE_BINARY_DIR}/include/graylog_logger/LibConfig.hpp ) -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}) +target_link_libraries(graylog_logger PRIVATE ${common_private_libs}) +target_link_libraries(graylog_logger PUBLIC ${common_public_libs}) target_include_directories(graylog_logger PUBLIC $ @@ -56,7 +64,8 @@ target_include_directories(graylog_logger add_library(graylog_logger_static STATIC ${Graylog_SRC} ${Graylog_INC} ${Graylog_private_INC}) add_library(GraylogLogger::graylog_logger_static ALIAS graylog_logger_static) -target_link_libraries(graylog_logger_static ${common_libs}) +target_link_libraries(graylog_logger_static PRIVATE ${common_private_libs}) +target_link_libraries(graylog_logger_static PUBLIC ${common_public_libs}) target_include_directories(graylog_logger_static PUBLIC $ @@ -108,8 +117,7 @@ configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/GraylogLoggerConfig.cm ) install(FILES - ${CMAKE_CURRENT_LIST_DIR}/../cmake/FindASIO.cmake - ${CMAKE_CURRENT_LIST_DIR}/../cmake/FindConcurrentQueue.cmake + ${CMAKE_CURRENT_LIST_DIR}/../cmake/Findconcurrentqueue.cmake ${CMAKE_CURRENT_BINARY_DIR}/GraylogLoggerConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/GraylogLoggerConfigVersion.cmake DESTINATION ${INSTALL_CONFIGDIR} diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 2e663b2..f407b59 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -26,13 +26,23 @@ set(UnitTest_INC Semaphore.hpp) add_executable(unit_tests EXCLUDE_FROM_ALL ${UnitTest_SRC} ${UnitTest_INC}) - -target_link_libraries(unit_tests +set(unit_test_libs PUBLIC GraylogLogger::graylog_logger_static - nlohmann_json::nlohmann_json GTest::GTest ${GMOCK_BOTH_LIBRARIES} - ASIO::ASIO + asio::asio +) + +if (nlohmann_json_FOUND) + list(APPEND unit_test_libs nlohmann_json::nlohmann_json) +endif() + +if (jsonformoderncpp_FOUND) + list(APPEND unit_test_libs jsonformoderncpp::jsonformoderncpp) +endif() + +target_link_libraries(unit_tests + ${unit_test_libs} ) add_test(TestAll unit_tests) From 8c725742e33167028b2b5f1886cedbef1d351ced Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Tue, 12 May 2020 11:50:42 +0200 Subject: [PATCH 2/4] Minor CMake fixes. --- cmake/{FindASIO.cmake => Findasio.cmake} | 0 cmake/{FindConcurrentQueue.cmake => Findconcurrentqueue.cmake} | 0 conanfile.txt | 1 + 3 files changed, 1 insertion(+) rename cmake/{FindASIO.cmake => Findasio.cmake} (100%) rename cmake/{FindConcurrentQueue.cmake => Findconcurrentqueue.cmake} (100%) diff --git a/cmake/FindASIO.cmake b/cmake/Findasio.cmake similarity index 100% rename from cmake/FindASIO.cmake rename to cmake/Findasio.cmake diff --git a/cmake/FindConcurrentQueue.cmake b/cmake/Findconcurrentqueue.cmake similarity index 100% rename from cmake/FindConcurrentQueue.cmake rename to cmake/Findconcurrentqueue.cmake diff --git a/conanfile.txt b/conanfile.txt index cd0f939..a47e5eb 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -12,3 +12,4 @@ gtest:shared=False [generators] cmake virtualrunenv +cmake_find_package From 9bd42a898381f69833268a26ade9d1bfc84e13f4 Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Tue, 12 May 2020 11:57:12 +0200 Subject: [PATCH 3/4] Fixed bad library name. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6e6c46..c695278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ if (NOT nlohmann_json_FOUND) endif() find_package(Threads REQUIRED) -find_package(ConcurrentQueue REQUIRED) +find_package(concurrentqueue REQUIRED) find_package(GTest) find_package(GMock) From 047034545b322165cf91a23ba17494e5cf2d0006 Mon Sep 17 00:00:00 2001 From: Jonas Nilsson Date: Tue, 12 May 2020 12:17:42 +0200 Subject: [PATCH 4/4] Updated the documentation. --- README.md | 3 +++ documentation/changes.md | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 0a44450..04ebcd0 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,9 @@ cmake .. make install ``` +#### Making a conan package +If you are creating a conan package of this library you should disable CMake from running Conan by providing the following argument to CMake: `-DCONAN=DISABLE`. Furthermore, you must also use the `cmake_find_package` generator for CMake to be able to find the dependencies. + #### System installed dependencies If using conan is not an option, it is possible to build the library using system installed dependencies. This requires a bit more work though and might not be as reliable. diff --git a/documentation/changes.md b/documentation/changes.md index 6af9b9d..3341220 100644 --- a/documentation/changes.md +++ b/documentation/changes.md @@ -1,5 +1,13 @@ ## Changes +### Version 2.0.2 +* Made important CMkae changes required for properly making Conan packages. (ed-alertedh) +* Made minor changes to the code to prevent issues when using a `using namespace std;` statement. +* Minor documentation changes. + +### Version 2.0.1 +* Fixed faulty CMake code that did not properly import dependencies. + ### Version 2.0.0 * Added performance tests. * Replaced the home-brewed concurrent queue with a *much* faster open source one.