Skip to content

Commit

Permalink
(#12700) sdbus-cpp: conan v2 support
Browse files Browse the repository at this point in the history
* sdbus-cpp/all: Update requirements/build_requirements

* sdbus-cpp/all: Fix TOOLS CROSS BUILDING (KB-H062) warning

WARN: [TOOLS CROSS BUILDING (KB-H062)] The
'tools.cross_building(self.settings)' syntax may not work correctly in
some scenarios. Consider using tools.cross_building(self).

* sdbus-cpp/all: Fix INVALID TOPICS (KB-H064) warning

WARN: [INVALID TOPICS (KB-H064)] The topic 'conan' is invalid and
should be removed from topics attribute.

* sdbus-cpp/all: Add pkg-config test

sdbus-cpp officially supports pkg-config, so we need to test it.

* sdbus-cpp/all: Add conan v2 support

* sdbus-cpp/all: Make a little cleanup and apply CCI recommendations

* sdbus-cpp/all: Add missing system libs

The math library was probably just missing. And the pthread library
was always implicitly inherited from libsystemd dependency.

* sdbus-cpp/all: Add information about LGPL exceptions for header files

Since version 0.9.0, sdbus-c++ has an additional license with an
exception for the template code in the header files. Basically it is a
fork of Qt LGPL exception 1.1.

* sdbus-cpp/all: Apply suggestions from code review

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* sdbus-cpp/all: Apply test packages review suggestions

* sdbus-cpp/all: Use conan.tools in test packages

Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
bobrofon and uilianries authored Sep 5, 2022
1 parent d8863a9 commit 9f82ea9
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 90 deletions.
7 changes: 0 additions & 7 deletions recipes/sdbus-cpp/all/CMakeLists.txt

This file was deleted.

32 changes: 18 additions & 14 deletions recipes/sdbus-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
sources:
"0.8.3":
url: "https://github.com/Kistler-Group/sdbus-cpp/archive/v0.8.3.tar.gz"
sha256: "0fd575ae0f463773dd9141242d1133731e2b780fd6526650ce992ba711d88628"
"1.0.0":
url: "https://github.com/Kistler-Group/sdbus-cpp/archive/v1.0.0.tar.gz"
sha256: "3db82112c0d8a171a4115d761e3a592b62091fa7600988736652595178ae4e94"
"1.2.0":
url: "https://github.com/Kistler-Group/sdbus-cpp/archive/v1.2.0.tar.gz"
sha256: "7f7231904abb6a996b8c18ddc5fb50078ef5dff5191649abf9f127aff41d24e9"
"1.1.0":
url: "https://github.com/Kistler-Group/sdbus-cpp/archive/v1.1.0.tar.gz"
sha256: "35e939fdd9c796522702c9c8762dd59b5c47f3440c01ba9feb9921c042780b55"
"1.0.0":
url: "https://github.com/Kistler-Group/sdbus-cpp/archive/v1.0.0.tar.gz"
sha256: "3db82112c0d8a171a4115d761e3a592b62091fa7600988736652595178ae4e94"
"0.8.3":
url: "https://github.com/Kistler-Group/sdbus-cpp/archive/v0.8.3.tar.gz"
sha256: "0fd575ae0f463773dd9141242d1133731e2b780fd6526650ce992ba711d88628"

"1.2.0":
url: "https://github.com/Kistler-Group/sdbus-cpp/archive/v1.2.0.tar.gz"
sha256: "7f7231904abb6a996b8c18ddc5fb50078ef5dff5191649abf9f127aff41d24e9"
patches:
"0.8.3":
- base_path: "source_subfolder"
patch_file: "patches/0001-xml2cpp-Add-missing-EXPAT-include-dirs-136.patch"
"1.0.0":
- base_path: "source_subfolder"
patch_file: "patches/0002-correct-readme-cpack-resource-path.patch"
- patch_file: "patches/0002-correct-readme-cpack-resource-path.patch"
patch_description: "fix out of tree build by using proper paths in cmake file"
patch_type: "backport"
patch_source: "https://github.com/Kistler-Group/sdbus-cpp/commit/0b8f2d97524f354bcaf816b27b6139a5b0c480ba"
"0.8.3":
- patch_file: "patches/0001-xml2cpp-Add-missing-EXPAT-include-dirs-136.patch"
patch_description: "fix build error by adding missing headers"
patch_type: "backport"
patch_source: "https://github.com/Kistler-Group/sdbus-cpp/commit/fb008445b15b452f461c34667f4991f5ce06e481"
128 changes: 73 additions & 55 deletions recipes/sdbus-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import os

from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, get, rmdir
from conan.tools.scm import Version

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.51.0"


class SdbusCppConan(ConanFile):
name = "sdbus-cpp"
license = "LGPL-2.1-or-later"
license = "LicenseRef-LGPL-2.1-or-later-WITH-sdbus-cpp-LGPL-exception-1.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/Kistler-Group/sdbus-cpp"
description = "High-level C++ D-Bus library for Linux designed" \
" to provide easy-to-use yet powerful API in modern C++"
topics = ("conan", "dbus", "sd-bus", "sdbus-c++", "sdbus-cpp")
topics = ("dbus", "sd-bus", "sdbus-c++")
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
Expand All @@ -25,17 +29,7 @@ class SdbusCppConan(ConanFile):
"fPIC": True,
"with_code_gen": False,
}
exports_sources = ("CMakeLists.txt", "patches/**")
generators = ("cmake", "pkg_config")
_cmake = None

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

