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 package cpplogging #14043

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
11 changes: 11 additions & 0 deletions recipes/cpplogging/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.4)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

if(WIN32 AND BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

add_subdirectory(source_subfolder)
20 changes: 20 additions & 0 deletions recipes/cpplogging/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sources:
"1.0.0.0":
url: "https://github.com/chronoxor/CppLogging/archive/refs/tags/1.0.0.0.tar.gz"
sha256: "c19843a7e6cbe828f8ceb01a3e2289f0e12ac528762e91175051f762325217ea"
"1.0.1.0":
url: "https://github.com/chronoxor/CppLogging/archive/refs/tags/1.0.1.0.tar.gz"
sha256: "46247873f8137ff1511222a85f34a8d54d5f804a93e3f04c6476bf61d8db7113"
"1.0.3.0":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need all these three versions? Otherwise, please, keep only the latest. We want to avoid more and more versions which are outdated and not downloaded. They cost CI time, resources and storage.

url: "https://github.com/chronoxor/CppLogging/archive/refs/tags/1.0.3.0.tar.gz"
sha256: "5aceac3951430535e542ab7ffb42eb32f90c52b1d16130ae3f8bb56074aca589"
patches:
"1.0.0.0":
- patch_file: "patches/0001-cmake-clean-up-1-0-0-0.patch"
base_path: "source_subfolder"
"1.0.1.0":
- patch_file: "patches/0001-cmake-clean-up-1-0-0-0.patch"
base_path: "source_subfolder"
"1.0.3.0":
- patch_file: "patches/0001-cmake-clean-up-1-0-3-0.patch"
base_path: "source_subfolder"
100 changes: 100 additions & 0 deletions recipes/cpplogging/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from conans import CMake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is a new recipe I would be really appreciated if you used the newer build helpers

This is deprecated and will be removed soon... you can see the template for a good example

from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the template, I'll look at it.
I left that one line because I struggled a bit when I tried to remove it and could not make the recipe to work.

from conan import ConanFile
from conan.tools import scm, build, files
from conan.errors import ConanInvalidConfiguration
import os
import glob


class CpploggingConan(ConanFile):
name = "cpplogging"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/chronoxor/CppLogging"
description = "C++ Logging Library provides functionality to log different events with a high" \
" throughput in multithreaded environment into different sinks (console, files, rolling files," \
" syslog, etc.). Logging configuration is very flexible and gives functionality to build flexible"\
" logger hierarchy with combination of logging processors (sync, async), filters, layouts (binary,"\
" hash, text) and appenders."
topics = ("performance", "logging", "speed", "logging-library", "low-latency")
settings = "os", "compiler", "build_type", "arch"
options = {"fPIC": [True, False],
"shared": [True, False]}
default_options = {"fPIC": True,
"shared": False}
generators = "cmake", "cmake_find_package"
exports_sources = ["patches/**", "CMakeLists.txt"]
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["CPPLOGGING_MODULE"] = "OFF"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self._cmake.definitions["CPPLOGGING_MODULE"] = "OFF"
self._cmake.definitions["CPPLOGGING_MODULE"] = False
self._cmake.definitions["BUILD_TESTING"] = False

Enforce disabling tests

self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

@property
def _compilers_minimum_version(self):
return {
"gcc": "9",
"Visual Studio": "15",
"clang": "5",
"apple-clang": "10",
}

def requirements(self):
self.requires("zlib/1.2.13")
if self.version < "1.0.3.0" :
self.requires("cppcommon/1.0.2.0")
else:
self.requires("cppcommon/1.0.3.0")

def configure(self):
if self.options.shared:
del self.options.fPIC

if self.settings.compiler.get_safe("cppstd"):
build.check_min_cppstd(self, "17")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking over the project is does not say this and the GitHub actions build without it so I am surprsed to see this here 🤔

Can you share why you are adding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project uses std::string_view which was added to the stl in C++17.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, but it should be pointed by the upstream, there is no reference about C++ standard there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just created the PR chronoxor/CppLogging#5 to enforce the standard as requirement.


minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)

