Add some recipes

This commit is contained in:
2025-04-24 22:24:04 +12:00
parent 8df741f8c0
commit 79e29df082
23 changed files with 1015 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
sources:
"1.15.1":
url: "https://github.com/gabime/spdlog/archive/v1.15.1.tar.gz"
sha256: "25c843860f039a1600f232c6eb9e01e6627f7d030a2ae5e232bdd3c9205d26cc"
"1.15.0":
url: "https://github.com/gabime/spdlog/archive/v1.15.0.tar.gz"
sha256: "9962648c9b4f1a7bbc76fd8d9172555bad1871fdb14ff4f842ef87949682caa5"
"1.14.1":
url: "https://github.com/gabime/spdlog/archive/v1.14.1.tar.gz"
sha256: "1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b"
"1.14.0":
url: "https://github.com/gabime/spdlog/archive/v1.14.0.tar.gz"
sha256: "429a6b73ade8285cb21f83bacf89e2821dd1720ea7faa3cb518ffe04b4e00efc"
"1.13.0":
url: "https://github.com/gabime/spdlog/archive/v1.13.0.tar.gz"
sha256: "534f2ee1a4dcbeb22249856edfb2be76a1cf4f708a20b0ac2ed090ee24cfdbc9"
"1.12.0":
url: "https://github.com/gabime/spdlog/archive/v1.12.0.tar.gz"
sha256: "4dccf2d10f410c1e2feaff89966bfc49a1abb29ef6f08246335b110e001e09a9"
"1.11.0":
url: "https://github.com/gabime/spdlog/archive/v1.11.0.tar.gz"
sha256: "ca5cae8d6cac15dae0ec63b21d6ad3530070650f68076f3a4a862ca293a858bb"
"1.10.0":
url: "https://github.com/gabime/spdlog/archive/v1.10.0.tar.gz"
sha256: "697f91700237dbae2326b90469be32b876b2b44888302afbc7aceb68bcfe8224"
"1.9.2":
url: "https://github.com/gabime/spdlog/archive/v1.9.2.tar.gz"
sha256: "6fff9215f5cb81760be4cc16d033526d1080427d236e86d70bb02994f85e3d38"
"1.9.1":
url: "https://github.com/gabime/spdlog/archive/v1.9.1.tar.gz"
sha256: "9a452cfa24408baccc9b2bc2d421d68172a7630c99e9504a14754be840d31a62"
"1.8.5":
url: "https://github.com/gabime/spdlog/archive/v1.8.5.tar.gz"
sha256: "944d0bd7c763ac721398dca2bb0f3b5ed16f67cef36810ede5061f35a543b4b8"
patches:
"1.11.0":
- patch_file: "patches/1.11.0-0001-fix-fmt10-build.patch"
patch_description: "Fix fmt 10.0.0 build"
patch_type: "conan"
patch_source: "https://github.com/gabime/spdlog/pull/2694"
# Each release is intended to work with some specific versions
fmt_version_mapping:
"1.15.1": "11.1.3"
"1.15.0": "11.0.2"
"1.14.1": "10.2.1"
"1.14.0": "10.2.1"
"1.13.0": "10.2.1"
"1.12.0": "10.2.1"
"1.11.0": "10.0.0"
"1.10.0": "8.1.1"
"1.9.2": "8.0.1"
"1.9.1": "8.0.1"
"1.8.5": "7.1.3"

View File