@property
def _build_subfolder(self):
return "build_subfolder"
generators = "PkgConfigDeps"

@property
def _minimum_cpp_standard(self):
Expand All @@ -48,74 +42,98 @@ def _minimum_compilers_version(self):
"clang": "6",
}

def export_sources(self):
for p in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, p["patch_file"], self.recipe_folder,
self.export_sources_folder)

def configure(self):
if Version(self.version) < "0.9.0":
self.license = "LGPL-2.1-or-later"

if self.options.shared:
del self.options.fPIC

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(str(self.info.settings.compiler))
if not min_version:
self.output.warn("{} recipe lacks information about the {} compiler support.".format(
self.name, self.settings.compiler))
self.name, self.info.settings.compiler))
else:
if tools.Version(self.settings.compiler.version) < min_version:
if Version(self.info.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration("{} requires C++{} support. The current compiler {} {} does not support it.".format(
self.name, self._minimum_cpp_standard, self.settings.compiler, self.settings.compiler.version))
if self.settings.os != "Linux":
self.name, self._minimum_cpp_standard, self.info.settings.compiler, self.info.settings.compiler.version))
if self.info.settings.os != "Linux":
raise ConanInvalidConfiguration("Only Linux supported")

def build_requirements(self):
self.build_requires("pkgconf/1.7.4")
self.tool_requires("pkgconf/1.7.4")
if self.options.with_code_gen:
self.build_requires("expat/2.4.1")
self.tool_requires("expat/2.4.8")

def requirements(self):
self.requires("libsystemd/249.4")
self.requires("libsystemd/251.4")

def layout(self):
cmake_layout(self, src_folder="src")

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_CODE_GEN"] = self.options.with_code_gen
self._cmake.definitions["BUILD_DOC"] = False
self._cmake.definitions["BUILD_TESTS"] = False
self._cmake.definitions["BUILD_LIBSYSTEMD"] = False
self._cmake.configure()
return self._cmake

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_CODE_GEN"] = self.options.with_code_gen
tc.variables["BUILD_DOC"] = False
tc.variables["BUILD_TESTS"] = False
tc.variables["BUILD_LIBSYSTEMD"] = False
tc.generate()

# workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/18150
copy(self, "*.pc", self.generators_folder,
os.path.join(self.generators_folder, "lib", "pkgconfig"))

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.install()
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
copy(self, "COPYING*", self.source_folder,
os.path.join(self.package_folder, "licenses"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "sdbus-c++")
self.cpp_info.components["sdbus-c++"].libs = ["sdbus-c++"]
self.cpp_info.components["sdbus-c++"].requires.append(
"libsystemd::libsystemd")
self.cpp_info.components["sdbus-c++"].set_property(
"cmake_target_name", "SDBusCpp::sdbus-c++")
self.cpp_info.components["sdbus-c++"].set_property(
"pkg_config_name", "sdbus-c++")
self.cpp_info.components["sdbus-c++"].system_libs = [
"pthread", "m"]

if self.options.with_code_gen:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH env var with : {}".format(bin_path))
self.buildenv_info.prepend_path("PATH", bin_path)

# TODO: Remove in Conan 2.0 where Environment class will be required.
self.env_info.PATH.append(bin_path)

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "SDBusCpp"
self.cpp_info.names["cmake_find_package_multi"] = "SDBusCpp"
self.cpp_info.filenames["cmake_find_package"] = "sdbus-c++"
self.cpp_info.filenames["cmake_find_package_multi"] = "sdbus-c++"
self.cpp_info.components["sdbus-c++"].libs = ["sdbus-c++"]
self.cpp_info.components["sdbus-c++"].requires.append("libsystemd::libsystemd")
self.cpp_info.components["sdbus-c++"].names["cmake_find_package"] = "sdbus-c++"
self.cpp_info.components["sdbus-c++"].names["cmake_find_package_multi"] = "sdbus-c++"
self.cpp_info.components["sdbus-c++"].names["pkg_config"] = "sdbus-c++"
if self.options.with_code_gen:
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH env var with : {}".format(bin_path))
self.env_info.PATH.append(bin_path)
7 changes: 2 additions & 5 deletions recipes/sdbus-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(PackageTest CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
cmake_minimum_required(VERSION 3.15)
project(PackageTest LANGUAGES CXX)

find_package(sdbus-c++ REQUIRED)

Expand Down
19 changes: 14 additions & 5 deletions recipes/sdbus-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import os

from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout


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

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.settings):
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], "example")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/sdbus-cpp/all/test_pkgconf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest LANGUAGES CXX)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SDBusCpp REQUIRED IMPORTED_TARGET sdbus-c++)

add_executable(example ../test_package/example.cpp)
target_link_libraries(example PRIVATE PkgConfig::SDBusCpp)
36 changes: 36 additions & 0 deletions recipes/sdbus-cpp/all/test_pkgconf/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.files import copy


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

def build_requirements(self):
self.tool_requires("pkgconf/1.7.4")

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

def layout(self):
cmake_layout(self)

def generate(self):
# workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/18150
copy(self, "*.pc", self.generators_folder,
os.path.join(self.generators_folder, "lib", "pkgconfig"))

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], "example")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/sdbus-cpp/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.13)
project(PackageTest CXX)

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

find_package(sdbus-c++ REQUIRED)

add_executable(example ../test_package/example.cpp)
target_link_libraries(example SDBusCpp::sdbus-c++)
21 changes: 21 additions & 0 deletions recipes/sdbus-cpp/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

from conan import ConanFile
from conan.tools.build import can_run

from conans import CMake


class SdbusCppTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = ("cmake", "cmake_find_package")

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

def test(self):
if can_run(self):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
11 changes: 11 additions & 0 deletions recipes/sdbus-cpp/all/test_v1_pkgconf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.13)
project(PackageTest CXX)

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

find_package(PkgConfig REQUIRED)
pkg_check_modules(SDBusCpp REQUIRED IMPORTED_TARGET sdbus-c++)

add_executable(example ../test_package/example.cpp)
target_link_libraries(example PRIVATE PkgConfig::SDBusCpp)
24 changes: 24 additions & 0 deletions recipes/sdbus-cpp/all/test_v1_pkgconf/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

from conan import ConanFile
from conan.tools.build import can_run

from conans import CMake


class SdbusCppTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = ("cmake", "pkg_config")

def build_requirements(self):
self.tool_requires("pkgconf/1.7.4")

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

def test(self):
if can_run(self):
bin_path = os.path.join("bin", "example")
self.run(bin_path, run_environment=True)
Loading

0 comments on commit 9f82ea9

Please sign in to comment.