From f19f72b4beff7620e1f36e194d3eaad3c4e82d81 Mon Sep 17 00:00:00 2001 From: Grzegorz Antoniak Date: Fri, 2 Dec 2022 20:08:24 +0100 Subject: [PATCH] Add `loguru/2.1.0` recipe Loguru: a lightweight and flexible C++ logging library. Website: https://emilk.github.io/loguru/index.html Source code: https://github.com/emilk/loguru Closes #14542 --- recipes/loguru/all/CMakeLists.txt | 63 ++++++++ recipes/loguru/all/LICENSE.md | 21 +++ recipes/loguru/all/conandata.yml | 4 + recipes/loguru/all/conanfile.py | 147 ++++++++++++++++++ .../loguru/all/test_package/CMakeLists.txt | 8 + recipes/loguru/all/test_package/conanfile.py | 32 ++++ .../loguru/all/test_package/test_package.cpp | 38 +++++ recipes/loguru/config.yml | 3 + 8 files changed, 316 insertions(+) create mode 100644 recipes/loguru/all/CMakeLists.txt create mode 100644 recipes/loguru/all/LICENSE.md create mode 100644 recipes/loguru/all/conandata.yml create mode 100644 recipes/loguru/all/conanfile.py create mode 100644 recipes/loguru/all/test_package/CMakeLists.txt create mode 100644 recipes/loguru/all/test_package/conanfile.py create mode 100644 recipes/loguru/all/test_package/test_package.cpp create mode 100644 recipes/loguru/config.yml diff --git a/recipes/loguru/all/CMakeLists.txt b/recipes/loguru/all/CMakeLists.txt new file mode 100644 index 00000000000000..b8d64cf258f38d --- /dev/null +++ b/recipes/loguru/all/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.25) +project(loguru) + +set(CMAKE_CXX_STANDARD 11) +set(src loguru.cpp loguru.hpp) + +if (LOGURU_STATIC) + message("-- loguru: building a static library") + add_library(loguru STATIC ${src}) +else () + message("-- loguru: building a shared library") + add_library(loguru SHARED ${src}) +endif () + +if (LOGURU_USE_FMTLIB) + message("-- loguru: using fmtlib") + target_compile_definitions(loguru PUBLIC -DLOGURU_USE_FMTLIB) + find_package(fmt CONFIG REQUIRED) + target_link_libraries(loguru PUBLIC fmt::fmt) +endif () + +if (LOGURU_SCOPE_TEXT_SIZE) + message("-- loguru: setting LOGURU_SCOPE_TEXT_SIZE=${LOGURU_SCOPE_TEXT_SIZE}") + target_compile_definitions(loguru PUBLIC -DLOGURU_SCOPE_TEXT_SIZE=${LOGURU_SCOPE_TEXT_SIZE}) +endif () + +if (LOGURU_FILENAME_WIDTH) + message("-- loguru: setting LOGURU_FILENAME_WIDTH=${LOGURU_FILENAME_WIDTH}") + target_compile_definitions(loguru PUBLIC -DLOGURU_FILENAME_WIDTH=${LOGURU_FILENAME_WIDTH}) +endif () + +if (LOGURU_THREADNAME_WIDTH) + message("-- loguru: setting LOGURU_THREADNAME_WIDTH=${LOGURU_THREADNAME_WIDTH}") + target_compile_definitions(loguru PUBLIC -DLOGURU_THREADNAME_WIDTH=${LOGURU_THREADNAME_WIDTH}) +endif () + +if (LOGURU_SCOPE_TIME_PRECISION) + message("-- loguru: setting LOGURU_SCOPE_TIME_PRECISION=${LOGURU_SCOPE_TIME_PRECISION}") + target_compile_definitions(loguru PUBLIC -DLOGURU_SCOPE_TIME_PRECISION=${LOGURU_SCOPE_TIME_PRECISION}) +endif () + +message("-- loguru: setting LOGURU_CATCH_SIGABRT=${LOGURU_CATCH_SIGABRT}") +target_compile_definitions(loguru PUBLIC -DLOGURU_CATCH_SIGABRT=${LOGURU_CATCH_SIGABRT}) + +message("-- loguru: setting LOGURU_VERBOSE_SCOPE_ENDINGS=${LOGURU_VERBOSE_SCOPE_ENDINGS}") +target_compile_definitions(loguru PUBLIC -DLOGURU_VERBOSE_SCOPE_ENDINGS=${LOGURU_VERBOSE_SCOPE_ENDINGS}) + +message("-- loguru: setting LOGURU_REDEFINE_ASSERT=${LOGURU_REDEFINE_ASSERT}") +target_compile_definitions(loguru PUBLIC -DLOGURU_REDEFINE_ASSERT=${LOGURU_REDEFINE_ASSERT}) + +message("-- loguru: setting LOGURU_WITH_STREAMS=${LOGURU_WITH_STREAMS}") +target_compile_definitions(loguru PUBLIC -DLOGURU_WITH_STREAMS=${LOGURU_WITH_STREAMS}) + +message("-- loguru: setting LOGURU_WITH_FILEABS=${LOGURU_WITH_FILEABS}") +target_compile_definitions(loguru PUBLIC -DLOGURU_WITH_FILEABS=${LOGURU_WITH_FILEABS}) + +message("-- loguru: setting LOGURU_WITH_RTTI=${LOGURU_WITH_RTTI}") +target_compile_definitions(loguru PUBLIC -DLOGURU_WITH_RTTI=${LOGURU_WITH_RTTI}) + +message("-- loguru: setting LOGURU_REPLACE_GLOG=${LOGURU_REPLACE_GLOG}") +target_compile_definitions(loguru PUBLIC -DLOGURU_REPLACE_GLOG=${LOGURU_REPLACE_GLOG}) + +install(TARGETS loguru) diff --git a/recipes/loguru/all/LICENSE.md b/recipes/loguru/all/LICENSE.md new file mode 100644 index 00000000000000..02316c431cd35d --- /dev/null +++ b/recipes/loguru/all/LICENSE.md @@ -0,0 +1,21 @@ +# Loguru + +Loguru logging library for C++, by Emil Ernerfeldt. + + https://github.com/emilk/loguru + +If you find Loguru useful, please let me know on twitter or in a mail! + +- Twitter: @ernerfeldt +- Mail: emil.ernerfeldt@gmail.com +- Website: www.ilikebigbits.com + +# License +This software is in the public domain. Where that dedication is not +recognized, you are granted a perpetual, irrevocable license to +copy, modify and distribute it as you see fit. + +# Inspiration +Much of Loguru was inspired by GLOG, https://code.google.com/p/google-glog/. +The choice of public domain is fully due Sean T. Barrett +and his wonderful stb libraries at https://github.com/nothings/stb. diff --git a/recipes/loguru/all/conandata.yml b/recipes/loguru/all/conandata.yml new file mode 100644 index 00000000000000..58f056e156c68e --- /dev/null +++ b/recipes/loguru/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "2.1.0": + url: "https://github.com/emilk/loguru/archive/refs/tags/v2.1.0.tar.gz" + sha256: "1a3be62ebec5609af60b1e094109a93b7412198b896bb88f31dcfe4d95b79ce7" diff --git a/recipes/loguru/all/conanfile.py b/recipes/loguru/all/conanfile.py new file mode 100644 index 00000000000000..8841623068ab1f --- /dev/null +++ b/recipes/loguru/all/conanfile.py @@ -0,0 +1,147 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout +from conan.tools.files import copy, get +from conan.tools.build import check_min_cppstd + +required_conan_version = ">=1.54.0" + + +def _int(flag): + if flag is not None and flag: + return "1" + else: + return "0" + + +class LoguruConan(ConanFile): + name = "loguru" + version = "2.1.0" + settings = "os", "arch", "compiler", "build_type" + exports_sources = 'CMakeLists.txt' + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/emilk/loguru" + license = "Unlicense" # Public domain + description = "Loguru is a C++11 logging library." + + options = { + "use_fmtlib": [True, False], + "shared": [True, False], + "catch_sigabrt": [True, False], + "verbose_scope_endings": [True, False], + "redefine_assert": [True, False], + "with_streams": [True, False], + "with_fileabs": [True, False], + "with_rtti": [True, False], + "replace_glog": [True, False], + + "scope_text_size": "ANY", # int + "filename_width": "ANY", # int + "threadname_width": "ANY", # int + "scope_time_precision": "ANY", # int + } + + default_options = { + "use_fmtlib": False, + "shared": False, + "catch_sigabrt": True, + "verbose_scope_endings": True, + "redefine_assert": False, + "with_streams": False, + "with_fileabs": False, + "with_rtti": True, + "replace_glog": False, + + "scope_text_size": None, # default: 196 + "filename_width": None, # default: 23 + "threadname_width": None, # default: 16 + "scope_time_precision": None, # 3=ms, 6=us, 9=ns, default: 3 + } + + def build_requirements(self): + self.tool_requires("cmake/3.25.0") + + def requirements(self): + if self.options.use_fmtlib: + self.requires("fmt/9.1.0", transitive_headers=True) + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, 11) + + if self.options.replace_glog: + print("loguru: replace_glog in effect, forcing with_streams=True") + + def source(self): + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) + + def layout(self): + cmake_layout(self) + + def generate(self): + tc = CMakeToolchain(self) + + tc.variables["LOGURU_USE_FMTLIB"] = self.options.use_fmtlib + tc.variables["LOGURU_STATIC"] = not self.options.shared + tc.variables["LOGURU_CATCH_SIGABRT"] = _int(self.options.catch_sigabrt) + tc.variables["LOGURU_VERBOSE_SCOPE_ENDINGS"] = _int(self.options.verbose_scope_endings) + tc.variables["LOGURU_REDEFINE_ASSERT"] = _int(self.options.redefine_assert) + tc.variables["LOGURU_WITH_STREAMS"] = _int(self.options.with_streams) + tc.variables["LOGURU_WITH_FILEABS"] = _int(self.options.with_fileabs) + tc.variables["LOGURU_WITH_RTTI"] = _int(self.options.with_rtti) + tc.variables["LOGURU_REPLACE_GLOG"] = _int(self.options.replace_glog) + + if self.options.scope_text_size: + tc.variables["LOGURU_SCOPE_TEXT_SIZE"] = self.options.scope_text_size + if self.options.filename_width: + tc.variables["LOGURU_FILENAME_WIDTH"] = self.options.filename_width + if self.options.threadname_width: + tc.variables["LOGURU_THREADNAME_WIDTH"] = self.options.threadname_width + if self.options.scope_time_precision: + tc.variables["LOGURU_SCOPE_TIME_PRECISION"] = self.options.scope_time_precision + + tc.generate() + deps = CMakeDeps(self) + deps.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, pattern='LICENSE.md', src=self.source_folder, dst=os.path.join(self.package_folder, 'licenses')) + cmake = CMake(self) + cmake.install() + copy(self, pattern='loguru.hpp', src=self.source_folder, dst=os.path.join(self.package_folder, 'include')) + + def package_info(self): + if self.options.use_fmtlib: + self.cpp_info.components["libloguru"].defines.append("LOGURU_USE_FMTLIB") + self.cpp_info.components["libloguru"].requires = ["fmt::fmt"] + + if self.options.scope_text_size: + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_SCOPE_TEXT_SIZE={self.options.scope_text_size}") + if self.options.filename_width: + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_FILENAME_WIDTH={self.options.filename_width}") + if self.options.threadname_width: + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_THREADNAME_WIDTH={self.options.threadname_width}") + if self.options.scope_time_precision: + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_SCOPE_TIME_PRECISION={self.options.scope_time_precision}") + + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_CATCH_SIGABRT={_int(self.options.catch_sigabrt)}") + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_VERBOSE_SCOPE_ENDINGS={_int(self.options.verbose_scope_endings)}") + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_REDEFINE_ASSERT={_int(self.options.redefine_assert)}") + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_WITH_STREAMS={_int(self.options.with_streams)}") + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_WITH_FILEABS={_int(self.options.with_fileabs)}") + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_WITH_RTTI={_int(self.options.with_rtti)}") + self.cpp_info.components["libloguru"].defines.append(f"LOGURU_REPLACE_GLOG={_int(self.options.replace_glog)}") + + if not self.options.shared: + self.cpp_info.components["libloguru"].defines.append("LOGURU_USE_STATIC") + + self.cpp_info.components["libloguru"].libs = ["loguru"] + + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["libloguru"].system_libs = ["pthread", "dl"] diff --git a/recipes/loguru/all/test_package/CMakeLists.txt b/recipes/loguru/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..aba0bad2842201 --- /dev/null +++ b/recipes/loguru/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +find_package(loguru REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PUBLIC loguru::loguru) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/loguru/all/test_package/conanfile.py b/recipes/loguru/all/test_package/conanfile.py new file mode 100644 index 00000000000000..dd1a55277e1353 --- /dev/null +++ b/recipes/loguru/all/test_package/conanfile.py @@ -0,0 +1,32 @@ +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.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") diff --git a/recipes/loguru/all/test_package/test_package.cpp b/recipes/loguru/all/test_package/test_package.cpp new file mode 100644 index 00000000000000..f446480b57be69 --- /dev/null +++ b/recipes/loguru/all/test_package/test_package.cpp @@ -0,0 +1,38 @@ +#include + +int main(int argc, char** argv) { + loguru::init(argc, argv); + + LOG_SCOPE_F(INFO, "logging scope"); + + LOG_F(INFO, "42=={}", 42); + LOG_F(INFO, "Use fmt? {}", LOGURU_USE_FMTLIB); + LOG_F(INFO, "Scope text size: {}", LOGURU_SCOPE_TEXT_SIZE); + LOG_F(INFO, "Filename width: {}", LOGURU_FILENAME_WIDTH); + LOG_F(INFO, "Threadname width: {}", LOGURU_THREADNAME_WIDTH); + LOG_F(INFO, "Catch sigabrt: {}", LOGURU_CATCH_SIGABRT); + LOG_F(INFO, "Verbose scope endings: {}", LOGURU_VERBOSE_SCOPE_ENDINGS); + LOG_F(INFO, "Redefine assert: {}", LOGURU_REDEFINE_ASSERT); + LOG_F(INFO, "With fileabs: {}", LOGURU_WITH_FILEABS); + LOG_F(INFO, "With rtti: {}", LOGURU_WITH_RTTI); + LOG_F(INFO, "With streams: {}", LOGURU_WITH_STREAMS); + +#if LOGURU_WITH_STREAMS == 1 + { + LOG_SCOPE_F(INFO, "streams"); + LOG_S(INFO) << "log via streams"; + } +#endif + + LOG_F(INFO, "Replace GLog: {}", LOGURU_REPLACE_GLOG); + +#if LOGURU_REPLACE_GLOG == 1 + { + LOG_SCOPE_F(INFO, "replace glog"); + LOG(INFO) << "log via glog api"; + } +#endif + + return 0; +} + diff --git a/recipes/loguru/config.yml b/recipes/loguru/config.yml new file mode 100644 index 00000000000000..dfff490f9a9b60 --- /dev/null +++ b/recipes/loguru/config.yml @@ -0,0 +1,3 @@ +versions: + "2.1.0": + folder: all