[gimp] libgimpwidgets: fix meson/mingw-w64 build and relocatable builds.



commit 8025962a20ae970c8b285ad882abcfa7b68946c2
Author: Jehan <jehan girinstud io>
Date:   Tue Jul 6 13:26:24 2021 +0200

    libgimpwidgets: fix meson/mingw-w64 build and relocatable builds.
    
    While passing the DATADIR macro works fine natively on Linux, it somehow
    failed with the mingw-w64 build with a very weird error:
    
    > <command-line>: error: expected identifier or '(' before string constant
    
    I could not understand what it means, as the '-DDATADIR="/some/path"'
    syntax is completely fine as far as I can see.
    Anyway since I see that DATAROOTDIR is already defined in meson config.h
    (but not in the autotools build, just the meson one!), and using
    datarootdir instead of datadir seems to be just fine (actually maybe
    even more appropriate when it comes to looking up the hicolor
    application icons), I just switched to using it.
    
    In the same time, I realized that my code using build-time macros won't
    work for relocatable builds anyway. So this commit also adds a bit of
    code path variant using gimp_installation_directory() in the case of
    ENABLE_RELOCATABLE_RESOURCES code path.

 libgimpwidgets/Makefile.am           |  2 +-
 libgimpwidgets/gimpwidgets-private.c | 56 ++++++++++++++++++++++++------------
 libgimpwidgets/meson.build           |  4 +--
 3 files changed, 40 insertions(+), 22 deletions(-)
