[pango] build: Add fallbacks for finding non-GNOME deps on MSVC



commit 18fb749d658e86edad8145a3032c4b6e3be48d72
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Aug 18 17:56:44 2017 +0800

    build: Add fallbacks for finding non-GNOME deps on MSVC
    
    Many of Pango's dependencies do not support a build system for Visual
    Studio that would generate the pkg-config files for them, so we need to
    try to look for them using cc.has_header() and cc.find_library() for
    them, namely for Cairo, FreeType, FontConfig and HarfBuzz as fallbacks.
    
    For Cairo, things are more complicated as there are multiple build
    options and configurations for it, so we need to check for those that we
    need after we find the Cairo headers and libraries by:
    
    -Including the respective headers (for cairo-win32.h, cairo-ps.h,
     cairo-pdf.h, cairo-quartz.h and cairo-xlib.h, since these features
     must have been enabled when Cairo is built and installed in order for
     those headers to be succesfully included)
    -For pangocairo with FreeType support, we need to check whether the
     FontConfig support is built into Cairo as well, as FontConfig support
     is actually required in Cairo for this.
    -For Cairo/PNG output surface support, check whether Cairo is built with
     PNG output surface support.
    
    We also need to update how pangocairo.pc and pangoft2 are generated:
    -On builds where pkg-config files can be found for cairo, freetype,
     fontconfig and/or harfbuzz:
     Generate it with "Requires: pango <depedencies>" as before, otherwise
     for MSVC builds where we find these libraries manually, we don't put
     these packages under "Requires:..." or "Requires.private:...", but
     instead put them under "Libs:", linking to each dep as -l<.lib file
     name>
    
    This is so that pangocairo.pc and pangooft2.pc can be correctly used by
    items that need to make use of it, such as g-ir-scanner.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783274

 configure.ac     |   19 +++++++
 meson.build      |  147 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 pangocairo.pc.in |    4 +-
 pangoft2.pc.in   |    6 +-
 4 files changed, 164 insertions(+), 12 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index cc76b4a..bc15292 100644
--- a/configure.ac
+++ b/configure.ac
@@ -423,6 +423,25 @@ if $have_cairo ; then
   AC_SUBST(PKGCONFIG_CAIRO_REQUIRES)
 fi
 
+# To compensate for Meson builds on MSVC where pkg-config files may well not be
+# available for cairo, harfbuzz, freetype2 and fontconfig
+CAIRO_PC="cairo"
+FREETYPE2_PC="freetype2"
+FONTCONFIG_PC="fontconfig"
+HARFBUZZ_PC="harfbuzz"
+AC_SUBST(CAIRO_PC)
+AC_SUBST(FREETYPE2_PC)
+AC_SUBST(FONTCONFIG_PC)
+AC_SUBST(HARFBUZZ_PC)
+CAIRO_LIB=
+FREETYPE2_LIB=
+FONTCONFIG_LIB=
+HARFBUZZ_LIB=
+AC_SUBST(CAIRO_LIB)
+AC_SUBST(FREETYPE2_LIB)
+AC_SUBST(FONTCONFIG_LIB)
+AC_SUBST(HARFBUZZ_LIB)
+
 AM_CONDITIONAL(HAVE_CAIRO, $have_cairo)
 AM_CONDITIONAL(HAVE_CAIRO_PNG, $have_cairo_png)
 AM_CONDITIONAL(HAVE_CAIRO_PS, $have_cairo_ps)
diff --git a/meson.build b/meson.build
index 5133d5c..98c5c0f 100644
--- a/meson.build
+++ b/meson.build
@@ -218,13 +218,52 @@ if thai_dep.found()
   pango_deps += thai_dep
 endif
 
+# These are for the various .pc files so that things will link
+# properly, depending on whether we have the pkg-config files
+# for those non-GNOME dependencies, or when we find them manually
+# for MSVC builds, as their MSVC build systems do not generate
+# pkg-config files for them
+cairo_pc = ''
+cairo_lib = ''
+harfbuzz_pc=''
+freetype2_pc=''
+fontconfig_pc=''
+harfbuzz_lib=''
+freetype2_lib=''
+fontconfig_lib=''
+
 harfbuzz_dep = dependency('harfbuzz', version: harfbuzz_req_version, required: false)
 if harfbuzz_dep.found()