@@ -0,0 +1,196 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.files import get, copy, rmdir, replace_in_file, apply_conandata_patches, export_conandata_patches
from conan.tools.microsoft import check_min_vs, is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version
import os
required_conan_version = ">=1.53.0"
class SpdlogConan(ConanFile):
name = "spdlog"
package_type = "library"
description = "Fast C++ logging library"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/gabime/spdlog"
topics = ("logger", "logging", "log-filtering", "file sink", "header-only")
license = "MIT"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"header_only": [True, False],
"wchar_support": [True, False],
"wchar_filenames": [True, False],
"wchar_console": [True, False],
"no_exceptions": [True, False],
"use_std_fmt": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"header_only": False,
"wchar_support": False,
"wchar_filenames": False,
"wchar_console": False,
"no_exceptions": False,
"use_std_fmt": False,
}
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
else:
del self.options.wchar_support
del self.options.wchar_filenames
del self.options.wchar_console
if Version(self.version) < "1.10.0":
del self.options.use_std_fmt
if Version(self.version) < "1.15.0":
self.options.rm_safe("wchar_console")
def configure(self):
if self.options.get_safe("shared") or self.options.header_only:
self.options.rm_safe("fPIC")
if self.options.header_only:
self.options.rm_safe("shared")
def layout(self):
cmake_layout(self, src_folder="src")
def requirements(self):
if not self.options.get_safe("use_std_fmt"):
fmt_version = self.conan_data["fmt_version_mapping"][self.version]
self.requires(f"fmt/{fmt_version}", transitive_headers=True, transitive_libs=True)
def package_id(self):
if self.info.options.header_only:
self.info.clear()
@property
def _std_fmt_compilers_minimum_version(self):
return {
"gcc": "13",
"clang": "14",
"apple-clang": "15",
"Visual Studio": "16",
"msvc": "192",
}
def validate(self):
if self.options.get_safe("use_std_fmt"):
check_min_cppstd(self, 20)
else:
check_min_cppstd(self, 11)
if self.options.get_safe("shared") and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration("Visual Studio build for shared library with MT runtime is not supported")
if self.options.get_safe("use_std_fmt"):
compiler_name = str(self.settings.compiler)
minimum_version = self._std_fmt_compilers_minimum_version.get(compiler_name, False)
if not minimum_version:
self.output.warning(f"{self.name} recipe lacks information about the {compiler_name} compiler support.")
elif Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} using std::fmt requires std::fmt, which your compiler does not support."
)
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
if not self.options.header_only:
tc = CMakeToolchain(self)
tc.variables["SPDLOG_BUILD_EXAMPLE"] = False
tc.variables["SPDLOG_BUILD_EXAMPLE_HO"] = False
tc.variables["SPDLOG_BUILD_TESTS"] = False
tc.variables["SPDLOG_BUILD_TESTS_HO"] = False
tc.variables["SPDLOG_BUILD_BENCH"] = False
if not self.options.get_safe("use_std_fmt"):
fmt = self.dependencies["fmt"]
tc.variables["SPDLOG_FMT_EXTERNAL"] = not fmt.options.header_only
tc.variables["SPDLOG_FMT_EXTERNAL_HO"] = fmt.options.header_only
tc.variables["SPDLOG_BUILD_SHARED"] = not self.options.header_only and self.options.shared
tc.variables["SPDLOG_WCHAR_SUPPORT"] = self.options.get_safe("wchar_support", False)
tc.variables["SPDLOG_WCHAR_FILENAMES"] = self.options.get_safe("wchar_filenames", False)
if Version(self.version) >= "1.15.0":
tc.variables["SDPLOG_WCHAR_CONSOLE"] = self.options.get_safe("wchar_console", False)
tc.variables["SPDLOG_INSTALL"] = True
tc.variables["SPDLOG_NO_EXCEPTIONS"] = self.options.no_exceptions
tc.variables["SPDLOG_USE_STD_FORMAT"] = self.options.get_safe("use_std_fmt")
if self.settings.os in ("iOS", "tvOS", "watchOS"):
tc.variables["SPDLOG_NO_TLS"] = True
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0091"] = "NEW"
tc.generate()
cmake_deps = CMakeDeps(self)
cmake_deps.generate()
def _patch_sources(self):
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "cmake", "utils.cmake"), "/WX", "")
# This is properly set in later versions
if self.options.get_safe("use_std_fmt") and Version(self.version) < "1.12":
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"CMAKE_CXX_STANDARD 11", "CMAKE_CXX_STANDARD 20")
def build(self):
self._patch_sources()
if not self.options.header_only:
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
if self.options.header_only:
copy(self,
src=os.path.join(self.source_folder, "include"),
pattern="*.h", dst=os.path.join(self.package_folder, "include"),
# Unvendor bundled dependencies https://github.com/gabime/spdlog/commit/18495bf25dad3a4e8c2fe3777a5f79acecde27e3
excludes=("spdlog/fmt/bundled/*"))
else:
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "spdlog", "cmake"))
def package_info(self):
target = "spdlog_header_only" if self.options.header_only else "spdlog"
self.cpp_info.set_property("cmake_file_name", "spdlog")
self.cpp_info.set_property("cmake_target_name", f"spdlog::{target}")
self.cpp_info.set_property("pkg_config_name", "spdlog")
# TODO: back to global scope in conan v2 once legacy generators removed
self.cpp_info.components["libspdlog"].set_property("cmake_target_name", f"spdlog::{target}")
if self.options.get_safe("use_std_fmt"):
self.cpp_info.components["libspdlog"].defines.append("SPDLOG_USE_STD_FORMAT")
else:
self.cpp_info.components["libspdlog"].requires = ["fmt::fmt"]
self.cpp_info.components["libspdlog"].defines.append("SPDLOG_FMT_EXTERNAL")
if self.options.header_only:
self.cpp_info.components["libspdlog"].libdirs = []
else:
suffix = "d" if self.settings.build_type == "Debug" else ""
self.cpp_info.components["libspdlog"].libs = [f"spdlog{suffix}"]
self.cpp_info.components["libspdlog"].defines.append("SPDLOG_COMPILED_LIB")
if self.options.get_safe("wchar_support"):
self.cpp_info.components["libspdlog"].defines.append("SPDLOG_WCHAR_TO_UTF8_SUPPORT")
if self.options.get_safe("wchar_filenames"):
self.cpp_info.components["libspdlog"].defines.append("SPDLOG_WCHAR_FILENAMES")
if self.options.get_safe("wchar_console"):
self.cpp_info.components["libspdlog"].defines.append("SPDLOG_UTF8_TO_WCHAR_CONSOLE")
if self.options.no_exceptions:
self.cpp_info.components["libspdlog"].defines.append("SPDLOG_NO_EXCEPTIONS")
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["libspdlog"].system_libs = ["pthread"]
if self.options.header_only and self.settings.os in ("iOS", "tvOS", "watchOS"):
self.cpp_info.components["libspdlog"].defines.append("SPDLOG_NO_TLS")

