Skip to content

Commit

Permalink
Add loguru/2.1.0 recipe
Browse files Browse the repository at this point in the history
Loguru: a lightweight and flexible C++ logging library.

Website: https://emilk.github.io/loguru/index.html
Source code: https://github.com/emilk/loguru

Closes conan-io#14542
  • Loading branch information
antekone committed Dec 2, 2022
1 parent 9ad4484 commit f19f72b
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 0 deletions.
63 changes: 63 additions & 0 deletions recipes/loguru/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions recipes/loguru/all/LICENSE.md
Original file line number Diff line number Diff line change
@@ -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: [email protected]
- 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.
4 changes: 4 additions & 0 deletions recipes/loguru/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.1.0":
url: "https://github.com/emilk/loguru/archive/refs/tags/v2.1.0.tar.gz"
sha256: "1a3be62ebec5609af60b1e094109a93b7412198b896bb88f31dcfe4d95b79ce7"
147 changes: 147 additions & 0 deletions recipes/loguru/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions recipes/loguru/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 32 additions & 0 deletions recipes/loguru/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
38 changes: 38 additions & 0 deletions recipes/loguru/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <loguru.hpp>

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;
}

3 changes: 3 additions & 0 deletions recipes/loguru/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.1.0":
folder: all

0 comments on commit f19f72b

Please sign in to comment.