(#13258) dbus: conan v2 support

* conan v2 support

* bump glib
This commit is contained in:
SpaceIm
2022-10-03 16:24:28 +02:00
committed by GitHub
parent ffbd37f8d8
commit f8cb8aedb1
10 changed files with 135 additions and 201 deletions

View File

@@ -1,7 +0,0 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)
include(../conanbuildinfo.cmake)
conan_basic_setup()
add_subdirectory("cmake")

View File

@@ -10,12 +10,8 @@ sources:
sha256: "f77620140ecb4cdc67f37fb444f8a6bea70b5b6461f12f1cbe2cec60fa7de5fe"
patches:
"1.12.20":
- patch_file: "patches/cmake_current_source_dir.patch"
base_path: "source_subfolder"
patch_type: "portability"
patch_source: "https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/332"
- patch_file: "patches/cmake_configure_checks_list_separator.patch"
base_path: "source_subfolder"
- patch_file: "patches/0001-cmake-project.patch"
- patch_file: "patches/0002-cmake_configure_checks_list_separator.patch"
patch_type: "portability"
url: "https://gitlab.freedesktop.org/dbus/dbus/-/commit/8cd1c2155252938ed38d2612e4d054c7fc0244c3.patch"
patch_source: "https://gitlab.freedesktop.org/dbus/dbus/-/issues/324"

View File

@@ -1,14 +1,13 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, mkdir, rename, replace_in_file, rmdir, save
from conan.tools.scm import Version
import os
import textwrap
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, copy, get, mkdir, rename, rmdir, save, rm
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.scm import Version
from conans import CMake
required_conan_version = ">=1.51.3"
required_conan_version = ">=1.52.0"
class DbusConan(ConanFile):
@@ -21,12 +20,12 @@ class DbusConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
options = {
"system_socket": "ANY",
"system_pid_file": "ANY",
"system_socket": ["ANY"],
"system_pid_file": ["ANY"],
"with_x11": [True, False],
"with_glib": [True, False],
"with_selinux": [True, False],
"session_socket_dir": "ANY",
"session_socket_dir": ["ANY"],
}
default_options = {
"system_socket": "",
@@ -37,29 +36,30 @@ class DbusConan(ConanFile):
"session_socket_dir": "/tmp",
}
generators = "cmake", "cmake_find_package", "VirtualBuildEnv", "VirtualRunEnv"
_cmake = None
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _build_subfolder(self):
return "build_subfolder"
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os not in ("Linux", "FreeBSD"):
del self.options.with_x11
def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
def layout(self):
cmake_layout(self, src_folder="src")
def requirements(self):
self.requires("expat/2.4.9")
if self.options.with_glib:
self.requires("glib/2.73.3")
self.requires("glib/2.74.0")
if self.options.with_selinux:
self.requires("selinux/3.3")
if self.options.get_safe("with_x11"):
@@ -67,52 +67,54 @@ class DbusConan(ConanFile):
def validate(self):
if Version(self.version) >= "1.14.0":
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < 7:
raise ConanInvalidConfiguration("dbus requires at least gcc 7.")
if self.settings.os == "Windows":
raise ConanInvalidConfiguration("dbus 1.14.0 does not support windows. contributions are welcome")
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)
copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, self._source_subfolder))
if self.info.settings.compiler == "gcc" and Version(self.info.settings.compiler.version) < 7:
raise ConanInvalidConfiguration(f"{self.ref} requires at least gcc 7.")
if self.info.settings.os == "Windows":
raise ConanInvalidConfiguration(f"{self.ref} does not support windows. contributions are welcome")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)
def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["DBUS_BUILD_TESTS"] = False
tc.variables["DBUS_ENABLE_DOXYGEN_DOCS"] = False
tc.variables["DBUS_ENABLE_XML_DOCS"] = False
tc.variables["DBUS_BUILD_X11"] = self.options.get_safe("with_x11", False)
tc.variables["DBUS_WITH_GLIB"] = self.options.with_glib
tc.variables["DBUS_DISABLE_ASSERT"] = is_apple_os(self)
tc.variables["DBUS_DISABLE_CHECKS"] = False
# https://github.com/freedesktop/dbus/commit/e827309976cab94c806fda20013915f1db2d4f5a
tc.variables["DBUS_SESSION_SOCKET_DIR"] = self.options.session_socket_dir
tc.generate()
self._cmake.definitions["DBUS_BUILD_TESTS"] = False
self._cmake.definitions["DBUS_ENABLE_DOXYGEN_DOCS"] = False
self._cmake.definitions["DBUS_ENABLE_XML_DOCS"] = False
deps = CMakeDeps(self)
deps.generate()
self._cmake.definitions["DBUS_BUILD_X11"] = self.options.get_safe("with_x11", False)
self._cmake.definitions["DBUS_WITH_GLIB"] = self.options.with_glib
self._cmake.definitions["DBUS_DISABLE_ASSERT"] = is_apple_os(self)
self._cmake.definitions["DBUS_DISABLE_CHECKS"] = False
# Conan does not provide an EXPAT_LIBRARIES CMake variable for the Expat library.
# Define EXPAT_LIBRARIES to be the expat::expat target provided by Conan to fix linking.
self._cmake.definitions["EXPAT_LIBRARIES"] = "expat::expat"
# https://github.com/freedesktop/dbus/commit/e827309976cab94c806fda20013915f1db2d4f5a
self._cmake.definitions["DBUS_SESSION_SOCKET_DIR"] = self.options.session_socket_dir
self._cmake.configure(source_folder=self._source_subfolder,
build_folder=self._build_subfolder)
return self._cmake
def _patch_sources(self):
apply_conandata_patches(self)
# Unfortunately, there is currently no other way to force disable
# CMAKE_FIND_PACKAGE_PREFER_CONFIG ON in CMake conan_toolchain.
replace_in_file(
self,
os.path.join(self.generators_folder, "conan_toolchain.cmake"),
"set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)",
"",
strict=False,
)
def build(self):
apply_conandata_patches(self)
cmake = self._configure_cmake()
self._patch_sources()
cmake = CMake(self)
if Version(self.version) < "1.14.0":
cmake.configure(build_script_folder=os.path.join(self.source_folder, "cmake"))
else:
cmake.configure()
cmake.build()
def package(self):
self.copy(pattern="COPYING", dst="licenses",
src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "share", "doc"))
@@ -123,7 +125,6 @@ class DbusConan(ConanFile):
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "systemd"))
rm(self, "*.la", self.package_folder)
# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self._create_cmake_module_alias_targets(
@@ -134,12 +135,12 @@ class DbusConan(ConanFile):
def _create_cmake_module_alias_targets(self, module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
content += textwrap.dedent(f"""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
""")
save(self, module_file, content)
@property
@@ -154,6 +155,7 @@ class DbusConan(ConanFile):
os.path.join("include", "dbus-1.0"),
os.path.join("lib", "dbus-1.0", "include"),
])
self.cpp_info.resdirs = ["res"]
self.cpp_info.libs = ["dbus-1"]
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("rt")

