forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(conan-io#14543) Add
loguru/2.1.0
recipe
* 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 conan-io#14542 * Simplify CMake and native features usage (#1) Simplifications and Conan v2 fixes * Update recipes/loguru/all/conanfile.py * Update recipes/loguru/all/conanfile.py * Update recipes/loguru/all/conanfile.py * loguru: use latest commit with CMake support * fixup: missing comma * fixup: typo * chore: rm config files * fixup: clean up defines * add includedirs, simplify test_package * add suffix * add m * fix windows shared * remove pdbs --------- Co-authored-by: Uilian Ries <[email protected]> Co-authored-by: Chris Mc <[email protected]> Co-authored-by: czoido <[email protected]>
- Loading branch information
1 parent
7f46775
commit 31f8c57
Showing
8 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"cci.20230406": | ||
url: "https://github.com/emilk/loguru/archive/4adaa185883e3c04da25913579c451d3c32cfac1.tar.gz" | ||
sha256: "1424f3ce814fa413e5fbdf2949994d455e3914560f958d2931ba869349a686a8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout | ||
from conan.tools.microsoft import is_msvc | ||
from conan.tools.files import get, load, save, rmdir, rm | ||
from conan.tools.build import check_min_cppstd | ||
|
||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class LoguruConan(ConanFile): | ||
name = "loguru" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/emilk/loguru" | ||
license = "Unlicense" | ||
topics = ("logging", "log", "fmt") | ||
description = "Loguru is a C++11 logging library." | ||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"with_fmt": [True, False], | ||
"verbose_scope_endings": [True, False], | ||
"redefine_assert": [True, False], | ||
"enable_streams": [True, False], | ||
"enable_fileabs": [True, False], | ||
"replace_glog": [True, False], | ||
|
||
"scope_text_size": [None, "ANY"], | ||
"scope_time_precision": [None, "ANY"], | ||
"filename_width": [None, "ANY"], | ||
"threadname_width": [None, "ANY"], | ||
} | ||
|
||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"with_fmt": False, | ||
"verbose_scope_endings": True, | ||
"redefine_assert": False, | ||
"enable_streams": False, | ||
"enable_fileabs": False, | ||
"replace_glog": False, | ||
"scope_text_size": 196, | ||
"scope_time_precision": 3, | ||
"filename_width": 23, | ||
"threadname_width": 16, | ||
} | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
|
||
def requirements(self): | ||
if self.options.with_fmt: | ||
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 and not self.options.enable_streams: | ||
# https://github.com/emilk/loguru/blob/4adaa185883e3c04da25913579c451d3c32cfac1/docs/index.html#L692 | ||
raise ConanInvalidConfiguration(f"{self.ref}:replace_glog needs {self.ref}:enable_streams=True") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder='src') | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["LOGURU_USE_FMTLIB"] = self.options.with_fmt | ||
tc.variables["LOGURU_VERBOSE_SCOPE_ENDINGS"] = self.options.verbose_scope_endings | ||
tc.variables["LOGURU_REDEFINE_ASSERT"] = self.options.redefine_assert | ||
tc.variables["LOGURU_WITH_STREAMS"] = self.options.enable_streams | ||
tc.variables["LOGURU_WITH_FILEABS"] = self.options.enable_fileabs | ||
tc.variables["LOGURU_REPLACE_GLOG"] = self.options.replace_glog | ||
tc.variables["LOGURU_SCOPE_TEXT_SIZE"] = self.options.scope_text_size | ||
tc.variables["LOGURU_SCOPE_TIME_PRECISION"] = self.options.scope_time_precision | ||
tc.variables["LOGURU_FILENAME_WIDTH"] = self.options.filename_width | ||
tc.variables["LOGURU_THREADNAME_WIDTH"] = self.options.threadname_width | ||
if is_msvc(self) and self.options.shared: | ||
tc.preprocessor_definitions["LOGURU_EXPORT"] = "__declspec(dllexport)" | ||
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): | ||
save(self, os.path.join(self.package_folder, 'licenses', 'LICENSE'), self._extracted_license) | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) | ||
|
||
def package_info(self): | ||
suffix = "d" if self.settings.build_type == "Debug" else "" | ||
self.cpp_info.libs = [f"loguru{suffix}"] | ||
self.cpp_info.includedirs = [os.path.join("include", "loguru")] | ||
# https://github.com/emilk/loguru/blob/4adaa185883e3c04da25913579c451d3c32cfac1/CMakeLists.txt#L301 | ||
self.cpp_info.set_property("cmake_file_name", "loguru") | ||
self.cpp_info.set_property("cmake_target_name", "loguru::loguru") | ||
|
||
self.cpp_info.defines.append(f"LOGURU_USE_FMTLIB={self.options.with_fmt}") | ||
self.cpp_info.defines.append(f"LOGURU_SCOPE_TEXT_SIZE={self.options.scope_text_size}") | ||
self.cpp_info.defines.append(f"LOGURU_SCOPE_TIME_PRECISION={self.options.scope_time_precision}") | ||
self.cpp_info.defines.append(f"LOGURU_FILENAME_WIDTH={self.options.filename_width}") | ||
self.cpp_info.defines.append(f"LOGURU_THREADNAME_WIDTH={self.options.threadname_width}") | ||
self.cpp_info.defines.append(f"LOGURU_VERBOSE_SCOPE_ENDINGS={self.options.verbose_scope_endings}") | ||
self.cpp_info.defines.append(f"LOGURU_REDEFINE_ASSERT={self.options.redefine_assert}") | ||
self.cpp_info.defines.append(f"LOGURU_WITH_STREAMS={self.options.enable_streams}") | ||
self.cpp_info.defines.append(f"LOGURU_WITH_FILEABS={self.options.enable_fileabs}") | ||
self.cpp_info.defines.append(f"LOGURU_REPLACE_GLOG={self.options.replace_glog}") | ||
|
||
if self.settings.os in ["Linux", "FreeBSD"]: | ||
self.cpp_info.system_libs = ["pthread", "dl", "m"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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.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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Partially taken from: https://github.com/emilk/loguru/tree/master/loguru_example | ||
|
||
#include <iostream> | ||
#include <loguru.hpp> | ||
#include <chrono> | ||
#include <thread> | ||
|
||
inline void sleep_ms(int ms) | ||
{ | ||
VLOG_F(2, "Sleeping for %d ms", ms); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(ms)); | ||
} | ||
|
||
inline void complex_calculation() | ||
{ | ||
LOG_SCOPE_F(INFO, "complex_calculation"); | ||
LOG_F(INFO, "Starting time machine..."); | ||
LOG_F(WARNING, "The flux capacitor is not getting enough power!"); | ||
LOG_F(INFO, "Lighting strike!"); | ||
VLOG_F(1, "Found 1.21 gigawatts..."); | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
loguru::init(argc, argv); | ||
LOG_F(INFO, "Hello from main.cpp!"); | ||
complex_calculation(); | ||
LOG_F(INFO, "main function about to end!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ | ||
${CMAKE_CURRENT_BINARY_DIR}/test_package/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from conans import ConanFile, CMake | ||
from conan.tools.build import cross_building | ||
import os | ||
|
||
|
||
class TestPackageV1Conan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "cmake", "cmake_find_package_multi" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not cross_building(self): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"cci.20230406": | ||
folder: all |