Skip to content

Commit

Permalink
xorg/system: Modernize
Browse files Browse the repository at this point in the history
Use tools.system.package_manager ang tools.gnu.PkgConfig from the `conan` namespace.
This greatly reduces complexity of the package.
  • Loading branch information
jwillikers committed Jul 14, 2022
1 parent a583276 commit 75a97f9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 85 deletions.
123 changes: 50 additions & 73 deletions recipes/xorg/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from conans import ConanFile, tools
from conans.errors import ConanException, ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.gnu import PkgConfig
from conan.tools.system.package_manager import Apt, Yum, PacMan, Pkg, Zypper
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=1.32"
required_conan_version = ">=1.47"

class ConanXOrg(ConanFile):
name = "xorg"
Expand All @@ -12,81 +14,49 @@ class ConanXOrg(ConanFile):
settings = "os"
topics = ("x11", "xorg")

def configure(self):
def validate(self):
if self.settings.os not in ["Linux", "FreeBSD"]:
raise ConanInvalidConfiguration("This recipe supports only Linux and FreeBSD")

def package_id(self):
self.info.header_only()

def _fill_cppinfo_from_pkgconfig(self, name):
pkg_config = tools.PkgConfig(name)
if not pkg_config.provides:
raise ConanException("OpenGL development files aren't available, give up")
libs = [lib[2:] for lib in pkg_config.libs_only_l]
lib_dirs = [lib[2:] for lib in pkg_config.libs_only_L]
ldflags = [flag for flag in pkg_config.libs_only_other]
include_dirs = [include[2:] for include in pkg_config.cflags_only_I]
cflags = [flag for flag in pkg_config.cflags_only_other if not flag.startswith("-D")]
defines = [flag[2:] for flag in pkg_config.cflags_only_other if flag.startswith("-D")]
variables = pkg_config.variables
def system_requirements(self):
apt = Apt(self)
apt.install(["libx11-dev", "libx11-xcb-dev", "libfontenc-dev", "libice-dev", "libsm-dev", "libxau-dev", "libxaw7-dev",
"libxcomposite-dev", "libxcursor-dev", "libxdamage-dev", "libxdmcp-dev", "libxext-dev", "libxfixes-dev",
"libxi-dev", "libxinerama-dev", "libxkbfile-dev", "libxmu-dev", "libxmuu-dev",
"libxpm-dev", "libxrandr-dev", "libxrender-dev", "libxres-dev", "libxss-dev", "libxt-dev", "libxtst-dev",
"libxv-dev", "libxvmc-dev", "libxxf86vm-dev", "xtrans-dev", "libxcb-render0-dev",
"libxcb-render-util0-dev", "libxcb-xkb-dev", "libxcb-icccm4-dev", "libxcb-image0-dev",
"libxcb-keysyms1-dev", "libxcb-randr0-dev", "libxcb-shape0-dev", "libxcb-sync-dev", "libxcb-xfixes0-dev",
"libxcb-xinerama0-dev", "xkb-data", "libxcb-dri3-dev", "uuid-dev"], update=True, check=True)
apt.install_substitutes(
["libxcb-util-dev", "libxcb-util0-dev"], update=True, check=True)

self.cpp_info.components[name].system_libs = libs
self.cpp_info.components[name].libdirs = lib_dirs
self.cpp_info.components[name].sharedlinkflags = ldflags
self.cpp_info.components[name].exelinkflags = ldflags
self.cpp_info.components[name].defines = defines
self.cpp_info.components[name].includedirs = include_dirs
self.cpp_info.components[name].cflags = cflags
self.cpp_info.components[name].cxxflags = cflags
self.cpp_info.components[name].version = pkg_config.version[0]
self.cpp_info.components[name].set_property("component_version", pkg_config.version[0])
self.cpp_info.components[name].set_property(
"pkg_config_custom_content",
"\n".join("%s=%s" % (key, value) for key,value in variables.items()))
Yum(self).install(["libxcb-devel", "libfontenc-devel", "libXaw-devel", "libXcomposite-devel",
"libXcursor-devel", "libXdmcp-devel", "libXtst-devel", "libXinerama-devel",
"libxkbfile-devel", "libXrandr-devel", "libXres-devel", "libXScrnSaver-devel", "libXvMC-devel",
"xorg-x11-xtrans-devel", "xcb-util-wm-devel", "xcb-util-image-devel", "xcb-util-keysyms-devel",
"xcb-util-renderutil-devel", "libXdamage-devel", "libXxf86vm-devel", "libXv-devel",
"xcb-util-devel", "libuuid-devel", "xkeyboard-config-devel"], update=True, check=True)