if not minimum_version:
self.output.warn("cpplogging requires C++17. Your compiler is unknown. Assuming it supports C++17.")
elif scm.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("cpplogging requires a compiler that supports at least C++17")
EmilienBINET marked this conversation as resolved.
Show resolved Hide resolved

def source(self):
files.get(self, **self.conan_data["sources"][self.version])
extracted_dir = glob.glob("CppLogging-*")[0]
os.rename(extracted_dir, self._source_subfolder)
Comment on lines +76 to +78
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
files.get(self, **self.conan_data["sources"][self.version])
extracted_dir = glob.glob("CppLogging-*")[0]
os.rename(extracted_dir, self._source_subfolder)
files.get(self, **self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)


def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
files.patch(self, **patch)

Comment on lines +85 to +87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for patch in self.conan_data.get("patches", {}).get(self.version, []):
files.patch(self, **patch)
apply_conandata_patches(self)

Need to update imports too:
https://docs.conan.io/en/latest/reference/conanfile/tools/files/patches.html?highlight=apply_conandata_patches

cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
self.copy(pattern="*.inl", dst="include", src=os.path.join(self._source_subfolder, "include"))

def package_info(self):
self.cpp_info.libs = files.collect_libs(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.cpp_info.libs = files.collect_libs(self)
self.cpp_info.libs = ["cpplogging"]

Avoid collect_libs, it does not respect linkage order and hides which libraries should be packaged.

if self.settings.os == "Windows":
self.cpp_info.system_libs = ["ws2_32", "crypt32", "mswsock"]
103 changes: 103 additions & 0 deletions recipes/cpplogging/all/patches/0001-cmake-clean-up-1-0-0-0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt 2021-12-19 20:42:05.000000000 +0100
+++ b/CMakeLists.txt 2022-11-02 16:17:59.870658464 +0100
@@ -17,20 +17,8 @@
endif()
endif()

-# CMake module path
-set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
-
-# Compiler features
-include(SetCompilerFeatures)
-include(SetCompilerWarnings)
-include(SetPlatformFeatures)
-include(SystemInformation)
-
-# Modules
-add_subdirectory("modules")
-
# Link libraries
-list(APPEND LINKLIBS cppcommon)
+list(APPEND LINKLIBS CONAN_PKG::cppcommon)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+list(APPEND LINKLIBS CONAN_PKG::cppcommon)

CONAN_PKG is deprecated, please, take a look on CMakeDeps generator instead.


# Support zlib/contrib/minizip
file(GLOB_RECURSE MINIZIP_FILES "source/logging/appenders/minizip/*.c")
@@ -60,14 +48,16 @@
target_compile_definitions(cpplogging PRIVATE USE_FILE32API=1)
endif()
target_include_directories(cpplogging PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
-target_link_libraries(cpplogging ${LINKLIBS} zlib)
+target_link_libraries(cpplogging ${LINKLIBS} CONAN_PKG::zlib)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

list(APPEND INSTALL_TARGETS cpplogging)
list(APPEND LINKLIBS cpplogging)
+target_compile_features(cpplogging PRIVATE cxx_std_17)

# Additional module components: benchmarks, examples, plugins, tests, tools and install
if(NOT CPPLOGGING_MODULE)

# Examples
+ if(FALSE)
file(GLOB EXAMPLE_HEADER_FILES "examples/*.h")
file(GLOB EXAMPLE_INLINE_FILES "examples/*.inl")
file(GLOB EXAMPLE_SOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/examples" "examples/*.cpp")
@@ -80,8 +70,10 @@
list(APPEND INSTALL_TARGETS ${EXAMPLE_TARGET})
list(APPEND INSTALL_TARGETS_PDB ${EXAMPLE_TARGET})
endforeach()
+ endif()

# Benchmarks
+ if(FALSE)
file(GLOB BENCHMARK_HEADER_FILES "performance/*.h")
file(GLOB BENCHMARK_INLINE_FILES "performance/*.inl")
file(GLOB BENCHMARK_SOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/performance" "performance/*.cpp")
@@ -94,8 +86,10 @@
list(APPEND INSTALL_TARGETS ${BENCHMARK_TARGET})
list(APPEND INSTALL_TARGETS_PDB ${BENCHMARK_TARGET})
endforeach()
+ endif()

# Tools
+ if(FALSE)
file(GLOB TOOLS_DIRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/tools" "tools/*")
foreach(TOOLS_DIR ${TOOLS_DIRS})
file(GLOB_RECURSE TOOLS_HEADER_FILES "tools/${TOOLS_DIR}/*.h")
@@ -108,8 +102,10 @@
list(APPEND INSTALL_TARGETS ${TOOL_TARGET})
list(APPEND INSTALL_TARGETS_PDB ${TOOL_TARGET})
endforeach()
+ endif()

# Tests
+ if(FALSE)
file(GLOB TESTS_HEADER_FILES "tests/*.h")
file(GLOB TESTS_INLINE_FILES "tests/*.inl")
file(GLOB TESTS_SOURCE_FILES "tests/*.cpp")
@@ -119,19 +115,22 @@
target_link_libraries(cpplogging-tests ${LINKLIBS})
list(APPEND INSTALL_TARGETS cpplogging-tests)
list(APPEND INSTALL_TARGETS_PDB cpplogging-tests)
+ endif()

# CTest
+ if(FALSE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ if(FALSE)

Use BUILD_TESTING instead.
https://cmake.org/cmake/help/latest/command/add_test.html

enable_testing()
add_test(cpplogging-tests cpplogging-tests --durations yes --order lex)
+ endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ endif()


# Install
install(TARGETS ${INSTALL_TARGETS}
- RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin"
- LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/bin"
- ARCHIVE DESTINATION "${PROJECT_SOURCE_DIR}/bin")
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)

# Install *.pdb files
- if(MSVC)
+ if(FALSE)
foreach(INSTALL_TARGET_PDB ${INSTALL_TARGETS_PDB})
install(FILES $<TARGET_PDB_FILE:${INSTALL_TARGET_PDB}> DESTINATION "${PROJECT_SOURCE_DIR}/bin")
endforeach()
109 changes: 109 additions & 0 deletions recipes/cpplogging/all/patches/0001-cmake-clean-up-1-0-3-0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt 2021-12-19 20:42:05.000000000 +0100
+++ b/CMakeLists.txt 2022-11-02 16:17:59.870658464 +0100
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.20)
+cmake_minimum_required(VERSION 3.18.2)

# Global properties
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
@@ -17,20 +17,8 @@
endif()
endif()

-# CMake module path
-set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
-
-# Compiler features
-include(SetCompilerFeatures)
-include(SetCompilerWarnings)
-include(SetPlatformFeatures)
-include(SystemInformation)
-
-# Modules
-add_subdirectory("modules")
-
# Link libraries
-list(APPEND LINKLIBS cppcommon)
+list(APPEND LINKLIBS CONAN_PKG::cppcommon)

# Support zlib/contrib/minizip
file(GLOB_RECURSE MINIZIP_FILES "source/logging/appenders/minizip/*.c")
@@ -60,14 +48,16 @@
target_compile_definitions(cpplogging PRIVATE USE_FILE32API=1)
endif()
target_include_directories(cpplogging PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
-target_link_libraries(cpplogging ${LINKLIBS} zlib)
+target_link_libraries(cpplogging ${LINKLIBS} CONAN_PKG::zlib)
list(APPEND INSTALL_TARGETS cpplogging)
list(APPEND LINKLIBS cpplogging)
+target_compile_features(cpplogging PRIVATE cxx_std_17)

# Additional module components: benchmarks, examples, plugins, tests, tools and install
if(NOT CPPLOGGING_MODULE)

# Examples
+ if(FALSE)
file(GLOB EXAMPLE_HEADER_FILES "examples/*.h")
file(GLOB EXAMPLE_INLINE_FILES "examples/*.inl")
file(GLOB EXAMPLE_SOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/examples" "examples/*.cpp")
@@ -80,8 +70,10 @@
list(APPEND INSTALL_TARGETS ${EXAMPLE_TARGET})
list(APPEND INSTALL_TARGETS_PDB ${EXAMPLE_TARGET})
endforeach()
+ endif()

# Benchmarks
+ if(FALSE)
file(GLOB BENCHMARK_HEADER_FILES "performance/*.h")
file(GLOB BENCHMARK_INLINE_FILES "performance/*.inl")
file(GLOB BENCHMARK_SOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/performance" "performance/*.cpp")
@@ -94,8 +86,10 @@
list(APPEND INSTALL_TARGETS ${BENCHMARK_TARGET})
list(APPEND INSTALL_TARGETS_PDB ${BENCHMARK_TARGET})
endforeach()
+ endif()

# Tools
+ if(FALSE)
file(GLOB TOOLS_DIRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/tools" "tools/*")
foreach(TOOLS_DIR ${TOOLS_DIRS})
file(GLOB_RECURSE TOOLS_HEADER_FILES "tools/${TOOLS_DIR}/*.h")
@@ -108,8 +102,10 @@
list(APPEND INSTALL_TARGETS ${TOOL_TARGET})
list(APPEND INSTALL_TARGETS_PDB ${TOOL_TARGET})
endforeach()
+ endif()

# Tests
+ if(FALSE)
file(GLOB TESTS_HEADER_FILES "tests/*.h")
file(GLOB TESTS_INLINE_FILES "tests/*.inl")
file(GLOB TESTS_SOURCE_FILES "tests/*.cpp")
@@ -119,19 +115,22 @@
target_link_libraries(cpplogging-tests ${LINKLIBS})
list(APPEND INSTALL_TARGETS cpplogging-tests)
list(APPEND INSTALL_TARGETS_PDB cpplogging-tests)
+ endif()

# CTest
+ if(FALSE)
enable_testing()
add_test(cpplogging-tests cpplogging-tests --durations yes --order lex)
+ endif()

# Install
install(TARGETS ${INSTALL_TARGETS}
- RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin"
- LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/bin"
- ARCHIVE DESTINATION "${PROJECT_SOURCE_DIR}/bin")
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)

# Install *.pdb files
- if(MSVC)
+ if(FALSE)
foreach(INSTALL_TARGET_PDB ${INSTALL_TARGETS_PDB})
install(FILES $<TARGET_PDB_FILE:${INSTALL_TARGET_PDB}> DESTINATION "${PROJECT_SOURCE_DIR}/bin")
endforeach()
9 changes: 9 additions & 0 deletions recipes/cpplogging/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

find_package(cpplogging CONFIG REQUIRED)

add_executable(console src/console.cpp)
target_link_libraries(console cpplogging::cpplogging)

target_compile_features(console PRIVATE cxx_std_17)
30 changes: 30 additions & 0 deletions recipes/cpplogging/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import cross_building
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from conan.tools.build import cross_building
from conan.tools.build import can_run

https://docs.conan.io/en/latest/reference/conanfile/tools/build.html?highlight=can_run#conan-tools-build-can-run



class CpploggingTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
# VirtualBuildEnv and VirtualRunEnv can be avoided if "tools.env.virtualenv:auto_use" is defined
# (it will be defined in Conan 2.0)
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv", "VirtualRunEnv"
apply_env = False
Comment on lines +10 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# VirtualBuildEnv and VirtualRunEnv can be avoided if "tools.env.virtualenv:auto_use" is defined
# (it will be defined in Conan 2.0)
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv", "VirtualRunEnv"
apply_env = False
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"

You are not testing a build tool

test_type = "explicit"

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

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def layout(self):
cmake_layout(self)

def test(self):
if not cross_building(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not cross_building(self):
if can_run(self):

cmd = os.path.join(self.cpp.build.bindirs[0], "console")
self.run(cmd, env="conanrun")
Loading