View File

@@ -0,0 +1,34 @@
From 576210a1363822a132657090b9f37e305bd0e2c2 Mon Sep 17 00:00:00 2001
From: pwqbot <ding00000804@gmail.com>
Date: Tue, 20 Jun 2023 10:41:48 +0800
Subject: [PATCH] fix fmt build
---
include/spdlog/common.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/spdlog/common.h b/include/spdlog/common.h
index f97fd48c..00f4d728 100644
--- a/include/spdlog/common.h
+++ b/include/spdlog/common.h
@@ -160,12 +160,19 @@ using format_string_t = fmt::format_string<Args...>;
template<class T>
using remove_cvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
+template<typename Char>
+# if FMT_VERSION >= 90101
+using fmt_runtime_string = fmt::runtime_format_string<Char>;
+# else
+using fmt_runtime_string = fmt::basic_runtime<Char>;
+# endif
+
// clang doesn't like SFINAE disabled constructor in std::is_convertible<> so have to repeat the condition from basic_format_string here,
// in addition, fmt::basic_runtime<Char> is only convertible to basic_format_string<Char> but not basic_string_view<Char>
template<class T, class Char = char>
struct is_convertible_to_basic_format_string
: std::integral_constant<bool,
- std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
+ std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt_runtime_string<Char>>::value>
{};
# if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)

View File

@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)
find_package(spdlog REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.cpp)
if(SPDLOG_HEADER_ONLY)
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog_header_only)
else()
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog)
endif()
if(SPDLOG_USE_STD_FORMAT)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
else()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
endif()

View File

@@ -0,0 +1,33 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["SPDLOG_HEADER_ONLY"] = self.dependencies["spdlog"].options.header_only
tc.variables["SPDLOG_USE_STD_FORMAT"] = self.dependencies["spdlog"].options.get_safe("use_std_fmt", False)
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

View File

@@ -0,0 +1,13 @@
#include <cstdlib>
#include "spdlog/spdlog.h"
#if defined __has_include
# if __has_include ("spdlog/fmt/bundled/core.h")
# error "bundled fmt within spdlog should not be present"
# endif
#endif
int main(void) {
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
return EXIT_SUCCESS;
}