View File

@@ -0,0 +1,23 @@
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -1,10 +1,3 @@
-# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
-list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
-
-# we do not need to have WIN32 defined
-set(CMAKE_LEGACY_CYGWIN_WIN32 0)
-
-project(dbus)
# we need to be up to date
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2 FATAL_ERROR)
@@ -19,6 +12,9 @@ if(CMAKE_MAJOR_VERSION GREATER 2)
cmake_policy(SET CMP0054 NEW)
endif()
endif()
+set(CMAKE_LEGACY_CYGWIN_WIN32 0)
+project(dbus)
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
# detect version
include(MacrosAutotools)

View File

@@ -1,112 +0,0 @@
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 3ac71a5a..9d203d5f 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -1,5 +1,5 @@
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
-list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/modules")
# we do not need to have WIN32 defined
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
@@ -114,7 +114,7 @@ endif (CYGWIN)
# search for required packages
if (WIN32)
# include local header first to avoid using old installed header
- set (CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/..)
+ set (CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${PROJECT_SOURCE_DIR}/..)
find_package(LibIconv)
include(Win32Macros)
addExplorerWrapper(${CMAKE_PROJECT_NAME})
@@ -148,7 +148,7 @@ add_definitions(-D_GNU_SOURCE)
INCLUDE(ConfigureChecks.cmake)
# @TODO: how to remove last dir from ${CMAKE_SOURCE_DIR} ?
-SET(DBUS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/..)
+SET(DBUS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
# make some more macros available
include (MacroLibrary)
@@ -281,7 +281,7 @@ endif (WIN32 OR CYGWIN)
set (EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
# for including config.h and for includes like <dir/foo.h>
-include_directories( ${CMAKE_SOURCE_DIR}/.. ${CMAKE_BINARY_DIR} ${CMAKE_INCLUDE_PATH} )
+include_directories( ${PROJECT_SOURCE_DIR}/.. ${PROJECT_BINARY_DIR} ${CMAKE_INCLUDE_PATH} )
# linker search directories
link_directories(${DBUS_LIB_DIR} ${LIBRARY_OUTPUT_PATH} )
diff --git a/cmake/bus/CMakeLists.txt b/cmake/bus/CMakeLists.txt
index 4c5bdcf2..5ac8454c 100644
--- a/cmake/bus/CMakeLists.txt
+++ b/cmake/bus/CMakeLists.txt
@@ -1,7 +1,7 @@
add_definitions(-DDBUS_COMPILATION)
SET(EFENCE "")
-SET(BUS_DIR ${CMAKE_SOURCE_DIR}/../bus)
+SET(BUS_DIR ${PROJECT_SOURCE_DIR}/../bus)
# config files for installation
CONFIGURE_FILE( "${BUS_DIR}/session.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/session.conf" IMMEDIATE @ONLY)
@@ -16,7 +16,7 @@ endif()
# copy services for local daemon start to local service dir data/dbus-1/services
SET (SERVICE_FILES test/data/valid-service-files)
-FILE(GLOB FILES "${CMAKE_SOURCE_DIR}/../${SERVICE_FILES}/*.service.in" )
+FILE(GLOB FILES "${PROJECT_SOURCE_DIR}/../${SERVICE_FILES}/*.service.in" )
FOREACH(FILE ${FILES})
GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME_WE)
SET (TARGET ${CMAKE_BINARY_DIR}/data/dbus-1/services/${FILENAME}.service)
@@ -84,7 +84,7 @@ endif(DBUS_ENABLE_STATS)
include_directories(
${CMAKE_BINARY_DIR}
- ${CMAKE_SOURCE_DIR}/..
+ ${PROJECT_SOURCE_DIR}/..
${EXPAT_INCLUDE_DIR}
)
diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt
index 8a01d918..93e541a5 100644
--- a/cmake/dbus/CMakeLists.txt
+++ b/cmake/dbus/CMakeLists.txt
@@ -1,4 +1,4 @@
-SET(DBUS_DIR ${CMAKE_SOURCE_DIR}/../dbus)
+SET(DBUS_DIR ${PROJECT_SOURCE_DIR}/../dbus)
configure_file(${DBUS_DIR}/dbus-arch-deps.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-arch-deps.h )
@@ -98,7 +98,7 @@ set (DBUS_LIB_HEADERS
${DBUS_DIR}/dbus-transport.h
${DBUS_DIR}/dbus-transport-protected.h
${DBUS_DIR}/dbus-watch.h
- ${CMAKE_BINARY_DIR}/config.h
+ ${PROJECT_BINARY_DIR}/config.h
)
if(UNIX)
set (DBUS_LIB_HEADERS ${DBUS_LIB_HEADERS}
@@ -330,7 +330,7 @@ else(WIN32)
endif(WIN32)
if (DBUS_ENABLE_EMBEDDED_TESTS)
- add_test_executable(test-dbus ${CMAKE_SOURCE_DIR}/../dbus/dbus-test-main.c ${DBUS_INTERNAL_LIBRARIES})
+ add_test_executable(test-dbus ${PROJECT_SOURCE_DIR}/../dbus/dbus-test-main.c ${DBUS_INTERNAL_LIBRARIES})
set_target_properties(test-dbus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
ENDIF (DBUS_ENABLE_EMBEDDED_TESTS)
diff --git a/cmake/modules/CPackInstallConfig.cmake b/cmake/modules/CPackInstallConfig.cmake
index 46e8fb6d..e2331425 100644
--- a/cmake/modules/CPackInstallConfig.cmake
+++ b/cmake/modules/CPackInstallConfig.cmake
@@ -9,8 +9,8 @@ endif (DBUS_INSTALL_SYSTEM_LIBS)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "D-BUS For Windows")
SET(CPACK_PACKAGE_VENDOR "D-BUS Windows Team")
-SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/../README")
-SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/../COPYING")
+SET(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/../README")
+SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/../COPYING")
# duplicated from VERSION
SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})

View File

@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES C)
find_package(DBus1 REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} dbus-1)
target_link_libraries(${PROJECT_NAME} PRIVATE dbus-1)

View File

@@ -1,13 +1,19 @@
import os
from conan import ConanFile
from conan.tools.build import cross_building
from conans import CMake
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 = "cmake", "cmake_find_package_multi", "VirtualBuildEnv", "VirtualRunEnv"
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)
@@ -15,6 +21,7 @@ class TestPackageConan(ConanFile):
cmake.build()
def test(self):
if not cross_building(self):
self.run("dbus-monitor --help", run_environment=True)
self.run(os.path.join("bin", "test_package"), run_environment=True)
if can_run(self):
self.run("dbus-monitor --help", env="conanrun")
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

View File

@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
find_package(DBus1 REQUIRED CONFIG)
add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE dbus-1)

View File

@@ -0,0 +1,18 @@
from conans import ConanFile, CMake, tools
import os
class TestPackageConan(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("dbus-monitor --help", run_environment=True)
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)