-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add loguru/2.1.0
recipe
#14543
Add loguru/2.1.0
recipe
#14543
Changes from 1 commit
9db2e89
04e99bc
31578a4
9c1aabf
8c5c095
485b37b
822dbae
b3bca04
bba9e2e
634bf5f
9bdf511
f620f5d
e2495f0
5f791ad
6c7c48b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) |
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" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,149 @@ | ||||||
import os | ||||||
|
||||||
from conan import tools, ConanFile | ||||||
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout | ||||||
from conan.tools.files import copy, get, load, save | ||||||
from conan.tools.build import check_min_cppstd | ||||||
|
||||||
required_conan_version = ">=1.53.0" | ||||||
|
||||||
|
||||||
def _int(flag): | ||||||
if flag is not None and flag: | ||||||
return "1" | ||||||
else: | ||||||
return "0" | ||||||
|
||||||
|
||||||
class LoguruConan(ConanFile): | ||||||
name = "loguru" | ||||||
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 | ||||||
antekone marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
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": [None, "ANY"], | ||||||
"filename_width": [None, "ANY"], | ||||||
"threadname_width": [None, "ANY"], | ||||||
"scope_time_precision": [None, "ANY"] | ||||||
} | ||||||
|
||||||
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") | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
it does not need cmake 3.25 for a very simple library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean I should remove the I mean, it currently uses CMake to build itself. Can I still remove cmake build dependency? |
||||||
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) | ||||||
|
||||||
def source(self): | ||||||
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) | ||||||
|
||||||
def layout(self): | ||||||
cmake_layout(self) | ||||||
uilianries marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
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() | ||||||
|
||||||
@property | ||||||
def _extracted_license(self): | ||||||
tmp = load(self, os.path.join(self.source_folder, 'loguru.hpp')) | ||||||
return tmp[2:tmp.find("# Inspiration", 0)].strip() | ||||||
|
||||||
def package(self): | ||||||
cmake = CMake(self) | ||||||
cmake.install() | ||||||
|
||||||
copy(self, pattern='loguru.hpp', src=self.source_folder, dst=os.path.join(self.package_folder, 'include')) | ||||||
save(self, os.path.join(self.package_folder, 'licenses', 'LICENSE'), self._extracted_license) | ||||||
|
||||||
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"] |
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) |
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") |
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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"2.1.0": | ||
folder: all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, submit this cmake script to the upstream first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upstream already has a PR related to adding full CMake build: emilk/loguru#215, but it's not merged since April.
I can use the CMake script from this un-merged PR. But in the meantime I've decided to use a minimal own CMake script only for Conan package, and migrate to the "official" CMake build once upstream's PR-215 will be merged.