+  harfbuzz_pc = 'harfbuzz'
+else
+  if cc.get_id() == 'msvc' and cc.has_header('hb.h')
+    # The CMake build files for HarfBuzz (which is used for MSVC builds) do not
+    # generate pkg-config files, so look for harfbuzz.lib
+    harfbuzz_dep = cc.find_library('harfbuzz', required: false)
+    if harfbuzz_dep.found()
+      harfbuzz_lib = '-lharfbuzz'
+    endif
+  endif
+endif
+if harfbuzz_dep.found()
   pango_deps += harfbuzz_dep
 endif
 
 fontconfig_dep = dependency('fontconfig', version: fontconfig_req_version, required: false)
 if fontconfig_dep.found()
+  fontconfig_pc = 'fontconfig'
+else
+  if cc.get_id() == 'msvc' and cc.has_header('fontconfig/fontconfig.h')
+    # Look for the Visual Studio-style import library if FontConfig's .pc file cannot be
+    # found on Visual Studio
+    fontconfig_dep = cc.find_library('fontconfig', required: false)
+    if fontconfig_dep.found()
+      fontconfig_lib = '-lfontconfig'
+    endif
+  endif
+endif
+
+if fontconfig_dep.found()
   pango_deps += fontconfig_dep
 
   if cc.has_function('FcWeightFromOpenTypeDouble', dependencies: fontconfig_dep)
@@ -236,6 +275,21 @@ endif
 # We require both fontconfig and freetype if we are to have either.
 freetype_dep = dependency('freetype2', required: false)
 
+if freetype_dep.found()
+  freetype2_pc = 'freetype2'
+else
+  if cc.get_id() == 'msvc' and cc.has_header('ft2build.h')
+    foreach ft2_lib: ['freetype', 'freetypemt']
+      if not freetype_dep.found()
+        freetype_dep = cc.find_library(ft2_lib, required: false)
+        if freetype_dep.found()
+          freetype2_lib = '-l@0@'.format(ft2_lib)
+        endif
+      endif
+    endforeach
+  endif
+endif
+
 # To build pangoft2, we need HarfBuzz, FontConfig and FreeType
 build_pangoft2 = harfbuzz_dep.found() and fontconfig_dep.found() and freetype_dep.found()
 if build_pangoft2
@@ -263,22 +317,34 @@ if host_system == 'darwin'
   endif
 endif
 
+cairo_pkgconfig_found = false
 cairo_dep = dependency('cairo', version: cairo_req_version, required: false)
+
 if cairo_dep.found()
+  cairo_pkgconfig_found = true
+else
+  if cc.get_id() == 'msvc' and cc.has_header('cairo.h')
+    cairo_dep = cc.find_library('cairo', required: false)
+  endif
+endif
+
+pango_font_backends = []
+pango_cairo_backends = []
+
+if cairo_pkgconfig_found
   # Check the following Cairo font backends
   # - dependency
   # - version
   # - define
   # - backend name
   # Note that Cairo can be built with FreeType but without FontConfig
+
   cairo_font_backends = [
     [ 'cairo-ft', cairo_req_version, 'HAVE_CAIRO_FREETYPE', 'freetype', ],
     [ 'cairo-win32', cairo_req_version, 'HAVE_CAIRO_WIN32', 'win32', ],
     [ 'cairo-quartz', cairo_req_version, 'HAVE_CAIRO_QUARTZ', 'quartz', ],
   ]
 
-  pango_font_backends = []
-
   foreach b: cairo_font_backends
     dep = dependency(b[0], version: b[1], required: false)
     if dep.found()
@@ -310,8 +376,6 @@ if cairo_dep.found()
     [ 'cairo-xlib', cairo_req_version, 'HAVE_CAIRO_XLIB', 'xlib', ],
   ]
 
-  pango_cairo_backends = []
-
   foreach b: cairo_surface_backends
     dep = dependency(b[0], version: b[1], required: false)
     if dep.found()
@@ -320,17 +384,78 @@ if cairo_dep.found()
     endif
   endforeach
 
