Skip to content

Commit

Permalink
(conan-io#25092) pango: add v1.54.0, enable libxft, freetype and font…
Browse files Browse the repository at this point in the history
…config by default, add introspection support

* pango: Fix some component requires

* Bump fontconfig to fix dependency conflict in libxft

* Add missing comma

* pango: add v1.54.0

* pango: use version ranges for meson and pkgconf

* pango: improve with_xft handling

* pango: enable freetype and fontconfig by default

* pango: add introspection support

* pango: revert propagation of option values to cairo

* Fix some issues in the recipe after inspecting meson.build

---------

Co-authored-by: ErniGH <[email protected]>

* Try to solve Windows compilation issues

* pango: add URLs to meson.build references in comments

* Add missing freetype requirement on pango, this might be overlinking but ok

---------

Co-authored-by: Jordan Williams <[email protected]>
Co-authored-by: Ernesto de Gracia Herranz <[email protected]>
Co-authored-by: Abril Rincón Blanco <[email protected]>
  • Loading branch information
4 people authored and OMGtechy committed Dec 31, 2024
1 parent e8ecd5f commit 010625b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 44 deletions.
3 changes: 3 additions & 0 deletions recipes/pango/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.54.0":
url: "https://download.gnome.org/sources/pango/1.54/pango-1.54.0.tar.xz"
sha256: "8a9eed75021ee734d7fc0fdf3a65c3bba51dfefe4ae51a9b414a60c70b2d1ed8"
"1.51.0":
url: "https://download.gnome.org/sources/pango/1.51/pango-1.51.0.tar.xz"
sha256: "74efc109ae6f903bbe6af77eaa2ac6094b8ee245a2e23f132a7a8f0862d1a9f5"
Expand Down
129 changes: 85 additions & 44 deletions recipes/pango/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import chdir, copy, get, rename, replace_in_file, rm, rmdir
from conan.tools.gnu import PkgConfigDeps
Expand Down Expand Up @@ -31,26 +32,32 @@ class PangoConan(ConanFile):
"with_xft": [True, False],
"with_freetype": [True, False],
"with_fontconfig": [True, False],
"with_introspection": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_libthai": False,
"with_cairo": True,
"with_xft": False,
"with_freetype": False,
"with_fontconfig": False,
"with_xft": True,
# TODO: Currently can't actually disable this in Macos at least,
# it always shows up as detected in meson
"with_freetype": True,
"with_fontconfig": True,
"with_introspection": False,
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.os not in ["FreeBSD", "Linux"]:
del self.options.with_xft

if self.settings.os in ["FreeBSD", "Linux"]:
self.options.with_xft = True
if not self.settings.os in ["Macos", "Windows"]:
self.options.with_freetype = True
self.options.with_fontconfig = True
# Optional in Windows/Macos but false by default
# https://gitlab.gnome.org/GNOME/pango/-/blob/1.54.0/meson.build#L242
if self.settings.os in ["Macos", "Windows"]:
self.options.with_fontconfig = False
self.options.with_freetype = False

def configure(self):
if self.options.shared:
Expand All @@ -64,16 +71,10 @@ def layout(self):
def requirements(self):
if self.options.with_freetype:
self.requires("freetype/2.13.2")

if self.options.with_fontconfig:
self.requires("fontconfig/2.15.0")
if self.options.with_xft:
if self.options.get_safe("with_xft"):
self.requires("libxft/2.3.8")
if (
self.options.with_xft
and self.options.with_fontconfig
and self.options.with_freetype
):
self.requires("xorg/system") # for xorg::xrender
if self.options.with_cairo:
# "pango/pangocairo.h" includes "cairo.h"
Expand All @@ -89,19 +90,25 @@ def validate(self):
and Version(self.settings.compiler.version) < "5"
):
raise ConanInvalidConfiguration(f"{self.name} does not support GCC before version 5. Contributions are welcome.")
if self.options.with_xft and not self.settings.os in ["Linux", "FreeBSD"]:
raise ConanInvalidConfiguration("Xft can only be used on Linux and FreeBSD")

if self.options.with_xft and (
not self.options.with_freetype or not self.options.with_fontconfig
):
raise ConanInvalidConfiguration("Xft requires freetype and fontconfig")
if self.options.get_safe("with_xft"):
if not self.options.with_freetype or not self.options.with_fontconfig:
raise ConanInvalidConfiguration(f"-o=&:with_xft=True requires -o=&:with_freetype=True and -o=&:with_fontconfig=True")

