[DO-973] harfbuzz package (!10)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/10
This commit is contained in:
Aleksandr Vodyanov
2024-12-26 12:02:17 +03:00
parent 39afe6a1dd
commit c807f2514e
126 changed files with 6604 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
sources:
"8.3.0":
url: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/releases/download/8.3.0/harfbuzz-8.3.0.tar.xz"
sha256: "109501eaeb8bde3eadb25fab4164e993fbace29c3d775bcaa1c1e58e2f15f847"
"8.2.2":
url: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/releases/download/8.2.2/harfbuzz-8.2.2.tar.xz"
sha256: "e433ad85fbdf57f680be29479b3f964577379aaf319f557eb76569f0ecbc90f3"
"8.2.1":
url: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/releases/download/8.2.1/harfbuzz-8.2.1.tar.xz"
sha256: "0fec78f98c9c8faf228957a201c8846f809452c20f8445eb092a1ba6f22dbea5"
"8.1.1":
url: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/releases/download/8.1.1/harfbuzz-8.1.1.tar.xz"
sha256: "0305ad702e11906a5fc0c1ba11c270b7f64a8f5390d676aacfd71db129d6565f"
"8.0.1":
url: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/releases/download/8.0.1/harfbuzz-8.0.1.tar.xz"
sha256: "c1ce780acd385569f25b9a29603d1d5bc71e6940e55bfdd4f7266fad50e42620"
"7.3.0":
url: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/releases/download/7.3.0/harfbuzz-7.3.0.tar.xz"
sha256: "20770789749ac9ba846df33983dbda22db836c70d9f5d050cb9aa5347094a8fb"
"6.0.0":
url: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/releases/download/6.0.0/harfbuzz-6.0.0.tar.xz"
sha256: "1d1010a1751d076d5291e433c138502a794d679a7498d1268ee21e2d4a140eb4"
"5.1.0":
url: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/releases/download/5.1.0/harfbuzz-5.1.0.tar.xz"
sha256: "2edb95db668781aaa8d60959d21be2ff80085f31b12053cdd660d9a50ce84f05"
patches:
"5.1.0":
- patch_file: "patches/0000-fix-freetype-lookup-5.1.0.patch"
patch_type: "portability"
patch_description: "fix fretype and icu dependency lookup"
patch_source: "https://nexus.avroid.tech/repository/devops-raw-proxy-github/harfbuzz/harfbuzz/pull/3811"

View File