def system_requirements(self):
packages = []
if tools.os_info.is_linux and self.settings.os == "Linux":
if tools.os_info.with_apt:
packages = ["libx11-dev", "libx11-xcb-dev", "libfontenc-dev", "libice-dev", "libsm-dev", "libxau-dev", "libxaw7-dev",
"libxcomposite-dev", "libxcursor-dev", "libxdamage-dev", "libxdmcp-dev", "libxext-dev", "libxfixes-dev",
"libxi-dev", "libxinerama-dev", "libxkbfile-dev", "libxmu-dev", "libxmuu-dev",
"libxpm-dev", "libxrandr-dev", "libxrender-dev", "libxres-dev", "libxss-dev", "libxt-dev", "libxtst-dev",
"libxv-dev", "libxvmc-dev", "libxxf86vm-dev", "xtrans-dev", "libxcb-render0-dev",
"libxcb-render-util0-dev", "libxcb-xkb-dev", "libxcb-icccm4-dev", "libxcb-image0-dev",
"libxcb-keysyms1-dev", "libxcb-randr0-dev", "libxcb-shape0-dev", "libxcb-sync-dev", "libxcb-xfixes0-dev",
"libxcb-xinerama0-dev", "xkb-data", "libxcb-dri3-dev", "uuid-dev"]
if (tools.os_info.linux_distro == "ubuntu" and tools.os_info.os_version < "15") or\
(tools.os_info.linux_distro == "debian" and tools.os_info.os_version < "12") or\
(tools.os_info.linux_distro == "raspbian" and tools.os_info.os_version < "12"):
packages.append( "libxcb-util0-dev" )
else:
packages.append( "libxcb-util-dev" )
elif tools.os_info.with_yum or tools.os_info.with_dnf or tools.os_info.with_zypper:
packages = ["libxcb-devel", "libfontenc-devel", "libXaw-devel", "libXcomposite-devel",
"libXcursor-devel", "libXdmcp-devel", "libXtst-devel", "libXinerama-devel",
"libxkbfile-devel", "libXrandr-devel", "libXres-devel", "libXScrnSaver-devel", "libXvMC-devel",
"xorg-x11-xtrans-devel", "xcb-util-wm-devel", "xcb-util-image-devel", "xcb-util-keysyms-devel",
"xcb-util-renderutil-devel", "libXdamage-devel", "libXxf86vm-devel", "libXv-devel",
"xcb-util-devel", "libuuid-devel"]
packages.append("xkeyboard-config" if tools.os_info.with_zypper else "xkeyboard-config-devel")
elif tools.os_info.with_pacman:
packages = ["libxcb", "libfontenc", "libice", "libsm", "libxaw", "libxcomposite", "libxcursor",
"libxdamage", "libxdmcp", "libxtst", "libxinerama", "libxkbfile", "libxrandr", "libxres",
"libxss", "libxvmc", "xtrans", "xcb-util-wm", "xcb-util-image","xcb-util-keysyms", "xcb-util-renderutil",
"libxxf86vm", "libxv", "xkeyboard-config", "xcb-util", "util-linux-libs"]
else:
self.output.warn("Do not know how to install 'xorg' for {}.".format(tools.os_info.linux_distro))

