Generate version and deprecation macros at build time
authorEmmanuele Bassi <ebassi@gnome.org>
Mon, 8 May 2023 18:39:35 +0000 (19:39 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Tue, 9 May 2023 15:43:25 +0000 (16:43 +0100)
Let's poach the same script used by GLib to avoid having to add all the
version macros by hand every time we increment the GTK version.

This is a work in progress:

- need to rename the GLIB_STATIC_COMPILATION check
- circular dependency: libgtkcss depends on gdkversionmacros.h, but libgdk
  depends on libgtkcss

build-aux/meson/gen-visibility-macros.py [new file with mode: 0755]
gdk/gdktypes.h
gdk/gdkversionmacros.h.in
gdk/meson.build
gtk/css/meson.build
meson.build

diff --git a/build-aux/meson/gen-visibility-macros.py b/build-aux/meson/gen-visibility-macros.py
new file mode 100755 (executable)
index 0000000..c75f50b
--- /dev/null
@@ -0,0 +1,201 @@
+#!/usr/bin/env python3
+#
+# SPDX-FileCopyrightText: 2022 Collabora Inc.
+#                         2023 Emmanuele Bassi
+#
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# Original author: Xavier Claessens <xclaesse@gmail.com>
+
+import argparse
+import textwrap
+from pathlib import Path
+
+
+# Disable line length warnings as wrapping the C code templates would be hard
+# flake8: noqa: E501
+
+
+def gen_versions_macros(args, current_major_version, current_minor_version, current_micro_version):
+    with args.out_path.open("w", encoding="utf-8") as ofile, args.in_path.open(
+        "r", encoding="utf-8"
+    ) as ifile:
+        for line in ifile.readlines():
+            if "@GDK_VERSIONS@" in line:
+                ofile.write(
+                    textwrap.dedent(
+                        f"""\
+                    /**
+                     * GDK_MAJOR_VERSION:
+                     *
+                     * The major version component of the library's version, e.g. "1" for "1.2.3".
+                     */
+                    #define GDK_MAJOR_VERSION ({current_major_version})
+
+                    /**
+                     * GDK_MINOR_VERSION:
+                     *
+                     * The minor version component of the library's version, e.g. "2" for "1.2.3".
+                     */
+                    #define GDK_MINOR_VERSION ({current_minor_version})
+
+                    /**
+                     * GDK_MICRO_VERSION:
+                     *
+                     * The micro version component of the library's version, e.g. "3" for "1.2.3".
+                     */
+                    #define GDK_MICRO_VERSION ({current_micro_version})
+                        """
+                        )
+                    )
+                for minor in range(0, current_minor_version + 2, 2):
+                    ofile.write(
+                        textwrap.dedent(
+                            f"""\
+                        /**
+                         * GDK_VERSION_{current_major_version}_{minor}:
+                         *
+                         * A macro that evaluates to the {current_major_version}.{minor} version of GTK, in a format
+                         * that can be used by the C pre-processor.
+                         *
+                         * Since: {current_major_version}.{minor}
+                         */
+                        #define GDK_VERSION_{current_major_version}_{minor} (G_ENCODE_VERSION ({current_major_version}, {minor}))
+                        """
+                        )
+                    )
+            else:
+                ofile.write(line)
+
+
+def gen_visibility_macros(args, current_major_version, current_minor_version, current_micro_version):
+    """
+    Generates a set of macros for each minor stable version of GTK
+
+    - GDK_DEPRECATED
+    - GDK_DEPRECATED_IN_…
+    - GDK_DEPRECATED_MACRO_IN_…
+    - GDK_DEPRECATED_ENUMERATOR_IN_…
+    - GDK_DEPRECATED_TYPE_IN_…
+
+    - GDK_AVAILABLE_IN_ALL
+    - GDK_AVAILABLE_IN_…
+    - GDK_AVAILABLE_STATIC_INLINE_IN_…
+    - GDK_AVAILABLE_MACRO_IN_…
+    - GDK_AVAILABLE_ENUMERATOR_IN_…
+    - GDK_AVAILABLE_TYPE_IN_…
+
+    - GDK_UNAVAILABLE(maj,min)
+    - GDK_UNAVAILABLE_STATIC_INLINE(maj,min)
+    """
+
+    ns = args.namespace
+    with args.out_path.open("w", encoding="utf-8") as f:
+        f.write(
+            textwrap.dedent(
+                f"""\
+            #pragma once
+
+            #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined({ns}_STATIC_COMPILATION)
+            #  define _{ns}_EXPORT __declspec(dllexport)
+            #  define _{ns}_IMPORT __declspec(dllimport)
+            #elif __GNUC__ >= 4
+            #  define _{ns}_EXPORT __attribute__((visibility("default")))
+            #  define _{ns}_IMPORT
+            #else
+            #  define _{ns}_EXPORT
+            #  define _{ns}_IMPORT
+            #endif
+            #ifdef {ns}_COMPILATION
+            #  define _{ns}_API _{ns}_EXPORT
+            #else
+            #  define _{ns}_API _{ns}_IMPORT
+            #endif
+
+            #define _{ns}_EXTERN _{ns}_API extern
+
+            #define {ns}_VAR _{ns}_EXTERN
+            #define {ns}_AVAILABLE_IN_ALL _{ns}_EXTERN
+
+            #ifdef GDK_DISABLE_DEPRECATION_WARNINGS
+            #define {ns}_DEPRECATED _{ns}_EXTERN
+            #define {ns}_DEPRECATED_FOR(f) _{ns}_EXTERN
+            #define {ns}_UNAVAILABLE(maj,min) _{ns}_EXTERN
+            #define {ns}_UNAVAILABLE_STATIC_INLINE(maj,min)
+            #else
+            #define {ns}_DEPRECATED G_DEPRECATED _{ns}_EXTERN
+            #define {ns}_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _{ns}_EXTERN
+            #define {ns}_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _{ns}_EXTERN
+            #define {ns}_UNAVAILABLE_STATIC_INLINE(maj,min) G_UNAVAILABLE(maj,min)
+            #endif
+            """
+            )
+        )
+        for minor in range(0, current_minor_version + 2, 2):
+            f.write(
+                textwrap.dedent(
+                    f"""
+                #if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_2_{minor}
+                #define {ns}_DEPRECATED_IN_{current_major_version}_{minor} {ns}_DEPRECATED
+                #define {ns}_DEPRECATED_IN_{current_major_version}_{minor}_FOR(f) {ns}_DEPRECATED_FOR (f)
+                #define {ns}_DEPRECATED_MACRO_IN_{current_major_version}_{minor} GDK_DEPRECATED_MACRO
+                #define {ns}_DEPRECATED_MACRO_IN_{current_major_version}_{minor}_FOR(f) GDK_DEPRECATED_MACRO_FOR (f)
+                #define {ns}_DEPRECATED_ENUMERATOR_IN_{current_major_version}_{minor} GDK_DEPRECATED_ENUMERATOR
+                #define {ns}_DEPRECATED_ENUMERATOR_IN_{current_major_version}_{minor}_FOR(f) GDK_DEPRECATED_ENUMERATOR_FOR (f)
+                #define {ns}_DEPRECATED_TYPE_IN_{current_major_version}_{minor} GDK_DEPRECATED_TYPE
+                #define {ns}_DEPRECATED_TYPE_IN_{current_major_version}_{minor}_FOR(f) GDK_DEPRECATED_TYPE_FOR (f)
+                #else
+                #define {ns}_DEPRECATED_IN_{current_major_version}_{minor} _{ns}_EXTERN
+                #define {ns}_DEPRECATED_IN_{current_major_version}_{minor}_FOR(f) _{ns}_EXTERN
+                #define {ns}_DEPRECATED_MACRO_IN_{current_major_version}_{minor}
+                #define {ns}_DEPRECATED_MACRO_IN_{current_major_version}_{minor}_FOR(f)
+                #define {ns}_DEPRECATED_ENUMERATOR_IN_{current_major_version}_{minor}
+                #define {ns}_DEPRECATED_ENUMERATOR_IN_{current_major_version}_{minor}_FOR(f)
+                #define {ns}_DEPRECATED_TYPE_IN_{current_major_version}_{minor}
+                #define {ns}_DEPRECATED_TYPE_IN_{current_major_version}_{minor}_FOR(f)
+                #endif
+
+                #if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_{current_major_version}_{minor}
+                #define {ns}_AVAILABLE_IN_{current_major_version}_{minor} {ns}_UNAVAILABLE ({current_major_version}, {minor})
+                #define {ns}_AVAILABLE_STATIC_INLINE_IN_{current_major_version}_{minor} GDK_UNAVAILABLE_STATIC_INLINE ({current_major_version}, {minor})
+                #define {ns}_AVAILABLE_MACRO_IN_{current_major_version}_{minor} GDK_UNAVAILABLE_MACRO ({current_major_version}, {minor})
+                #define {ns}_AVAILABLE_ENUMERATOR_IN_{current_major_version}_{minor} GDK_UNAVAILABLE_ENUMERATOR ({current_major_version}, {minor})
+                #define {ns}_AVAILABLE_TYPE_IN_{current_major_version}_{minor} GDK_UNAVAILABLE_TYPE ({current_major_version}, {minor})
+                #else
+                #define {ns}_AVAILABLE_IN_{current_major_version}_{minor} _{ns}_EXTERN
+                #define {ns}_AVAILABLE_STATIC_INLINE_IN_{current_major_version}_{minor}
+                #define {ns}_AVAILABLE_MACRO_IN_{current_major_version}_{minor}
+                #define {ns}_AVAILABLE_ENUMERATOR_IN_{current_major_version}_{minor}
+                #define {ns}_AVAILABLE_TYPE_IN_{current_major_version}_{minor}
+                #endif
+                """
+                )
+            )
+
+
+def main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("gtk_version", help="Current GLib version")
+    subparsers = parser.add_subparsers()
+
+    versions_parser = subparsers.add_parser(
+        "versions-macros", help="Generate versions macros"
+    )
+    versions_parser.add_argument("in_path", help="input file", type=Path)
+    versions_parser.add_argument("out_path", help="output file", type=Path)
+    versions_parser.set_defaults(func=gen_versions_macros)
+
+    visibility_parser = subparsers.add_parser(
+        "visibility-macros", help="Generate visibility macros"
+    )
+    visibility_parser.add_argument("namespace", help="Macro namespace")
+    visibility_parser.add_argument("out_path", help="output file", type=Path)
+    visibility_parser.set_defaults(func=gen_visibility_macros)
+
+    args = parser.parse_args()
+    version = [int(i) for i in args.gtk_version.split(".")]
+    args.func(args, version[0], version[1], version[2])
+
+
+if __name__ == "__main__":
+    main()
index 69136f7ab0a25f9ca48116325a79e33734c65bba..2b7804c85e2f572796f3627af7ffdf3fd1dc77d2 100644 (file)
  * (or GTK). One such setting is what windowing API backend is in use.
  */
 #include <gdk/gdkconfig.h>
+#include <gdk/gdkversionmacros.h>
+
+/* Visibility macros; must be included after the two headers above */
+#include <gdk/gdk-visibility.h>
 
 G_BEGIN_DECLS
 
index e8dd30eeb994a2a0fb130f7fc419532c7db4effe..0aa6348642460e29d737988e3e0f2fc34d6ca4a2 100644 (file)
 
 #include <glib.h>
 
-/**
- * GDK_MAJOR_VERSION:
- *
- * The major version component of the library's version, e.g. "1" for "1.2.3".
- */
-#define GDK_MAJOR_VERSION (@GTK_MAJOR_VERSION@)
-
-/**
- * GDK_MINOR_VERSION:
- *
- * The minor version component of the library's version, e.g. "2" for "1.2.3".
- */
-#define GDK_MINOR_VERSION (@GTK_MINOR_VERSION@)
-
-/**
- * GDK_MICRO_VERSION:
- *
- * The micro version component of the library's version, e.g. "3" for "1.2.3".
- */
-#define GDK_MICRO_VERSION (@GTK_MICRO_VERSION@)
-
 #ifndef _GDK_EXTERN
 #define _GDK_EXTERN extern
 #endif
 
-/**
- * GDK_DISABLE_DEPRECATION_WARNINGS:
- *
- * A macro that should be defined before including the `gdk.h` header.
- *
- * If this symbol is defined, no compiler warnings will be produced for
- * uses of deprecated GDK and GTK APIs.
+/* These macros are used to mark deprecated symbols in GLib headers,
+ * and thus have to be exposed in installed headers. But please
+ * do *not* use them in other projects. Instead define your own wrappers
+ * around it.
  */
 
-#ifdef GDK_DISABLE_DEPRECATION_WARNINGS
-#define GDK_DEPRECATED _GDK_EXTERN
-#define GDK_DEPRECATED_FOR(f) _GDK_EXTERN
-#define GDK_UNAVAILABLE(maj,min) _GDK_EXTERN
+#if !defined(GDK_DISABLE_DEPRECATION_WARNINGS) && \
+    (G_GNUC_CHECK_VERSION(4, 6) ||                 \
+     __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4))
+#define _GDK_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x))
+#define GDK_DEPRECATED_MACRO _GDK_GNUC_DO_PRAGMA(GCC warning "Deprecated pre-processor symbol")
+#define GDK_DEPRECATED_MACRO_FOR(f) \
+  _GDK_GNUC_DO_PRAGMA(GCC warning G_STRINGIFY (Deprecated pre-processor symbol: replace with #f))
+#define GDK_UNAVAILABLE_MACRO(maj,min) \
+  _GDK_GNUC_DO_PRAGMA(GCC warning G_STRINGIFY (Not available before maj.min))
 #else
-#define GDK_DEPRECATED G_DEPRECATED _GDK_EXTERN
-#define GDK_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _GDK_EXTERN
-#define GDK_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _GDK_EXTERN
+#define GDK_DEPRECATED_MACRO
+#define GDK_DEPRECATED_MACRO_FOR(f)
+#define GDK_UNAVAILABLE_MACRO(maj,min)
 #endif
 
-/* XXX: Every new stable minor release bump should add a macro here */
-
-/**
- * GDK_VERSION_4_0:
- *
- * A macro that evaluates to the 4.0 version of GDK, in a format
- * that can be used by the C pre-processor.
- */
-#define GDK_VERSION_4_0        (G_ENCODE_VERSION (4, 0))
-
-/**
- * GDK_VERSION_4_2:
- *
- * A macro that evaluates to the 4.2 version of GDK, in a format
- * that can be used by the C pre-processor.
- *
- * Since: 4.2
- */
-#define GDK_VERSION_4_2        (G_ENCODE_VERSION (4, 2))
-
-/**
- * GDK_VERSION_4_4:
- *
- * A macro that evaluates to the 4.4 version of GDK, in a format
- * that can be used by the C pre-processor.
- *
- * Since: 4.4
- */
-#define GDK_VERSION_4_4        (G_ENCODE_VERSION (4, 4))
-
-/**
- * GDK_VERSION_4_6:
- *
- * A macro that evaluates to the 4.6 version of GDK, in a format
- * that can be used by the C pre-processor.
- *
- * Since: 4.6
- */
-#define GDK_VERSION_4_6        (G_ENCODE_VERSION (4, 6))
-
-/**
- * GDK_VERSION_4_8:
- *
- * A macro that evaluates to the 4.8 version of GDK, in a format
- * that can be used by the C pre-processor.
- *
- * Since: 4.8
- */
-#define GDK_VERSION_4_8        (G_ENCODE_VERSION (4, 8))
-
-/**
- * GDK_VERSION_4_10:
- *
- * A macro that evaluates to the 4.10 version of GDK, in a format
- * that can be used by the C pre-processor.
- *
- * Since: 4.10
- */
-#define GDK_VERSION_4_10        (G_ENCODE_VERSION (4, 10))
+#if !defined(GDK_DISABLE_DEPRECATION_WARNINGS) && \
+    (G_GNUC_CHECK_VERSION(6, 1) ||                 \
+     (defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))))
+#define GDK_DEPRECATED_ENUMERATOR G_DEPRECATED
+#define GDK_DEPRECATED_ENUMERATOR_FOR(f) G_DEPRECATED_FOR(f)
+#define GDK_UNAVAILABLE_ENUMERATOR(maj,min) G_UNAVAILABLE(maj,min)
+#else
+#define GDK_DEPRECATED_ENUMERATOR
+#define GDK_DEPRECATED_ENUMERATOR_FOR(f)
+#define GDK_UNAVAILABLE_ENUMERATOR(maj,min)
+#endif
 