+  # This is to set up pangocairo.pc so that things that refer to
+  # it will link correctly
+  cairo_pc = 'cairo'
+elif (cc.get_id() == 'msvc' and cairo_dep.found())
+  # Fallback: Look for Cairo items manually
+  # We need to check for headers for some
+  cairo_headers = [ 'win32', 'quartz', 'ps', 'pdf', 'xlib' ]
+
+  foreach header : cairo_headers
+    if cc.has_header('cairo-@0@.h'.format(header))
+      pango_conf.set('HAVE_CAIRO_@0@'.format(header.underscorify().to_upper()), 1)
+      if header == 'win32' or header == 'quartz'
+        pango_font_backends += header
+      else
+        pango_cairo_backends += header
+      endif
+    endif
+  endforeach
+
+  # Other cairo features that we need to check for symbols
+  # Note that Cairo with FreeType support can be without FontConfig
+  # support, so we must check for FontConfig support in Cairo
+  if cc.links('''#include <cairo-ft.h>
+                 int main() {
+                   FcPattern *p = NULL;
+                   cairo_ft_font_face_create_for_pattern (p);
+                   return 0;
+                 }''',
+                 dependencies: cairo_dep,
+                 name : 'Cairo is built with FreeType and FontConfig support')
+    if build_pangoft2
+      pango_conf.set('HAVE_CAIRO_FREETYPE', 1)
+      pango_font_backends += 'freetype'
+    endif
+  endif
+
+  if pango_font_backends.length() == 0
+    error('No Cairo font backends found')
+  endif
+
+  # Check for Cairo's libpng output surface support
+  if cc.links('''#include <cairo.h>
+                 #include <stdio.h>
+                 int main() {
+                   cairo_surface_t *s = NULL;
+                   const char *f = "abc.png";
+                   cairo_surface_write_to_png (s, f);
+                   return 0;
+                 }''',
+                 dependencies: cairo_dep,
+                 name : 'Cairo is built with PNG output surface support')
+    pango_conf.set('HAVE_CAIRO_PNG', 1)
+    pango_cairo_backends += 'png'
+  endif
+
+  # This is to set up pangocairo.pc so that things that refer to
+  # it will link correctly, when we don't have pkg-config files for cairo
+  cairo_lib = '-lcairo'
+endif
+
+if cairo_dep.found()
   pango_conf.set('HAVE_CAIRO', 1)
   pango_deps += cairo_dep
 
-  pangocairo_requires = []
+  pangocairo_requires = ''
 
   if pango_font_backends.contains('freetype')
-    pangocairo_requires += 'pangoft2'
+    pangocairo_requires += 'pangoft2 '
   endif
 
   if pango_font_backends.contains('win32')
-    pangocairo_requires += 'pangowin32'
+    pangocairo_requires += 'pangowin32 '
   endif
 endif
 
@@ -343,6 +468,14 @@ pkgconf.set('includedir', pango_includedir)
 pkgconf.set('VERSION', meson.project_version())
 pkgconf.set('PANGO_API_VERSION', pango_api_version)
 pkgconf.set('PKGCONFIG_CAIRO_REQUIRES', pangocairo_requires)
+pkgconf.set('CAIRO_PC', cairo_pc)
+pkgconf.set('CAIRO_LIB', cairo_lib)
+pkgconf.set('FREETYPE2_PC', freetype2_pc)
+pkgconf.set('FREETYPE2_LIB', freetype2_lib)
+pkgconf.set('FONTCONFIG_PC', fontconfig_pc)
+pkgconf.set('FONTCONFIG_LIB', fontconfig_lib)
+pkgconf.set('HARFBUZZ_PC', harfbuzz_pc)
+pkgconf.set('HARFBUZZ_LIB', harfbuzz_lib)
 
 pkgconf_files = [
   [ 'pango.pc' ],
diff --git a/pangocairo.pc.in b/pangocairo.pc.in
index 223f839..ea5e326 100644
--- a/pangocairo.pc.in
+++ b/pangocairo.pc.in
@@ -6,7 +6,7 @@ includedir=@includedir@
 Name: Pango Cairo
 Description: Cairo rendering support for Pango
 Version: @VERSION@
-Requires: pango cairo
+Requires: pango @CAIRO_PC@
 Requires.private: @PKGCONFIG_CAIRO_REQUIRES@
-Libs: -L${libdir} -lpangocairo-@PANGO_API_VERSION@
+Libs: -L${libdir} -lpangocairo-@PANGO_API_VERSION@ @CAIRO_LIB@
 Cflags: -I${includedir}/pango-1.0
diff --git a/pangoft2.pc.in b/pangoft2.pc.in
index ee8d643..42eea21 100644
--- a/pangoft2.pc.in
+++ b/pangoft2.pc.in
@@ -6,7 +6,7 @@ includedir=@includedir@
 Name: Pango FT2 and Pango Fc
 Description: Freetype 2.0 and fontconfig font support for Pango
 Version: @VERSION@
-Requires: pango freetype2 fontconfig
-Requires.private: harfbuzz
-Libs: -L${libdir} -lpangoft2-@PANGO_API_VERSION@
+Requires: pango @FREETYPE2_PC@ @FONTCONFIG_PC@
+Requires.private: @HARFBUZZ_PC@
+Libs: -L${libdir} -lpangoft2-@PANGO_API_VERSION@ @FREETYPE2_LIB@ @FONTCONFIG_LIB@ @HARFBUZZ_LIB@
 Cflags: -I${includedir}/pango-1.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]