elif tools.os_info.is_freebsd and self.settings.os == "FreeBSD":
packages = ["libX11", "libfontenc", "libice", "libsm", "libxaw", "libxcomposite", "libxcursor",
"libxdamage", "libxdmcp", "libxtst", "libxinerama", "libxkbfile", "libxrandr", "libxres",
"libXScrnSaver", "libxvmc", "xtrans", "xcb-util-wm", "xcb-util-image", "xcb-util-keysyms", "xcb-util-renderutil",
"libxxf86vm", "libxv", "xkeyboard-config", "xcb-util"]
if packages:
package_tool = tools.SystemPackageTool(conanfile=self, default_mode="verify")
package_tool.install_packages(update=True, packages=packages)
Zypper(self).install(["libxcb-devel", "libfontenc-devel", "libXaw-devel", "libXcomposite-devel",
"libXcursor-devel", "libXdmcp-devel", "libXtst-devel", "libXinerama-devel",
"libxkbfile-devel", "libXrandr-devel", "libXres-devel", "libXScrnSaver-devel", "libXvMC-devel",
"xorg-x11-xtrans-devel", "xcb-util-wm-devel", "xcb-util-image-devel", "xcb-util-keysyms-devel",
"xcb-util-renderutil-devel", "libXdamage-devel", "libXxf86vm-devel", "libXv-devel",
"xcb-util-devel", "libuuid-devel", "xkeyboard-config"], update=True, check=True)

PacMan(self).install(["libxcb", "libfontenc", "libice", "libsm", "libxaw", "libxcomposite", "libxcursor",
"libxdamage", "libxdmcp", "libxtst", "libxinerama", "libxkbfile", "libxrandr", "libxres",
"libxss", "libxvmc", "xtrans", "xcb-util-wm", "xcb-util-image", "xcb-util-keysyms", "xcb-util-renderutil",
"libxxf86vm", "libxv", "xkeyboard-config", "xcb-util", "util-linux-libs"], update=True, check=True)

Pkg(self).install(["libX11", "libfontenc", "libice", "libsm", "libxaw", "libxcomposite", "libxcursor",
"libxdamage", "libxdmcp", "libxtst", "libxinerama", "libxkbfile", "libxrandr", "libxres",
"libXScrnSaver", "libxvmc", "xtrans", "xcb-util-wm", "xcb-util-image", "xcb-util-keysyms", "xcb-util-renderutil",
"libxxf86vm", "libxv", "xkeyboard-config", "xcb-util"], update=True, check=True)

def package_info(self):
for name in ["x11", "x11-xcb", "fontenc", "ice", "sm", "xau", "xaw7",
Expand All @@ -97,9 +67,16 @@ def package_info(self):
"xcb-renderutil", "xcb-shape", "xcb-shm", "xcb-sync", "xcb-xfixes",
"xcb-xinerama", "xcb", "xkeyboard-config", "xcb-atom", "xcb-aux", "xcb-event", "xcb-util",
"xcb-dri3"] + ([] if self.settings.os == "FreeBSD" else ["uuid"]):
self._fill_cppinfo_from_pkgconfig(name)
self.cpp_info.components[name].set_property("pkg_config_name", name)
pkg_config = PkgConfig(self, name)
pkg_config.fill_cpp_info(
self.cpp_info.components[name], is_system=True)
self.cpp_info.components[name].version = pkg_config.version
self.cpp_info.components[name].set_property(
"pkg_config_name", name)
self.cpp_info.components[name].set_property(
"component_version", pkg_config.version)
self.cpp_info.components[name].set_property("pkg_config_custom_content",
"\n".join("%s=%s" % (key, value) for key, value in pkg_config.variables.items()))

if self.settings.os == "Linux":
self.cpp_info.components["sm"].requires.append("uuid")

12 changes: 5 additions & 7 deletions recipes/xorg/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)

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

set(SOURCES test_package.c)
find_package(xorg REQUIRED)

add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
add_executable(test_package test_package.c)
target_link_libraries(test_package PRIVATE xorg::xorg)
20 changes: 15 additions & 5 deletions recipes/xorg/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.cmake import CMake
from conan.tools.layout import cmake_layout


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

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", "test_package")
self.run(bin_path, run_environment=True)
if not cross_building(self):
cmd = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(cmd, env="conanrun")

0 comments on commit 75a97f9

Please sign in to comment.