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

new recipe log4cpp/1.1.4 #21525

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/log4cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.1.4":
url: "https://sourceforge.net/projects/log4cpp/files/log4cpp-1.1.x%20%28new%29/log4cpp-1.1/log4cpp-1.1.4.tar.gz"
sha256: "696113659e426540625274a8b251052cc04306d8ee5c42a0c7639f39ca90c9d6"
81 changes: 81 additions & 0 deletions recipes/log4cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.files import copy, get, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=1.53.0"


class Log4cppConan(ConanFile):
name = "log4cpp"
description = (
"A library of C++ classes for flexible logging to files (rolling), syslog, "
"IDSA and other destinations. It is modeled after the Log4j Java library, "
"staying as close to their API as is reasonable."
)
license = "LGPL-2.1-or-later"
topics = ("logging", "log", "logging-library")
homepage = "https://log4cpp.sourceforge.net/"
url = "https://github.com/conan-io/conan-center-index"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

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 layout(self):
basic_layout(self, src_folder="src")

def validate(self):
if self.settings.os == "Windows":
raise ConanInvalidConfiguration(
f"{self.ref} recipe doesn't support Windows yet, but it could. Contributions are welcomed."
)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = AutotoolsToolchain(self)
yes_no = lambda v: "yes" if v else "no"
tc.configure_args.extend([
"--enable-debug={}".format(yes_no(self.settings.build_type == "Debug")),
])
tc.generate()

def build(self):
autotools = Autotools(self)
autotools.configure(build_script_folder=os.path.join(self.source_folder, "log4cpp"))
autotools.make()

def package(self):
copy(self, "COPYING", src=os.path.join(self.source_folder, "log4cpp"), dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
autotools.install()
rmdir(self, os.path.join(self.package_folder, "bin"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.set_property("pkg_config_name", "log4cpp")
self.cpp_info.libs = ["log4cpp"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread"])
7 changes: 7 additions & 0 deletions recipes/log4cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(log4cpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE log4cpp::log4cpp)
27 changes: 27 additions & 0 deletions recipes/log4cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

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")
properties = os.path.join(self.source_folder, "log4cpp.properties")
self.run(f"{bin_path} {properties}", env="conanrun")
24 changes: 24 additions & 0 deletions recipes/log4cpp/all/test_package/log4cpp.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
log4cpp.rootCategory=DEBUG, rootAppender
log4cpp.category.sub1=DEBUG, A1, A2
log4cpp.category.sub1.sub2=DEBUG, A3

log4cpp.appender.rootAppender=ConsoleAppender
log4cpp.appender.rootAppender.layout=PatternLayout
log4cpp.appender.rootAppender.layout.ConversionPattern=%d [%p] %m%n

log4cpp.appender.A1=FileAppender
log4cpp.appender.A1.fileName=A1.log
log4cpp.appender.A1.layout=BasicLayout

log4cpp.appender.A2=FileAppender
log4cpp.appender.A2.threshold=WARN
log4cpp.appender.A2.fileName=A2.log
log4cpp.appender.A2.layout=PatternLayout
log4cpp.appender.A2.layout.ConversionPattern=%d [%p] %m%n

log4cpp.appender.A3=RollingFileAppender
log4cpp.appender.A3.fileName=A3.log
log4cpp.appender.A3.maxFileSize=200
log4cpp.appender.A3.maxBackupIndex=1
log4cpp.appender.A3.layout=PatternLayout
log4cpp.appender.A3.layout.ConversionPattern=%d [%p] %m%n
39 changes: 39 additions & 0 deletions recipes/log4cpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <log4cpp/Category.hh>
#include <log4cpp/PropertyConfigurator.hh>

#include <iostream>

int main(int argc, char **argv)
{
if (argc < 2) {
std::cerr << "Need at least one argument" << std::endl;
return 1;
}

log4cpp::PropertyConfigurator::configure(argv[1]);

log4cpp::Category& root = log4cpp::Category::getRoot();

log4cpp::Category& sub1 = log4cpp::Category::getInstance(std::string("sub1"));

log4cpp::Category& sub2 = log4cpp::Category::getInstance(std::string("sub1.sub2"));

root.warn("Storm is coming");

sub1.debug("Received storm warning");
sub1.info("Closing all hatches");

sub2.debug("Hiding solar panels");
sub2.error("Solar panels are blocked");
sub2.debug("Applying protective shield");
sub2.warn("Unfolding protective shield");
sub2.info("Solar panels are shielded");

sub1.info("All hatches closed");

root.info("Ready for storm.");

log4cpp::Category::shutdown();

return 0;
}
3 changes: 3 additions & 0 deletions recipes/log4cpp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.1.4":
folder: all