-/**
- * GDK_VERSION_4_12:
- *
- * A macro that evaluates to the 4.12 version of GDK, in a format
- * that can be used by the C pre-processor.
- *
- * Since: 4.12
- */
-#define GDK_VERSION_4_12        (G_ENCODE_VERSION (4, 12))
+#if !defined(GDK_DISABLE_DEPRECATION_WARNINGS) && \
+    (G_GNUC_CHECK_VERSION(3, 1) ||                 \
+     (defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))))
+#define GDK_DEPRECATED_TYPE G_DEPRECATED
+#define GDK_DEPRECATED_TYPE_FOR(f) G_DEPRECATED_FOR(f)
+#define GDK_UNAVAILABLE_TYPE(maj,min) G_UNAVAILABLE(maj,min)
+#else
+#define GDK_DEPRECATED_TYPE
+#define GDK_DEPRECATED_TYPE_FOR(f)
+#define GDK_UNAVAILABLE_TYPE(maj,min)
+#endif
 
+@GDK_VERSIONS@
 
 /* evaluates to the current stable version; for development cycles,
  * this means the next stable target, with a hard backstop to the
 # error "GDK_VERSION_MIN_REQUIRED must be >= GDK_VERSION_4_0"
 #endif
 
-#define GDK_AVAILABLE_IN_ALL                  _GDK_EXTERN
-
-/* XXX: Every new stable minor release should add a set of macros here */
-
-/* This is not really necessary for 4.0, since there can't be an
- * earlier version, and there are no deprecated symbols. We just
- * include it for completeness, and because it's easier to copy
- * this stanza every time a new development cycle starts.
- */
-#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_0
-# define GDK_AVAILABLE_IN_4_0                   GDK_UNAVAILABLE(4, 0)
-#else
-# define GDK_AVAILABLE_IN_4_0                   _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_0
-# define GDK_DEPRECATED_IN_4_0                  GDK_DEPRECATED
-# define GDK_DEPRECATED_IN_4_0_FOR(f)           GDK_DEPRECATED_FOR(f)
-#else
-# define GDK_DEPRECATED_IN_4_0                  _GDK_EXTERN
-# define GDK_DEPRECATED_IN_4_0_FOR(f)           _GDK_EXTERN
-#endif
-
-
-#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_2
-# define GDK_AVAILABLE_IN_4_2                   GDK_UNAVAILABLE(4, 2)
-#else
-# define GDK_AVAILABLE_IN_4_2                   _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_2
-# define GDK_DEPRECATED_IN_4_2                  GDK_DEPRECATED
-# define GDK_DEPRECATED_IN_4_2_FOR(f)           GDK_DEPRECATED_FOR(f)
-#else
-# define GDK_DEPRECATED_IN_4_2                  _GDK_EXTERN
-# define GDK_DEPRECATED_IN_4_2_FOR(f)           _GDK_EXTERN
-#endif
-
-
-#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_4
-# define GDK_AVAILABLE_IN_4_4                   GDK_UNAVAILABLE(4, 4)
-#else
-# define GDK_AVAILABLE_IN_4_4                   _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_4
-# define GDK_DEPRECATED_IN_4_4                  GDK_DEPRECATED
-# define GDK_DEPRECATED_IN_4_4_FOR(f)           GDK_DEPRECATED_FOR(f)
-#else
-# define GDK_DEPRECATED_IN_4_4                  _GDK_EXTERN
-# define GDK_DEPRECATED_IN_4_4_FOR(f)           _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_6
-# define GDK_AVAILABLE_IN_4_6                   GDK_UNAVAILABLE(4, 6)
-#else
-# define GDK_AVAILABLE_IN_4_6                   _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_6
-# define GDK_DEPRECATED_IN_4_6                  GDK_DEPRECATED
-# define GDK_DEPRECATED_IN_4_6_FOR(f)           GDK_DEPRECATED_FOR(f)
-#else
-# define GDK_DEPRECATED_IN_4_6                  _GDK_EXTERN
-# define GDK_DEPRECATED_IN_4_6_FOR(f)           _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_8
-# define GDK_AVAILABLE_IN_4_8                   GDK_UNAVAILABLE(4, 8)
-#else
-# define GDK_AVAILABLE_IN_4_8                   _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_8
-# define GDK_DEPRECATED_IN_4_8                  GDK_DEPRECATED
-# define GDK_DEPRECATED_IN_4_8_FOR(f)           GDK_DEPRECATED_FOR(f)
-#else
-# define GDK_DEPRECATED_IN_4_8                  _GDK_EXTERN
-# define GDK_DEPRECATED_IN_4_8_FOR(f)           _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_10
-# define GDK_AVAILABLE_IN_4_10                  GDK_UNAVAILABLE(4, 10)
-#else
-# define GDK_AVAILABLE_IN_4_10                  _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_10
-# define GDK_DEPRECATED_IN_4_10                 GDK_DEPRECATED
-# define GDK_DEPRECATED_IN_4_10_FOR(f)          GDK_DEPRECATED_FOR(f)
-#else
-# define GDK_DEPRECATED_IN_4_10                 _GDK_EXTERN
-# define GDK_DEPRECATED_IN_4_10_FOR(f)          _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MAX_ALLOWED < GDK_VERSION_4_12
-# define GDK_AVAILABLE_IN_4_12                  GDK_UNAVAILABLE(4, 12)
-#else
-# define GDK_AVAILABLE_IN_4_12                  _GDK_EXTERN
-#endif
-
-#if GDK_VERSION_MIN_REQUIRED >= GDK_VERSION_4_12
-# define GDK_DEPRECATED_IN_4_12                 GDK_DEPRECATED
-# define GDK_DEPRECATED_IN_4_12_FOR(f)          GDK_DEPRECATED_FOR(f)
-#else
-# define GDK_DEPRECATED_IN_4_12                 _GDK_EXTERN
-# define GDK_DEPRECATED_IN_4_12_FOR(f)          _GDK_EXTERN
-#endif
-
 #endif  /* __GDK_VERSION_MACROS_H__ */