@@ -0,0 +1,226 @@
from conan import ConanFile, conan_version
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os, fix_apple_shared_install_name
from conan.tools.build import can_run, stdcpp_library
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir, replace_in_file
from conan.tools.gnu import PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
from conan.tools.microsoft import is_msvc_static_runtime, is_msvc
from conan.tools.scm import Version
import os
required_conan_version = ">=1.60.0 <2.0 || >=2.0.6"
class HarfbuzzConan(ConanFile):
name = "harfbuzz"
description = "HarfBuzz is an OpenType text shaping engine."
topics = ("opentype", "text", "engine")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://harfbuzz.github.io/"
license = "MIT"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_freetype": [True, False],
"with_icu": [True, False],
"with_glib": [True, False],
"with_gdi": [True, False],
"with_uniscribe": [True, False],
"with_directwrite": [True, False],
"with_subset": [True, False],
"with_coretext": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_freetype": True,
"with_icu": False,
"with_glib": True,
"with_gdi": True,
"with_uniscribe": True,
"with_directwrite": False,
"with_subset": False,
"with_coretext": True,
}
short_paths = True
@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
else:
del self.options.with_gdi
del self.options.with_uniscribe
del self.options.with_directwrite
if not is_apple_os(self):
del self.options.with_coretext
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if self.options.shared and self.options.with_glib:
wildcard = "" if Version(conan_version) < "2.0.0" else "/*"
self.options[f"glib{wildcard}"].shared = True
def layout(self):
basic_layout(self, src_folder="src")
def requirements(self):
if self.options.with_freetype:
self.requires("freetype/2.13.2")
if self.options.with_icu:
self.requires("icu/74.1")
if self.options.with_glib:
self.requires("glib/2.78.3")
def validate(self):
if self.options.shared and self.options.with_glib and not self.dependencies["glib"].options.shared:
raise ConanInvalidConfiguration(
"Linking a shared library against static glib can cause unexpected behaviour."
)
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "7":
raise ConanInvalidConfiguration("New versions of harfbuzz require at least gcc 7")
if self.options.with_glib and self.dependencies["glib"].options.shared and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration(
"Linking shared glib with the MSVC static runtime is not supported"
)
def build_requirements(self):
# self.tool_requires("meson/1.4.0")
if not self.conf.get("tools.gnu:pkg_config", check_type=str):
self.tool_requires("pkgconf/[>=2.1.0]")
if self.options.with_glib:
self.tool_requires("glib/<host_version>")
if self.settings.os == "Macos":
# Ensure that the gettext we use at build time is compatible
# with the libiconv that is transitively exposed by glib
self.tool_requires("gettext/0.21")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
def is_enabled(value):
return "enabled" if value else "disabled"
def meson_backend_and_flags():
def is_vs_2017():
version = Version(self.settings.compiler.version)
return version == "15" or version == "191"
if is_msvc(self) and is_vs_2017() and self.settings.build_type == "Debug":
# Mitigate https://learn.microsoft.com/en-us/cpp/build/reference/zf?view=msvc-170
return "vs", ["/bigobj"]
return "ninja", []
VirtualBuildEnv(self).generate()
# Avoid conflicts with libiconv
# see: https://github.com/conan-io/conan-center-index/pull/17046#issuecomment-1554629094
if self._settings_build.os == "Macos":
env = Environment()
env.define_path("DYLD_FALLBACK_LIBRARY_PATH", "$DYLD_LIBRARY_PATH")
env.define_path("DYLD_LIBRARY_PATH", "")
env.vars(self, scope="build").save_script("conanbuild_macos_runtimepath")
PkgConfigDeps(self).generate()
backend, cxxflags = meson_backend_and_flags()
tc = MesonToolchain(self, backend=backend)
tc.project_options["auto_features"] = "disabled"
tc.project_options.update({
"glib": is_enabled(self.options.with_glib),
"icu": is_enabled(self.options.with_icu),
"freetype": is_enabled(self.options.with_freetype),
"gdi": is_enabled(self.options.get_safe("with_gdi")),
"coretext": is_enabled(self.options.get_safe("with_coretext")),
"directwrite": is_enabled(self.options.get_safe("with_directwrite")),
"gobject": is_enabled(can_run(self) and self.options.with_glib),
"introspection": is_enabled(False),
"tests": "disabled",
"docs": "disabled",
"benchmark": "disabled",
"icu_builtin": "false"
})
tc.cpp_args += cxxflags
tc.generate()
def build(self):
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "meson.build"), "subdir('util')", "")
meson = Meson(self)
meson.configure()
meson.build()
def package(self):
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses"))
meson = Meson(self)
meson.install()
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
fix_apple_shared_install_name(self)
fix_msvc_libname(self)
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "harfbuzz")
self.cpp_info.set_property("cmake_target_name", "harfbuzz::harfbuzz")
self.cpp_info.set_property("pkg_config_name", "harfbuzz")
if self.options.with_icu:
self.cpp_info.libs.append("harfbuzz-icu")
if self.options.with_subset:
self.cpp_info.libs.append("harfbuzz-subset")
self.cpp_info.libs.append("harfbuzz")
self.cpp_info.includedirs.append(os.path.join("include", "harfbuzz"))
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
if self.settings.os == "Windows" and not self.options.shared:
self.cpp_info.system_libs.append("user32")
if self.options.with_gdi or self.options.with_uniscribe:
self.cpp_info.system_libs.append("gdi32")
if self.options.with_uniscribe or self.options.with_directwrite:
self.cpp_info.system_libs.append("rpcrt4")
if self.options.with_uniscribe:
self.cpp_info.system_libs.append("usp10")
if self.options.with_directwrite:
self.cpp_info.system_libs.append("dwrite")
if is_apple_os(self) and self.options.get_safe("with_coretext", False):
if self.settings.os == "Macos":
self.cpp_info.frameworks.append("ApplicationServices")
else:
self.cpp_info.frameworks.extend(["CoreFoundation", "CoreGraphics", "CoreText"])
if not self.options.shared:
libcxx = stdcpp_library(self)
if libcxx:
self.cpp_info.system_libs.append(libcxx)
def fix_msvc_libname(conanfile, remove_lib_prefix=True):
"""remove lib prefix & change extension to .lib in case of cl like compiler"""
from conan.tools.files import rename
import glob
if not conanfile.settings.get_safe("compiler.runtime"):
return
libdirs = getattr(conanfile.cpp.package, "libdirs")
for libdir in libdirs:
for ext in [".dll.a", ".dll.lib", ".a"]:
full_folder = os.path.join(conanfile.package_folder, libdir)
for filepath in glob.glob(os.path.join(full_folder, f"*{ext}")):
libname = os.path.basename(filepath)[0:-len(ext)]
if remove_lib_prefix and libname[0:3] == "lib":
libname = libname[3:]
rename(conanfile, filepath, os.path.join(os.path.dirname(filepath), f"{libname}.lib"))

