From 348299ad9266a31baea2f33378a6eaef8ca80ebf Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov Date: Thu, 9 Jan 2025 20:43:34 +0800 Subject: [PATCH] Feature: vcpkg compatibility (#14) Signed-off-by: Dmitriy Khaustov aka xDimon (cherry picked from commit 4dd31224415fdf6623947f901727154e2da9d872) --- CMakeLists.txt | 26 ++++++++++++++++++++++---- cmake/dependencies.cmake | 21 +++++++++++++-------- cmake/toolchain/compiler/clang.cmake | 6 ++++++ cmake/toolchain/compiler/gcc.cmake | 2 ++ include/soralog/circular_buffer.hpp | 2 +- include/soralog/event.hpp | 3 ++- src/logging_system.cpp | 2 +- src/soralog.cpp | 2 +- test/unit/macros_test.cpp | 3 ++- vcpkg-configuration.json | 14 ++++++++++++++ vcpkg.json | 9 +++++++++ 11 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 vcpkg-configuration.json create mode 100644 vcpkg.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 38a9fb7..4f21775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,10 +7,28 @@ cmake_minimum_required(VERSION 3.12) -include("cmake/Hunter/init.cmake") +if (PACKAGE_MANAGER) + if(PACKAGE_MANAGER NOT MATCHES "^(hunter|vcpkg)$") + message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set") + endif () +else () + set(PACKAGE_MANAGER "hunter") + if (CMAKE_TOOLCHAIN_FILE) + get_filename_component(ACTUAL_NAME ${CMAKE_TOOLCHAIN_FILE} NAME) + if(ACTUAL_NAME STREQUAL "vcpkg.cmake") + message(STATUS "vcpkg will be used because vcpkg.cmake has found") + set(PACKAGE_MANAGER "vcpkg") + endif () + endif () +endif () +message(STATUS "Selected package manager: ${PACKAGE_MANAGER}") + +if (PACKAGE_MANAGER STREQUAL "hunter") + include("cmake/Hunter/init.cmake") +endif () cmake_policy(SET CMP0048 NEW) -project(soralog VERSION 0.2.4 LANGUAGES CXX) +project(soralog VERSION 0.2.5 LANGUAGES CXX) find_program(CCACHE_FOUND ccache) if (CCACHE_FOUND) @@ -34,9 +52,9 @@ if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) CACHE FILEPATH "Default toolchain" ) endif () + print("Toolchain: ${CMAKE_TOOLCHAIN_FILE}") + include(${CMAKE_TOOLCHAIN_FILE}) endif () -print("Toolchain: ${CMAKE_TOOLCHAIN_FILE}") -include(${CMAKE_TOOLCHAIN_FILE}) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index c1cbcdc..bc9c56f 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -5,16 +5,21 @@ # SPDX-License-Identifier: Apache-2.0 # -if (TESTING OR COVERAGE) - hunter_add_package(GTest) - find_package(GTest CONFIG REQUIRED) -endif() +function(reg_dependency name) + if (${HUNTER_ENABLED}) + hunter_add_package(${name}) + endif () + find_package(${name} CONFIG REQUIRED) +endfunction() + -hunter_add_package(yaml-cpp) -find_package(yaml-cpp CONFIG REQUIRED) +reg_dependency(yaml-cpp) if (NOT TARGET yaml-cpp::yaml-cpp) add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp) endif() -hunter_add_package(fmt) -find_package(fmt CONFIG REQUIRED) +reg_dependency(fmt) + +if (TESTING OR COVERAGE) + reg_dependency(GTest) +endif() diff --git a/cmake/toolchain/compiler/clang.cmake b/cmake/toolchain/compiler/clang.cmake index aa5be39..fe97f2a 100644 --- a/cmake/toolchain/compiler/clang.cmake +++ b/cmake/toolchain/compiler/clang.cmake @@ -20,6 +20,9 @@ endif() find_program(CMAKE_C_COMPILER clang + clang-20 + clang-19 + clang-18 clang-17 clang-16 clang-15 @@ -29,6 +32,9 @@ find_program(CMAKE_C_COMPILER clang-11) find_program(CMAKE_CXX_COMPILER clang++ + clang++-20 + clang++-19 + clang++-18 clang++-17 clang++-16 clang++-15 diff --git a/cmake/toolchain/compiler/gcc.cmake b/cmake/toolchain/compiler/gcc.cmake index 9d2fc36..ab0a17b 100644 --- a/cmake/toolchain/compiler/gcc.cmake +++ b/cmake/toolchain/compiler/gcc.cmake @@ -13,6 +13,7 @@ endif() find_program(CMAKE_C_COMPILER gcc + gcc-14 gcc-13 gcc-12 gcc-11 @@ -20,6 +21,7 @@ find_program(CMAKE_C_COMPILER gcc-9) find_program(CMAKE_CXX_COMPILER g++ + g++-14 g++-13 g++-12 g++-11 diff --git a/include/soralog/circular_buffer.hpp b/include/soralog/circular_buffer.hpp index 25d8510..76aa463 100644 --- a/include/soralog/circular_buffer.hpp +++ b/include/soralog/circular_buffer.hpp @@ -38,7 +38,7 @@ namespace soralog { } // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes) - std::atomic_flag busy = ATOMIC_VAR_INIT(false); + std::atomic_flag busy{false}; private: // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) diff --git a/include/soralog/event.hpp b/include/soralog/event.hpp index a673b0d..b7c4c97 100644 --- a/include/soralog/event.hpp +++ b/include/soralog/event.hpp @@ -88,8 +88,9 @@ namespace soralog { } it{message_data_}; try { + using OutputIt = decltype(it); message_size_ = - ::fmt::vformat_to_n( + ::fmt::vformat_to_n( it, max_message_length, ::fmt::detail_exported::compile_string_to_view(format), diff --git a/src/logging_system.cpp b/src/logging_system.cpp index 7512d96..48a5f58 100644 --- a/src/logging_system.cpp +++ b/src/logging_system.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include diff --git a/src/soralog.cpp b/src/soralog.cpp index 77acc7c..2398763 100644 --- a/src/soralog.cpp +++ b/src/soralog.cpp @@ -10,6 +10,6 @@ namespace soralog { // to suppress warning about no symbols in cpp // NOLINTNEXTLINE(bugprone-reserved-identifier) - const char *const __library_name = "soralog"; + extern const char *const __library_name = "soralog"; } // namespace soralog diff --git a/test/unit/macros_test.cpp b/test/unit/macros_test.cpp index 7a109a2..9585649 100644 --- a/test/unit/macros_test.cpp +++ b/test/unit/macros_test.cpp @@ -20,8 +20,9 @@ class MacrosTest : public ::testing::Test { template void log(Level lvl, const Format &format, Args &&...args) { last_level = lvl; + using OutputIt = decltype(message_buf.begin()); size_t len = - ::fmt::vformat_to_n( + ::fmt::vformat_to_n( message_buf.begin(), message_buf.size(), ::fmt::detail_exported::compile_string_to_view(format), ::fmt::make_format_args(args...)) diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 0000000..4f69c22 --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "fe1cde61e971d53c9687cf9a46308f8f55da19fa", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..c3e159e --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,9 @@ +{ + "name": "soralog", + "version": "0.2.5", + "dependencies": [ + "fmt", + "yaml-cpp", + "gtest" + ] +}