Skip to content
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

Merged
merged 15 commits into from
Jul 3, 2023
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:
"cci.20230406":
url: "https://github.com/emilk/loguru/archive/4adaa185883e3c04da25913579c451d3c32cfac1.tar.gz"
sha256: "1424f3ce814fa413e5fbdf2949994d455e3914560f958d2931ba869349a686a8"
139 changes: 139 additions & 0 deletions recipes/loguru/all/conanfile.py
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"
uilianries marked this conversation as resolved.
Show resolved Hide resolved
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')
uilianries marked this conversation as resolved.
Show resolved Hide resolved

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"]
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)
31 changes: 31 additions & 0 deletions recipes/loguru/all/test_package/conanfile.py
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")
29 changes: 29 additions & 0 deletions recipes/loguru/all/test_package/test_package.cpp
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!");
}
8 changes: 8 additions & 0 deletions recipes/loguru/all/test_v1_package/CMakeLists.txt
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/)
18 changes: 18 additions & 0 deletions recipes/loguru/all/test_v1_package/conanfile.py
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)
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:
"cci.20230406":
folder: all