From c6d616cc41561cc0029050e579b36cb5084a05ed Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 17 Oct 2022 22:41:51 -0400 Subject: [PATCH] Generate and install hb-features.h This header has defines for all the optional dependendencies that come with their own Harfbuzz headers, so you can do: #include #ifdef HB_HAS_DIRECTWRITE #include #endif --- src/Makefile.am | 42 ++++++++++++++++++- src/hb-features.h.in | 96 ++++++++++++++++++++++++++++++++++++++++++++ src/meson.build | 18 +++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/hb-features.h.in diff --git a/src/Makefile.am b/src/Makefile.am index 225444e32..d8f68ae05 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,9 @@ HBLIBS += $(GLIB_LIBS) HBDEPS += $(GLIB_DEPS) HBSOURCES += $(HB_GLIB_sources) HBHEADERS += $(HB_GLIB_headers) +HB_HAS_GLIB_DEF = define HB_HAS_GLIB 1 +else +HB_HAS_GLIB_DEF = undef HB_HAS_GLIB endif if HAVE_FREETYPE @@ -55,6 +58,9 @@ HBLIBS += $(FREETYPE_LIBS) HBDEPS += $(FREETYPE_DEPS) HBSOURCES += $(HB_FT_sources) HBHEADERS += $(HB_FT_headers) +HB_HAS_FREETYPE_DEF = define HB_HAS_FREETYPE 1 +else +HB_HAS_FREETYPE_DEF = undef HB_HAS_FREETYPE endif if HAVE_GRAPHITE2 @@ -63,6 +69,9 @@ HBLIBS += $(GRAPHITE2_LIBS) HBDEPS += $(GRAPHITE2_DEPS) HBSOURCES += $(HB_GRAPHITE2_sources) HBHEADERS += $(HB_GRAPHITE2_headers) +HB_HAS_GRAPHITE_DEF = define HB_HAS_GRAPHITE 1 +else +HB_HAS_GRAPHITE_DEF = undef HB_HAS_GRAPHITE endif if HAVE_UNISCRIBE @@ -70,6 +79,9 @@ HBCFLAGS += $(UNISCRIBE_CFLAGS) HBNONPCLIBS += $(UNISCRIBE_LIBS) HBSOURCES += $(HB_UNISCRIBE_sources) HBHEADERS += $(HB_UNISCRIBE_headers) +HB_HAS_UNISCRIBE_DEF = define HB_HAS_UNISCRIBE 1 +else +HB_HAS_UNISCRIBE_DEF = undef HB_HAS_UNISCRIBE endif if HAVE_DIRECTWRITE @@ -77,6 +89,9 @@ HBCFLAGS += $(DIRECTWRITE_CXXFLAGS) HBNONPCLIBS += $(DIRECTWRITE_LIBS) HBSOURCES += $(HB_DIRECTWRITE_sources) HBHEADERS += $(HB_DIRECTWRITE_headers) +HB_HAS_DIRECTWRITE_DEF = define HB_HAS_DIRECTWRITE 1 +else +HB_HAS_DIRECTWRITE_DEF = undef HB_HAS_DIRECTWRITE endif if HAVE_GDI @@ -84,6 +99,9 @@ HBCFLAGS += $(GDI_CXXFLAGS) HBNONPCLIBS += $(GDI_LIBS) HBSOURCES += $(HB_GDI_sources) HBHEADERS += $(HB_GDI_headers) +HB_HAS_GDI_DEF = define HB_HAS_GDI 1 +else +HB_HAS_GDI_DEF = undef HB_HAS_GDI endif if HAVE_CORETEXT @@ -91,6 +109,9 @@ HBCFLAGS += $(CORETEXT_CFLAGS) HBNONPCLIBS += $(CORETEXT_LIBS) HBSOURCES += $(HB_CORETEXT_sources) HBHEADERS += $(HB_CORETEXT_headers) +HB_HAS_CORETEXT_DEF = define HB_HAS_CORETEXT 1 +else +HB_HAS_CORETEXT_DEF = undef HB_HAS_CORETEXT endif @@ -147,7 +168,7 @@ pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = harfbuzz.pc cmakedir = $(libdir)/cmake/harfbuzz cmake_DATA = harfbuzz-config.cmake -EXTRA_DIST += hb-version.h.in harfbuzz.pc.in harfbuzz-config.cmake.in +EXTRA_DIST += hb-version.h.in hb-features.h.in harfbuzz.pc.in harfbuzz-config.cmake.in lib_LTLIBRARIES += libharfbuzz-subset.la libharfbuzz_subset_la_LINK = $(chosen_linker) $(libharfbuzz_subset_la_LDFLAGS) @@ -178,6 +199,7 @@ HBCFLAGS += $(ICU_CFLAGS) HBLIBS += $(ICU_LIBS) HBSOURCES += $(HB_ICU_sources) HBHEADERS += $(HB_ICU_headers) +HB_HAS_ICU_DEF = define HB_HAS_ICU 1 else lib_LTLIBRARIES += libharfbuzz-icu.la libharfbuzz_icu_la_SOURCES = $(HB_ICU_sources) @@ -187,6 +209,7 @@ libharfbuzz_icu_la_LIBADD = $(ICU_LIBS) libharfbuzz.la EXTRA_libharfbuzz_icu_la_DEPENDENCIES = $(harfbuzz_icu_def_dependency) pkginclude_HEADERS += $(HB_ICU_headers) pkgconfig_DATA += harfbuzz-icu.pc +HB_HAS_ICU_DEF = undef HB_HAS_ICU endif endif EXTRA_DIST += harfbuzz-icu.pc.in @@ -226,6 +249,23 @@ EXTRA_DIST += \ $(NULL) +BUILT_SOURCES += \ + hb-features.h + +hb-features.h: hb-features.h.in $(top_srcdir)/configure.ac + $(AM_V_GEN) $(SED) \ + -e 's/mesondefine HB_HAS_FREETYPE/$(HB_HAS_FREETYPE_DEF)/' \ + -e 's/mesondefine HB_HAS_GDI/$(HB_HAS_GDI_DEF)/' \ + -e 's/#mesondefine HB_HAS_GDI/$(HB_HAS_GDI_DEF)/' \ + -e 's/#mesondefine HB_HAS_GRAPHITE/$(HB_HAS_GRAPHITE_DEF)/' \ + -e 's/#mesondefine HB_HAS_GLIB/$(HB_HAS_GLIB_DEF)/' \ + -e 's/#mesondefine HB_HAS_UNISCRIBE/$(HB_HAS_UNISCRIBE_DEF)/' \ + -e 's/#mesondefine HB_HAS_DIRECTWRITE/$(HB_HAS_DIRECTWRITE_DEF)/' \ + -e 's/#mesondefine HB_HAS_CORETEXT/$(HB_HAS_CORETEXT_DEF)/' \ + -e 's/#mesondefine HB_HAS_ICU/$(HB_HAS_ICU_DEF)/' \ + "$<" > "$@" || ($(RM) "$@"; false) + + %.pc: %.pc.in $(top_builddir)/config.status $(AM_V_GEN) \ $(SED) -e 's@%prefix%@$(prefix)@g' \ diff --git a/src/hb-features.h.in b/src/hb-features.h.in new file mode 100644 index 000000000..30ebf6519 --- /dev/null +++ b/src/hb-features.h.in @@ -0,0 +1,96 @@ +/* + * Copyright © 2022 Red Hat, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#if !defined(HB_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR) +#error "Include instead." +#endif + +#ifndef HB_FEATURES_H +#define HB_FEATURES_H + +#include "hb-common.h" + +HB_BEGIN_DECLS + + +/** + * HB_HAS_FREETYPE: + * + * Defined if Harfbuzz has been built with Freetype support. + */ +#mesondefine HB_HAS_FREETYPE + +/** + * HB_HAS_GDI: + * + * Defined if Harfbuzz has been built with GDI support. + */ +#mesondefine HB_HAS_GDI + +/** + * HB_HAS_GRAPHITE: + * + * Defined if Harfbuzz has been built with Graphite support. + */ +#mesondefine HB_HAS_GRAPHITE + +/** + * HB_HAS_GLIB: + * + * Defined if Harfbuzz has been built with GLib support. + */ +#mesondefine HB_HAS_GLIB + +/** + * HB_HAS_UNISCRIBE: + * + * Defined if Harfbuzz has been built with Uniscribe support. + */ +#mesondefine HB_HAS_UNISCRIBE + +/** + * HB_HAS_DIRECTWRITE: + * + * Defined if Harfbuzz has been built with DirectWrite support. + */ +#mesondefine HB_HAS_DIRECTWRITE + +/** + * HB_HAS_CORETEXT: + * + * Defined if Harfbuzz has been built with CoreText support. + */ +#mesondefine HB_HAS_CORETEXT + +/** + * HB_HAS_ICU: + * + * Defined if Harfbuzz has been built with ICU support. + */ +#mesondefine HB_HAS_ICU + + +HB_END_DECLS + +#endif /* HB_FEATURES_H */ diff --git a/src/meson.build b/src/meson.build index d53e77b5f..133f9fe36 100644 --- a/src/meson.build +++ b/src/meson.build @@ -414,33 +414,40 @@ harfbuzz_deps = [thread_dep, m_dep] + harfbuzz_extra_deps libharfbuzz_link_language = 'c' +hb_features = configuration_data() + if conf.get('HAVE_FREETYPE', 0) == 1 hb_sources += hb_ft_sources hb_headers += hb_ft_headers harfbuzz_deps += [freetype_dep] + hb_features.set('HB_HAS_FREETYPE', 1) endif if conf.get('HAVE_GDI', 0) == 1 hb_sources += hb_gdi_sources hb_headers += hb_gdi_headers harfbuzz_deps += gdi_uniscribe_deps + hb_features.set('HB_HAS_GDI', 1) endif if conf.get('HAVE_GRAPHITE2', 0) == 1 hb_sources += hb_graphite2_sources hb_headers += hb_graphite2_headers harfbuzz_deps += [graphite2_dep, graphite_dep] + hb_features.set('HB_HAS_GRAPHITE', 1) endif if conf.get('HAVE_GLIB', 0) == 1 hb_sources += hb_glib_sources hb_headers += hb_glib_headers harfbuzz_deps += [glib_dep] + hb_features.set('HB_HAS_GLIB', 1) endif if conf.get('HAVE_UNISCRIBE', 0) == 1 hb_sources += hb_uniscribe_sources hb_headers += hb_uniscribe_headers + hb_features.set('HB_HAS_UNISCRIBE', 1) endif if conf.get('HAVE_DIRECTWRITE', 0) == 1 @@ -448,12 +455,14 @@ if conf.get('HAVE_DIRECTWRITE', 0) == 1 hb_headers += hb_directwrite_headers # hb-directwrite needs a C++ linker libharfbuzz_link_language = 'cpp' + hb_features.set('HB_HAS_DIRECTWRITE', 1) endif if conf.get('HAVE_CORETEXT', 0) == 1 hb_sources += hb_coretext_sources hb_headers += hb_coretext_headers harfbuzz_deps += coretext_deps + hb_features.set('HB_HAS_CORETEXT', 1) endif have_icu = conf.get('HAVE_ICU', 0) == 1 @@ -463,8 +472,17 @@ if have_icu and have_icu_builtin hb_sources += hb_icu_sources hb_headers += hb_icu_headers harfbuzz_deps += [icu_dep] + hb_features.set('HB_HAS_ICU', 1) endif +hb_features_h = configure_file(input: 'hb-features.h.in', + output: 'hb-features.h', + configuration: hb_features, + install: true, + install_dir: get_option('includedir') / meson.project_name()) + +# Base and default-included sources and headers + # harfbuzz gen_def = find_program('gen-def.py')