View File

@@ -0,0 +1,72 @@
diff --git a/meson.build b/meson.build
index df4443fb2..b8b143948 100644
--- a/meson.build
+++ b/meson.build
@@ -21,7 +21,7 @@ pkgmod = import('pkgconfig')
cpp = meson.get_compiler('cpp')
null_dep = dependency('', required: false)
-if cpp.get_id() == 'msvc'
+if cpp.get_argument_syntax() == 'msvc'
# Ignore several spurious warnings for things HarfBuzz does very commonly.
# If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
# If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
@@ -83,25 +83,39 @@ check_funcs = [
m_dep = cpp.find_library('m', required: false)
-# https://github.com/harfbuzz/harfbuzz/pull/2498
-freetype_dep = dependency(cpp.get_argument_syntax() == 'msvc' ? 'freetype' : 'freetype2',
- required: get_option('freetype'),
- default_options: ['harfbuzz=disabled'])
+
+# Try pkgconfig name
+freetype_dep = dependency('freetype2', required: false)
+if not freetype_dep.found()
+ # Try cmake name
+ freetype_dep = dependency('freetype', required: false)
+endif
+if not freetype_dep.found()
+ # Subproject fallback, `allow_fallback: true` means the fallback will be
+ # tried even if the freetype option is set to `auto`.
+ freetype_dep = dependency('freetype2',
+ required: get_option('freetype'),
+ default_options: ['harfbuzz=disabled'],
+ allow_fallback: true)
+endif
glib_dep = dependency('glib-2.0', required: get_option('glib'))
gobject_dep = dependency('gobject-2.0', required: get_option('gobject'))
graphite2_dep = dependency('graphite2', required: get_option('graphite2'))
graphite_dep = dependency('graphite2', required: get_option('graphite'))
-if cpp.get_argument_syntax() == 'msvc'
+# Try pkgconfig name
+icu_dep = dependency('icu-uc', required: false)
+if not icu_dep.found()
+ # Try cmake name
icu_dep = dependency('ICU',
- required: get_option('icu'),
+ required: false,
components: 'uc',
method: 'cmake')
-else
- icu_dep = dependency('icu-uc',
- required: get_option('icu'),
- method: 'pkg-config')
+endif
+if not icu_dep.found()
+ # Subproject fallback if icu option is enabled
+ icu_dep = dependency('icu-uc', required: get_option('icu'))
endif
if icu_dep.found() and icu_dep.type_name() == 'pkgconfig'
@@ -118,7 +132,7 @@ if not get_option('cairo').disabled()
cairo_ft_dep = dependency('cairo-ft', required: false)
if (not cairo_dep.found() and
- cpp.get_id() == 'msvc' and
+ cpp.get_argument_syntax() == 'msvc' and
cpp.has_header('cairo.h'))
cairo_dep = cpp.find_library('cairo', required: false)
if cairo_dep.found() and cpp.has_function('cairo_ft_font_face_create_for_ft_face',

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES C)
find_package(harfbuzz REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE harfbuzz::harfbuzz)
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)

View File

@@ -0,0 +1,10 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"build/gcc-12-x86_64-gnu17-release/generators/CMakePresets.json",
"build/gcc-11.5-x86_64-17-release/generators/CMakePresets.json"
]
}

View File

@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
test_type = "explicit"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
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], "test_package")
self.run(bin_path, env="conanrun")

View File

@@ -0,0 +1,9 @@
#include <stdio.h>
#include <string.h>
#include <hb.h>
int main() {
const char *version = hb_version_string();
printf("harfbuzz version: %s\n", version);
return 0;
}

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)

View File

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

View File

@@ -0,0 +1,17 @@
versions:
"8.3.0":
folder: all
"8.2.2":
folder: all
"8.2.1":
folder: all
"8.1.1":
folder: all
"8.0.1":
folder: all
"7.3.0":
folder: all
"6.0.0":
folder: all
"5.1.0":
folder: all