if self.dependencies["glib"].options.shared and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration(
"Linking shared glib with the MSVC static runtime is not supported"
)

# Can't be turned off outside Macos/Windows
# https://gitlab.gnome.org/GNOME/pango/-/blob/1.54.0/meson.build#L240
if self.settings.os not in ["Macos", "Windows"] and not self.options.with_fontconfig:
raise ConanInvalidConfiguration(f"{self.ref} requires -o=&:with_fontconfig=True for {self.settings.os}")

if (self.options.with_fontconfig and self.options.with_freetype
and not self.dependencies["cairo"].options.with_fontconfig):
raise ConanInvalidConfiguration(f"{self.ref} with -o=&:with_fontconfig=True and -o=&:with_freetype=True requires -o=cairo/*:with_fontconfig=True")

if self.options.shared:
if not self.dependencies["glib"].options.shared:
raise ConanInvalidConfiguration(
Expand All @@ -118,33 +125,43 @@ def validate(self):

def build_requirements(self):
self.tool_requires("glib/<host_version>")
self.tool_requires("meson/1.4.0")
self.tool_requires("meson/[>=1.2.3 <2]")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/2.1.0")
self.tool_requires("pkgconf/[>=2.2 <3]")
if self.options.with_introspection:
self.tool_requires("gobject-introspection/1.78.1")

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

def generate(self):
virtual_build_env = VirtualBuildEnv(self)
virtual_build_env.generate()
pkg_config_deps = PkgConfigDeps(self)
pkg_config_deps.generate()
VirtualBuildEnv(self).generate()

deps = PkgConfigDeps(self)
if self.options.with_introspection:
# gnome.generate_gir() in Meson looks for gobject-introspection-1.0.pc
deps.build_context_activated = ["gobject-introspection"]
deps.generate()

enabled_disabled = lambda opt: "enabled" if opt else "disabled"
tc = MesonToolchain(self)
tc.project_options["introspection"] = "disabled"
tc.project_options["libthai"] = "enabled" if self.options.with_libthai else "disabled"
tc.project_options["cairo"] = "enabled" if self.options.with_cairo else "disabled"
tc.project_options["xft"] = "enabled" if self.options.with_xft else "disabled"
tc.project_options["fontconfig"] = "enabled" if self.options.with_fontconfig else "disabled"
tc.project_options["freetype"] = "enabled" if self.options.with_freetype else "disabled"
tc.project_options["introspection"] = enabled_disabled(self.options.with_introspection)
tc.project_options["libthai"] = enabled_disabled(self.options.with_libthai)
tc.project_options["cairo"] = enabled_disabled(self.options.with_cairo)
tc.project_options["xft"] = enabled_disabled(self.options.get_safe("with_xft"))
tc.project_options["fontconfig"] = enabled_disabled(self.options.with_fontconfig)
tc.project_options["freetype"] = enabled_disabled(self.options.with_freetype)
tc.generate()

def build(self):
def _patch_sources(self):
meson_build = os.path.join(self.source_folder, "meson.build")
replace_in_file(self, meson_build, "subdir('tests')", "")
replace_in_file(self, meson_build, "subdir('tools')", "")
replace_in_file(self, meson_build, "subdir('utils')", "")
replace_in_file(self, meson_build, "subdir('examples')", "")

def build(self):
self._patch_sources()
meson = Meson(self)
meson.configure()
meson.build()
Expand All @@ -164,6 +181,9 @@ def package(self):
self._fix_library_names(os.path.join(self.package_folder, "lib"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rm(self, "*.pdb", self.package_folder, recursive=True)
if self.options.with_introspection:
os.rename(os.path.join(self.package_folder, "share"),
os.path.join(self.package_folder, "res"))

def package_info(self):
self.cpp_info.components["pango_"].libs = ["pango-1.0"]
Expand All @@ -178,41 +198,57 @@ def package_info(self):
if self.options.with_fontconfig:
self.cpp_info.components["pango_"].requires.append("fontconfig::fontconfig")

if self.options.with_xft:
self.cpp_info.components["pango_"].requires.append("libxft::libxft")
# Pango only uses xrender when Xft, fontconfig and freetype are enabled
if self.options.with_fontconfig and self.options.with_freetype:
self.cpp_info.components["pango_"].requires.append("xorg::xrender")
if self.options.get_safe("with_xft"):
# Pango only uses xrender when Xft, fontconfig and freetype are enabled, which if with_xft is true,
# means that the other options are true because they are checked in the validate() method
self.cpp_info.components["pango_"].requires.extend(["libxft::libxft", "xorg::xrender"])
if self.options.with_cairo:
self.cpp_info.components["pango_"].requires.append("cairo::cairo_")
self.cpp_info.components["pango_"].includedirs = [
os.path.join(self.package_folder, "include", "pango-1.0")
]

if self.options.with_freetype:
if self.options.with_introspection:
self.cpp_info.components["pango_"].resdirs = ["res"]
self.buildenv_info.append_path("GI_GIR_PATH", os.path.join(self.package_folder, "res", "gir-1.0"))
self.buildenv_info.append_path("GI_TYPELIB_PATH", os.path.join(self.package_folder, "lib", "girepository-1.0"))
self.env_info.GI_GIR_PATH.append(os.path.join(self.package_folder, "res", "gir-1.0"))
self.env_info.GI_TYPELIB_PATH.append(os.path.join(self.package_folder, "lib", "girepository-1.0"))

# From meson.build: "To build pangoft2, we need HarfBuzz, FontConfig and FreeType"
if self.options.with_freetype and self.options.with_fontconfig:
self.cpp_info.components["pangoft2"].libs = ["pangoft2-1.0"]
self.cpp_info.components["pangoft2"].set_property("pkg_config_name", "pangoft2")
self.cpp_info.components["pangoft2"].requires = [
"pango_",
"freetype::freetype",
"fontconfig::fontconfig",
]
self.cpp_info.components["pangoft2"].includedirs = [
os.path.join(self.package_folder, "include", "pango-1.0")
]

# https://gitlab.gnome.org/GNOME/pango/-/blob/1.54.0/meson.build#L320
self.cpp_info.components["pango_"].requires.append("freetype::freetype")

if self.options.with_fontconfig:
self.cpp_info.components["pangofc"].set_property("pkg_config_name", "pangofc")
if self.options.with_freetype:
self.cpp_info.components["pangofc"].requires = ["pangoft2"]
# pangoft2 is always built if pango has fontconfig and freetype support
self.cpp_info.components["pangofc"].requires = ["freetype::freetype", "harfbuzz::harfbuzz", "pangoft2"]
elif self.options.with_freetype:
self.cpp_info.components["pango_"].requires.append("freetype::freetype")

if self.settings.os != "Windows":
self.cpp_info.components["pangoroot"].set_property("pkg_config_name", "pangoroot")
if self.options.with_freetype:
self.cpp_info.components["pangoroot"].requires = ["pangoft2"]

if self.options.with_xft:
if self.options.get_safe("with_xft"):
self.cpp_info.components["pangoxft"].libs = ["pangoxft-1.0"]
self.cpp_info.components["pangoxft"].set_property("pkg_config_name", "pangoxft")
# pangoft2 is always built if pango has fontconfig and freetype support,
# which is always true if pango has xft support enabled
self.cpp_info.components["pangoxft"].requires = ["pango_", "pangoft2"]
self.cpp_info.components["pangoxft"].includedirs = [
os.path.join(self.package_folder, "include", "pango-1.0")
Expand All @@ -226,11 +262,16 @@ def package_info(self):
if Version(self.version) >= "1.50.12":
self.cpp_info.components["pangowin32"].system_libs.append("dwrite")

if is_apple_os(self):
# https://gitlab.gnome.org/GNOME/pango/-/blob/1.54.0/meson.build#L333-346
self.cpp_info.components["pango_"].frameworks.extend(["CoreText", "CoreFoundation", "ApplicationServices"])

if self.options.with_cairo:
self.cpp_info.components["pangocairo"].libs = ["pangocairo-1.0"]
self.cpp_info.components["pangocairo"].set_property("pkg_config_name", "pangocairo")
self.cpp_info.components["pangocairo"].requires = ["pango_"]
if self.options.with_freetype:
self.cpp_info.components["pangocairo"].requires = ["pango_", "cairo::cairo_"]
if self.options.with_freetype and self.options.with_fontconfig:
# https://gitlab.gnome.org/GNOME/pango/-/blob/1.54.0/meson.build#L506
self.cpp_info.components["pangocairo"].requires.append("pangoft2")
if self.settings.os == "Windows":
self.cpp_info.components["pangocairo"].requires.append("pangowin32")
Expand Down
2 changes: 2 additions & 0 deletions recipes/pango/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.54.0":
folder: all
"1.51.0":
folder: all
"1.50.14":
Expand Down

0 comments on commit 010625b

Please sign in to comment.