index c83af4873d982d421e78f05429fa28c62d1c427b..f953b6efcc685ed5944de5a48730128bdea4f999 100644 (file)
@@ -146,7 +146,7 @@ gdk_enums = gnome.mkenums_simple('gdkenumtypes',
   sources: gdk_public_headers,
   decorator: 'GDK_AVAILABLE_IN_ALL',
   body_prefix: '#include "config.h"',
-  header_prefix: '#include "gdkversionmacros.h"',
+  header_prefix: '#include "gdkversionmacros.h"\n#include "gdk-visibility.h"',
   install_dir: gtk_includedir / 'gtk-4.0/gdk',
   install_header: true,
 )
@@ -183,11 +183,23 @@ gdkversion_cdata.set('GTK_MAJOR_VERSION', gtk_major_version)
 gdkversion_cdata.set('GTK_MINOR_VERSION', gtk_minor_version)
 gdkversion_cdata.set('GTK_MICRO_VERSION', gtk_micro_version)
 
-gdkversionmacros = configure_file(
+gdkversionmacros_h = custom_target(
   input: 'gdkversionmacros.h.in',
   output: 'gdkversionmacros.h',
-  configuration: gdkversion_cdata,
+  command: [gen_visibility_macros, meson.project_version(), 'versions-macros', '@INPUT@', '@OUTPUT@'],
+  install: true,
   install_dir: gtk_includedir / 'gtk-4.0/gdk',
+  # FIXME: Not needed with Meson >= 0.64.0
+  install_tag: 'devel',
+)
+
+gdk_visibility_h = custom_target(
+  output: 'gdk-visibility.h',
+  command: [gen_visibility_macros, meson.project_version(), 'visibility-macros', 'GDK', '@OUTPUT@'],
+  install: true,
+  install_dir: gtk_includedir / 'gtk-4.0/gdk',
+  # FIXME: Not needed with Meson >= 0.64.0
+  install_tag: 'devel',
 )
 
 gdkinc = include_directories('.')
@@ -197,7 +209,7 @@ gdkwayland_inc = include_directories('wayland')
 wlinc = include_directories('.')
 win32rcinc = include_directories('win32/rc')
 
-gdk_gen_headers = [gdkenum_h, gdkmarshal_h, gdkconfig, gdkversionmacros]
+gdk_gen_headers = [gdkenum_h, gdkmarshal_h, gdkconfig, gdkversionmacros_h, gdk_visibility_h]
 
 gdk_deps = [
   libm,
@@ -231,7 +243,8 @@ gdk_sources += [
   gdk_enums,
   gdk_marshalers,
   gdkresources,
-  gdkversionmacros,
+  gdkversionmacros_h,
+  gdk_visibility_h,
   gdk_private_h_sources,
   gdk_public_headers
 ]
index bf083f693e4ea1c39047fb1df1520c848ace8603..c56a5be78809d33a98d7231e5170b724dbb67744 100644 (file)
@@ -24,6 +24,8 @@ gtk_css_deps = [
   glib_dep,
   gobject_dep,
   platform_gio_dep,
+  gdkversionmacros_h,
+  gdk_visibility_h,
 ]
 
 gtk_css_enums = gnome.mkenums('gtkcssenumtypes',
index d8829671ee59979dc29afa69f523ddd74893a0eb..28066d8e3a14edbce3e803b59c4f6d340b8bfc75 100644 (file)
@@ -747,6 +747,8 @@ build_gir = gir.found() and (get_option('introspection').enabled() or
 
 project_build_root = meson.current_build_dir()
 
+gen_visibility_macros = find_program('build-aux/meson/gen-visibility-macros.py')
+
 subdir('gtk/css')
 subdir('gdk')
 subdir('gsk')