Skip to content

Commit

Permalink
Comply to new practices
Browse files Browse the repository at this point in the history
  • Loading branch information
ngrodzitski committed Dec 21, 2022
1 parent 03bb2fa commit 07f07e8
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 98 deletions.
134 changes: 54 additions & 80 deletions recipes/logr/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy, rmdir
from conan.tools.layout import basic_layout
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import check_min_vs, is_msvc
from conan.tools.scm import Version
import os

required_conan_version = ">=1.50.0"

class LogrConan(ConanFile):
name = "logr"
Expand All @@ -14,22 +20,14 @@ class LogrConan(ConanFile):
"for server/desktop applications"
)
topics = ("logger", "development", "util", "utils")
generators = "cmake"

settings = "os", "compiler", "build_type", "arch"
no_copy_source = True

options = {"backend": ["spdlog", "glog", "log4cplus", "boostlog", None]}
default_options = {"backend": "spdlog"}

_cmake = None

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

@property
def _build_subfolder(self):
return "build_subfolder"
def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
if Version(self.version) >= "0.6.0":
Expand All @@ -50,91 +48,67 @@ def requirements(self):
elif self.options.backend == "boostlog":
self.requires("boost/1.77.0")

def configure(self):
minimal_cpp_standard = "17"
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, minimal_cpp_standard)
def package_id(self):
self.info.clear()

if Version(self.version) >= "0.6.0":
minimal_version = {
"gcc": "10",
"clang": "11",
"apple-clang": "12",
"Visual Studio": "19",
}
else:
minimal_version = {
"gcc": "7",
"clang": "7",
"apple-clang": "10",
"Visual Studio": "16",
}

compiler = str(self.settings.compiler)
if compiler not in minimal_version:
self.output.warn(
(
"%s recipe lacks information about the %s compiler "
"standard version support"
def validate(self):
minimal_cpp_standard = "17"
if self.settings.get_safe("compiler.cppstd"):
check_min_cppstd(self, minimal_cpp_standard)
minimal_version = {
"gcc": "10",
"clang": "11",
"apple-clang": "12",
}
check_min_vs(self, 190)
if not is_msvc(self):
minimum_version = minimal_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires minimum {self.settings.compiler}-{minimum_version}."
)
% (self.name, compiler)
)
self.output.warn(
"%s requires a compiler that supports at least C++%s"
% (self.name, minimal_cpp_standard)
)
return

version = tools.Version(self.settings.compiler.version)
if version < minimal_version[compiler]:
raise ConanInvalidConfiguration(
"%s requires a compiler that supports at least C++%s"
% (self.name, minimal_cpp_standard)
)

def _configure_cmake(self):
if self._cmake:
return self._cmake

self._cmake = CMake(self)
self._cmake.definitions["LOGR_WITH_SPDLOG_BACKEND"] = (

def generate(self):
tc = CMakeToolchain(self)
tc.variables["LOGR_WITH_SPDLOG_BACKEND"] = (
self.options.backend == "spdlog"
)
self._cmake.definitions["LOGR_WITH_GLOG_BACKEND"] = (
tc.variables["LOGR_WITH_GLOG_BACKEND"] = (
self.options.backend == "glog"
)
self._cmake.definitions["LOGR_WITH_LOG4CPLUS_BACKEND"] = (
tc.variables["LOGR_WITH_LOG4CPLUS_BACKEND"] = (
self.options.backend == "log4cplus"
)
self._cmake.definitions["LOGR_WITH_BOOSTLOG_BACKEND"] = (
tc.variables["LOGR_WITH_BOOSTLOG_BACKEND"] = (
self.options.backend == "boostlog"
)
tc.variables["LOGR_INSTALL"] = True
tc.variables["LOGR_CONAN_PACKAGING"] = True
tc.variables["LOGR_BUILD_TESTS"] = False
tc.variables["LOGR_BUILD_EXAMPLES"] = False
tc.variables["LOGR_BUILD_BENCHMARKS"] = False
tc.generate()

self._cmake.definitions["LOGR_INSTALL"] = True
self._cmake.definitions["LOGR_CONAN_PACKAGING"] = True
self._cmake.definitions["LOGR_BUILD_TESTS"] = False
self._cmake.definitions["LOGR_BUILD_EXAMPLES"] = False
self._cmake.definitions["LOGR_BUILD_BENCHMARKS"] = False

self._cmake.configure(source_folder=self._source_subfolder)
return self._cmake
deps = CMakeDeps(self)
deps.generate()

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, "logr"))
cmake.install()

tools.rmdir(os.path.join(self.package_folder, "lib"))

def package_id(self):
self.info.settings.clear()
rmdir(self, os.path.join(self.package_folder, "lib"))

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.set_property("cmake_file_name", "logr")

self.cpp_info.names["cmake_find_package"] = "logr"
self.cpp_info.names["cmake_find_package_multi"] = "logr"

Expand Down
15 changes: 4 additions & 11 deletions recipes/logr/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
cmake_minimum_required(VERSION 3.8)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project(PackageTest CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
project(test_package CXX)

find_package(logr REQUIRED)

add_executable(example example.cpp)
target_link_libraries(example logr::logr)
add_executable(${PROJECT_NAME} example.cpp)
target_link_libraries(${PROJECT_NAME} logr::logr)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
22 changes: 15 additions & 7 deletions recipes/logr/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os

from conans import ConanFile, CMake, tools

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

class LogrTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/logr/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(logr REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/example.cpp)
target_link_libraries(${PROJECT_NAME} logr::logr)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
16 changes: 16 additions & 0 deletions recipes/logr/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake, tools
import os


class LogrTestConan(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 tools.cross_building(self):
self.run(os.path.join("bin", "test_package"), run_environment=True)

0 comments on commit 07f07e8

Please sign in to comment.