Skip to content

Commit

Permalink
Feature: vcpkg compatibility (#14)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

(cherry picked from commit 4dd3122)
  • Loading branch information
xDimon committed Jan 10, 2025
1 parent 526cede commit 348299a
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 17 deletions.
26 changes: 22 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
21 changes: 13 additions & 8 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions cmake/toolchain/compiler/clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ endif()

find_program(CMAKE_C_COMPILER
clang
clang-20
clang-19
clang-18
clang-17
clang-16
clang-15
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmake/toolchain/compiler/gcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ endif()

find_program(CMAKE_C_COMPILER
gcc
gcc-14
gcc-13
gcc-12
gcc-11
gcc-10
gcc-9)
find_program(CMAKE_CXX_COMPILER
g++
g++-14
g++-13
g++-12
g++-11
Expand Down
2 changes: 1 addition & 1 deletion include/soralog/circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion include/soralog/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ namespace soralog {
} it{message_data_};

try {
using OutputIt = decltype(it);
message_size_ =
::fmt::vformat_to_n(
::fmt::vformat_to_n<OutputIt>(
it,
max_message_length,
::fmt::detail_exported::compile_string_to_view<char>(format),
Expand Down
2 changes: 1 addition & 1 deletion src/logging_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <cassert>
#include <functional>
#include <iostream>
#include <ranges>
#include <set>

#include <soralog/group.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/soralog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/unit/macros_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class MacrosTest : public ::testing::Test {
template <typename Format, typename... Args>
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<OutputIt>(
message_buf.begin(), message_buf.size(),
::fmt::detail_exported::compile_string_to_view<char>(format),
::fmt::make_format_args(args...))
Expand Down
14 changes: 14 additions & 0 deletions vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
9 changes: 9 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "soralog",
"version": "0.2.5",
"dependencies": [
"fmt",
"yaml-cpp",
"gtest"
]
}

0 comments on commit 348299a

Please sign in to comment.