---
diff --git a/libgimpwidgets/Makefile.am b/libgimpwidgets/Makefile.am
index d1a7726edd..2e99f00721 100644
--- a/libgimpwidgets/Makefile.am
+++ b/libgimpwidgets/Makefile.am
@@ -56,7 +56,7 @@ libgimpwidgetsincludedir = $(includedir)/gimp-$(GIMP_API_VERSION)/libgimpwidgets
 AM_CPPFLAGS = \
        -DG_LOG_DOMAIN=\"LibGimpWidgets\"       \
        -DGIMP_WIDGETS_COMPILATION              \
-       -DDATADIR=\""$(datadir)"\"              \
+       -DDATAROOTDIR=\""$(datarootdir)"\"      \
        -I$(top_srcdir)                         \
        $(GEGL_CFLAGS)                          \
        $(GTK_CFLAGS)                           \
diff --git a/libgimpwidgets/gimpwidgets-private.c b/libgimpwidgets/gimpwidgets-private.c
index 83c46b6e90..f435c35b34 100644
--- a/libgimpwidgets/gimpwidgets-private.c
+++ b/libgimpwidgets/gimpwidgets-private.c
@@ -65,8 +65,9 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
                    GimpGetColorFunc      get_background_func,
                    GimpEnsureModulesFunc ensure_modules_func)
 {
-  const gchar *svg_icon = DATADIR "/icons/hicolor/scalable/apps/gimp.svg";
   GList       *icons = NULL;
+  gchar       *base_dir;
+  gchar       *path;
   GdkPixbuf   *pixbuf;
 
   g_return_if_fail (standard_help_func != NULL);
@@ -83,6 +84,12 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
 
   gimp_icons_init ();
 
+#ifdef ENABLE_RELOCATABLE_RESOURCES
+  base_dir = g_build_filename (gimp_installation_directory (), "share", "icons", "hicolor", NULL);
+#else
+  base_dir = g_build_filename (DATAROOTDIR, "icons", "hicolor", NULL);
+#endif
+
   /* Loading the application icons. Unfortunately GTK doesn't know how
    * to load any size from a single SVG, so we have to generate common
    * sizes ourselves.
@@ -90,31 +97,40 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
    * then the application icon is dependant to the theme and for now at
    * least, we want the installed icon.
    */
-  pixbuf = gdk_pixbuf_new_from_file (DATADIR "/icons/hicolor/16x16/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "16x16/apps/gimp.png", NULL);
+  pixbuf = gdk_pixbuf_new_from_file (DATAROOTDIR "/icons/hicolor/16x16/apps/gimp.png", NULL);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
   else
-    g_warning ("Application icon missing: %s", DATADIR "/icons/hicolor/16x16/apps/gimp.png");
+    g_warning ("Application icon missing: %s", path);
+  g_free (path);
 
-  pixbuf = gdk_pixbuf_new_from_file (DATADIR "/icons/hicolor/32x32/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "32x32/apps/gimp.png", NULL);
+  pixbuf = gdk_pixbuf_new_from_file (DATAROOTDIR "/icons/hicolor/32x32/apps/gimp.png", NULL);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
   else
-    g_warning ("Application icon missing: %s", DATADIR "/icons/hicolor/32x32/apps/gimp.png");
+    g_warning ("Application icon missing: %s", path);
+  g_free (path);
 
-  pixbuf = gdk_pixbuf_new_from_file (DATADIR "/icons/hicolor/48x48/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "48x48/apps/gimp.png", NULL);
+  pixbuf = gdk_pixbuf_new_from_file (DATAROOTDIR "/icons/hicolor/48x48/apps/gimp.png", NULL);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
   else
-    g_warning ("Application icon missing: %s", DATADIR "/icons/hicolor/48x48/apps/gimp.png");
+    g_warning ("Application icon missing: %s", path);
+  g_free (path);
 
-  pixbuf = gdk_pixbuf_new_from_file (DATADIR "/icons/hicolor/64x64/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "64x64/apps/gimp.png", NULL);
+  pixbuf = gdk_pixbuf_new_from_file (DATAROOTDIR "/icons/hicolor/64x64/apps/gimp.png", NULL);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
   else
-    g_warning ("Application icon missing: %s", DATADIR "/icons/hicolor/64x64/apps/gimp.png");
+    g_warning ("Application icon missing: %s", path);
+  g_free (path);
 
-  pixbuf = gdk_pixbuf_new_from_file_at_size (svg_icon, 128, 128, NULL);
+  path   = g_build_filename (base_dir, "scalable/apps/gimp.svg", NULL);
+  pixbuf = gdk_pixbuf_new_from_file_at_size (path, 128, 128, NULL);
   if (pixbuf)
     {
       /* Various common sizes from the same SVG. Why I go into such
@@ -124,31 +140,34 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
        */
       icons = g_list_prepend (icons, pixbuf);
 
-      pixbuf = gdk_pixbuf_new_from_file_at_size (svg_icon, 144, 144, NULL);
+      pixbuf = gdk_pixbuf_new_from_file_at_size (path, 144, 144, NULL);
       icons = g_list_prepend (icons, pixbuf);
 
-      pixbuf = gdk_pixbuf_new_from_file_at_size (svg_icon, 160, 160, NULL);
+      pixbuf = gdk_pixbuf_new_from_file_at_size (path, 160, 160, NULL);
       icons = g_list_prepend (icons, pixbuf);
 
-      pixbuf = gdk_pixbuf_new_from_file_at_size (svg_icon, 176, 176, NULL);
+      pixbuf = gdk_pixbuf_new_from_file_at_size (path, 176, 176, NULL);
       icons = g_list_prepend (icons, pixbuf);
 
-      pixbuf = gdk_pixbuf_new_from_file_at_size (svg_icon, 192, 192, NULL);
+      pixbuf = gdk_pixbuf_new_from_file_at_size (path, 192, 192, NULL);
       icons = g_list_prepend (icons, pixbuf);
 
-      pixbuf = gdk_pixbuf_new_from_file_at_size (svg_icon, 224, 224, NULL);
+      pixbuf = gdk_pixbuf_new_from_file_at_size (path, 224, 224, NULL);
       icons = g_list_prepend (icons, pixbuf);
     }
   else
     {
-      g_warning ("Application icon missing: %s", svg_icon);
+      g_warning ("Application icon missing: %s", path);
     }
+  g_free (path);
 
-  pixbuf = gdk_pixbuf_new_from_file (DATADIR "/icons/hicolor/256x256/apps/gimp.png", NULL);
+  path   = g_build_filename (base_dir, "256x256/apps/gimp.png", NULL);
+  pixbuf = gdk_pixbuf_new_from_file (DATAROOTDIR "/icons/hicolor/256x256/apps/gimp.png", NULL);
   if (pixbuf)
     icons = g_list_prepend (icons, pixbuf);
   else
-    g_warning ("Application icon missing: %s", DATADIR "/icons/hicolor/256x256/apps/gimp.png");
+    g_warning ("Application icon missing: %s", path);
+  g_free (path);
 
   gtk_window_set_default_icon_list (icons);
   g_list_free_full (icons, g_object_unref);
@@ -156,6 +175,7 @@ gimp_widgets_init (GimpHelpFunc          standard_help_func,
   gimp_widgets_init_foreign_enums ();
 
   gimp_widgets_initialized = TRUE;
+  g_free (base_dir);
 }
 
 /* clean up babl (in particular, so that the fish cache is constructed) if the
diff --git a/libgimpwidgets/meson.build b/libgimpwidgets/meson.build
index 3cf15959c8..488ce7ad5f 100644
--- a/libgimpwidgets/meson.build
+++ b/libgimpwidgets/meson.build
@@ -189,9 +189,7 @@ libgimpwidgets = library('gimpwidgets-'+ gimp_api_version,
   dependencies: [
     gegl, gtk3, lcms, math
   ],
-  c_args: [ '-DG_LOG_DOMAIN="LibGimpWidgets"', '-DGIMP_WIDGETS_COMPILATION',
-            '-DDATADIR="@0@"'.format(prefix / get_option('datadir')),
-  ],
+  c_args: [ '-DG_LOG_DOMAIN="LibGimpWidgets"', '-DGIMP_WIDGETS_COMPILATION', ],
   link_with: [
     libgimpbase,
     libgimpcolor,


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