Skip to content

Commit

Permalink
(#13568) gtk/system: allow cross compilation
Browse files Browse the repository at this point in the history
* gtk/system: allow cross compilation

* use new system helper

* fixup

* Update conanfile.py

* Update conanfile.py

* Update conanfile.py
  • Loading branch information
ericLemanissier authored Oct 18, 2022
1 parent b6f44a4 commit a3b6451
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions recipes/gtk/system/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from conans import ConanFile, tools
from conans.errors import ConanException, ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration, ConanException
from conan.tools.system import package_manager
from conans import tools

required_conan_version = ">=1.47"


class ConanGTK(ConanFile):
Expand All @@ -8,22 +12,22 @@ class ConanGTK(ConanFile):
license = "LGPL-2.1-or-later"
homepage = "https://www.gtk.org"
description = "A free and open-source cross-platform widget toolkit for creating graphical user interfaces"
settings = "os"
settings = "os", "arch", "compiler", "build_type"
options = {"version": [2, 3]}
default_options = {"version": 2}
topics = ("gui", "widget", "graphical")

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.settings.clear()

def _fill_cppinfo_from_pkgconfig(self, name):
pkg_config = tools.PkgConfig(name)
if not pkg_config.provides:
raise ConanException("GTK-{} development files aren't available, give up.".format(self.options.version))
raise ConanException(f"GTK-{self.options.version} 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]
Expand All @@ -41,27 +45,24 @@ def _fill_cppinfo_from_pkgconfig(self, name):
self.cpp_info.components[name].cxxflags = cflags

def system_requirements(self):
packages = []
if tools.os_info.is_linux and self.settings.os == "Linux":
if tools.os_info.with_apt:
packages = ["libgtk2.0-dev"] if self.options.version == 2 else ["libgtk-3-dev"]
elif tools.os_info.with_yum or tools.os_info.with_dnf:
packages = ["gtk{}-devel".format(self.options.version)]
elif tools.os_info.with_pacman:
packages = ["gtk{}".format(self.options.version)]
elif tools.os_info.with_zypper:
packages = ["gtk{}-devel".format(self.options.version)]
else:
self.output.warn("Do not know how to install 'GTK-{}' for {}."
.format(self.options.version,
tools.os_info.linux_distro))
if tools.os_info.is_freebsd and self.settings.os == "FreeBSD":
packages = ["gtk{}".format(self.options.version)]
if packages:
package_tool = tools.SystemPackageTool(conanfile=self, default_mode="verify")
for p in packages:
package_tool.install(update=True, packages=p)
dnf = package_manager.Dnf(self)
dnf.install([f"gtk{self.options.version}-devel"], update=True, check=True)

yum = package_manager.Yum(self)
yum.install([f"gtk{self.options.version}-devel"], update=True, check=True)

apt = package_manager.Apt(self)
apt.install(["libgtk2.0-dev"] if self.options.version == 2 else ["libgtk-3-dev"], update=True, check=True)

pacman = package_manager.PacMan(self)
pacman.install([f"gtk{self.options.version}"], update=True, check=True)

zypper = package_manager.Zypper(self)
zypper.install([f"gtk{self.options.version}-devel"], update=True, check=True)

pkg = package_manager.Pkg(self)
pkg.install([f"gtk{self.options.version}"], update=True, check=True)

def package_info(self):
for name in ["gtk+-{}.0".format(self.options.version)]:
for name in [f"gtk+-{self.options.version}.0"]:
self._fill_cppinfo_from_pkgconfig(name)

0 comments on commit a3b6451

Please sign in to comment.