Fix symbol visibility macros on Windows

There is currently no `dllimport` attribute on any of our function,
which prevents MSVC to optimize function calls.

To fix that issue, we need to redeclare all our visibility macros for
each of our libraries, because when compiling e.g. GIO code, we need
dllimport in GLIB headers and dllexport in GIO headers. That means they
cannot use the same GLIB_AVAILABLE_* macro.

Since that's a lot of boilerplate to copy/paste after each version bump,
this MR generate all those macros using a python script.

Also simplify the meson side by using `gnu_symbol_visibility : 'hidden'`
keyword argument instead of passing the cflag manually.

This leaves only API index to add manually into glib-docs.xml when
bumping GLib version. That file cannot be generated because Meson does
not allow passing a buit file to gnome.gtkdoc()'s main_xml kwarg
unfortunately.
This commit is contained in:
Xavier Claessens 2022-10-03 10:36:04 -04:00
parent d40459c280
commit dcfc9f689e
30 changed files with 409 additions and 1655 deletions

View File

@ -3,7 +3,7 @@ gdbus_object_manager_example_doc = gnome.gtkdoc('gdbus-object-manager-example',
namespace : 'example',
dependencies : [libgdbus_example_objectmanager_dep],
src_dir : 'gio/tests/gdbus-object-manager-example',
scan_args : gtkdoc_common_scan_args + [
scan_args : [
'--rebuild-types',
],
install : false,

View File

@ -98,6 +98,7 @@ if get_option('gtk_doc')
'gwin32volumemonitor.h',
'thumbnail-verify.h',
'xdp-dbus.h',
'gio-visibility.h',
]
sections_files = files('gio-sections-common.txt')
@ -187,7 +188,8 @@ if get_option('gtk_doc')
mode : 'none',
dependencies : [libgio_dep, libgobject_dep, libglib_dep],
src_dir : 'gio',
scan_args : gtkdoc_common_scan_args + [
scan_args : [
'--ignore-decorators=' + ignore_decorators.replace('GLIB', 'GIO'),
'--rebuild-types',
'--ignore-headers=' + ' '.join(ignore_headers),
],

View File

@ -116,355 +116,22 @@ GLIB_MICRO_VERSION
GLIB_CHECK_VERSION
<SUBSECTION>
GLIB_VERSION_2_26
GLIB_VERSION_2_28
GLIB_VERSION_2_30
GLIB_VERSION_2_32
GLIB_VERSION_2_34
GLIB_VERSION_2_36
GLIB_VERSION_2_38
GLIB_VERSION_2_40
GLIB_VERSION_2_42
GLIB_VERSION_2_44
GLIB_VERSION_2_46
GLIB_VERSION_2_48
GLIB_VERSION_2_50
GLIB_VERSION_2_52
GLIB_VERSION_2_54
GLIB_VERSION_2_56
GLIB_VERSION_2_58
GLIB_VERSION_2_60
GLIB_VERSION_2_62
GLIB_VERSION_2_64
GLIB_VERSION_2_66
GLIB_VERSION_2_68
GLIB_VERSION_2_70
GLIB_VERSION_2_72
GLIB_VERSION_2_74
GLIB_VERSION_CUR_STABLE
GLIB_VERSION_PREV_STABLE
GLIB_VERSION_MIN_REQUIRED
GLIB_VERSION_MAX_ALLOWED
GLIB_DISABLE_DEPRECATION_WARNINGS
@GLIB_VERSIONS@
<SUBSECTION Private>
G_ENCODE_VERSION
GLIB_AVAILABLE_ENUMERATOR_IN_2_26
GLIB_AVAILABLE_ENUMERATOR_IN_2_28
GLIB_AVAILABLE_ENUMERATOR_IN_2_30
GLIB_AVAILABLE_ENUMERATOR_IN_2_32
GLIB_AVAILABLE_ENUMERATOR_IN_2_34
GLIB_AVAILABLE_ENUMERATOR_IN_2_36
GLIB_AVAILABLE_ENUMERATOR_IN_2_38
GLIB_AVAILABLE_ENUMERATOR_IN_2_40
GLIB_AVAILABLE_ENUMERATOR_IN_2_42
GLIB_AVAILABLE_ENUMERATOR_IN_2_44
GLIB_AVAILABLE_ENUMERATOR_IN_2_46
GLIB_AVAILABLE_ENUMERATOR_IN_2_48
GLIB_AVAILABLE_ENUMERATOR_IN_2_50
GLIB_AVAILABLE_ENUMERATOR_IN_2_52
GLIB_AVAILABLE_ENUMERATOR_IN_2_54
GLIB_AVAILABLE_ENUMERATOR_IN_2_56
GLIB_AVAILABLE_ENUMERATOR_IN_2_58
GLIB_AVAILABLE_ENUMERATOR_IN_2_60
GLIB_AVAILABLE_ENUMERATOR_IN_2_62
GLIB_AVAILABLE_ENUMERATOR_IN_2_64
GLIB_AVAILABLE_ENUMERATOR_IN_2_66
GLIB_AVAILABLE_ENUMERATOR_IN_2_68
GLIB_AVAILABLE_ENUMERATOR_IN_2_70
GLIB_AVAILABLE_ENUMERATOR_IN_2_72
GLIB_AVAILABLE_ENUMERATOR_IN_2_74
GLIB_AVAILABLE_IN_ALL
GLIB_AVAILABLE_IN_2_26
GLIB_AVAILABLE_IN_2_28
GLIB_AVAILABLE_IN_2_30
GLIB_AVAILABLE_IN_2_32
GLIB_AVAILABLE_IN_2_34
GLIB_AVAILABLE_IN_2_36
GLIB_AVAILABLE_IN_2_38
GLIB_AVAILABLE_IN_2_40
GLIB_AVAILABLE_IN_2_42
GLIB_AVAILABLE_IN_2_44
GLIB_AVAILABLE_IN_2_46
GLIB_AVAILABLE_IN_2_48
GLIB_AVAILABLE_IN_2_50
GLIB_AVAILABLE_IN_2_52
GLIB_AVAILABLE_IN_2_54
GLIB_AVAILABLE_IN_2_56
GLIB_AVAILABLE_IN_2_58
GLIB_AVAILABLE_IN_2_60
GLIB_AVAILABLE_IN_2_62
GLIB_AVAILABLE_IN_2_64
GLIB_AVAILABLE_IN_2_66
GLIB_AVAILABLE_IN_2_68
GLIB_AVAILABLE_IN_2_70
GLIB_AVAILABLE_IN_2_72
GLIB_AVAILABLE_IN_2_74
GLIB_AVAILABLE_MACRO_IN_2_26
GLIB_AVAILABLE_MACRO_IN_2_28
GLIB_AVAILABLE_MACRO_IN_2_30
GLIB_AVAILABLE_MACRO_IN_2_32
GLIB_AVAILABLE_MACRO_IN_2_34
GLIB_AVAILABLE_MACRO_IN_2_36
GLIB_AVAILABLE_MACRO_IN_2_38
GLIB_AVAILABLE_MACRO_IN_2_40
GLIB_AVAILABLE_MACRO_IN_2_42
GLIB_AVAILABLE_MACRO_IN_2_44
GLIB_AVAILABLE_MACRO_IN_2_46
GLIB_AVAILABLE_MACRO_IN_2_48
GLIB_AVAILABLE_MACRO_IN_2_50
GLIB_AVAILABLE_MACRO_IN_2_52
GLIB_AVAILABLE_MACRO_IN_2_54
GLIB_AVAILABLE_MACRO_IN_2_56
GLIB_AVAILABLE_MACRO_IN_2_58
GLIB_AVAILABLE_MACRO_IN_2_60
GLIB_AVAILABLE_MACRO_IN_2_62
GLIB_AVAILABLE_MACRO_IN_2_64
GLIB_AVAILABLE_MACRO_IN_2_66
GLIB_AVAILABLE_MACRO_IN_2_68
GLIB_AVAILABLE_MACRO_IN_2_70
GLIB_AVAILABLE_MACRO_IN_2_72
GLIB_AVAILABLE_MACRO_IN_2_74
GLIB_AVAILABLE_STATIC_INLINE_IN_2_44
GLIB_AVAILABLE_STATIC_INLINE_IN_2_60
GLIB_AVAILABLE_STATIC_INLINE_IN_2_62
GLIB_AVAILABLE_STATIC_INLINE_IN_2_64
GLIB_AVAILABLE_STATIC_INLINE_IN_2_66
GLIB_AVAILABLE_STATIC_INLINE_IN_2_68
GLIB_AVAILABLE_STATIC_INLINE_IN_2_70
GLIB_AVAILABLE_STATIC_INLINE_IN_2_72
GLIB_AVAILABLE_STATIC_INLINE_IN_2_74
GLIB_AVAILABLE_TYPE_IN_2_26
GLIB_AVAILABLE_TYPE_IN_2_28
GLIB_AVAILABLE_TYPE_IN_2_30
GLIB_AVAILABLE_TYPE_IN_2_32
GLIB_AVAILABLE_TYPE_IN_2_34
GLIB_AVAILABLE_TYPE_IN_2_36
GLIB_AVAILABLE_TYPE_IN_2_38
GLIB_AVAILABLE_TYPE_IN_2_40
GLIB_AVAILABLE_TYPE_IN_2_42
GLIB_AVAILABLE_TYPE_IN_2_44
GLIB_AVAILABLE_TYPE_IN_2_46
GLIB_AVAILABLE_TYPE_IN_2_48
GLIB_AVAILABLE_TYPE_IN_2_50
GLIB_AVAILABLE_TYPE_IN_2_52
GLIB_AVAILABLE_TYPE_IN_2_54
GLIB_AVAILABLE_TYPE_IN_2_56
GLIB_AVAILABLE_TYPE_IN_2_58
GLIB_AVAILABLE_TYPE_IN_2_60
GLIB_AVAILABLE_TYPE_IN_2_62
GLIB_AVAILABLE_TYPE_IN_2_64
GLIB_AVAILABLE_TYPE_IN_2_66
GLIB_AVAILABLE_TYPE_IN_2_68
GLIB_AVAILABLE_TYPE_IN_2_70
GLIB_AVAILABLE_TYPE_IN_2_72
GLIB_AVAILABLE_TYPE_IN_2_74
GLIB_DEPRECATED_ENUMERATOR
GLIB_DEPRECATED_ENUMERATOR_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_26
GLIB_DEPRECATED_ENUMERATOR_IN_2_26_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_28
GLIB_DEPRECATED_ENUMERATOR_IN_2_28_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_30
GLIB_DEPRECATED_ENUMERATOR_IN_2_30_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_32
GLIB_DEPRECATED_ENUMERATOR_IN_2_32_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_34
GLIB_DEPRECATED_ENUMERATOR_IN_2_34_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_36
GLIB_DEPRECATED_ENUMERATOR_IN_2_36_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_38
GLIB_DEPRECATED_ENUMERATOR_IN_2_38_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_40
GLIB_DEPRECATED_ENUMERATOR_IN_2_40_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_42
GLIB_DEPRECATED_ENUMERATOR_IN_2_42_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_44
GLIB_DEPRECATED_ENUMERATOR_IN_2_44_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_46
GLIB_DEPRECATED_ENUMERATOR_IN_2_46_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_48
GLIB_DEPRECATED_ENUMERATOR_IN_2_48_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_50
GLIB_DEPRECATED_ENUMERATOR_IN_2_50_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_52
GLIB_DEPRECATED_ENUMERATOR_IN_2_52_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_54
GLIB_DEPRECATED_ENUMERATOR_IN_2_54_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_56
GLIB_DEPRECATED_ENUMERATOR_IN_2_56_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_58
GLIB_DEPRECATED_ENUMERATOR_IN_2_58_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_60
GLIB_DEPRECATED_ENUMERATOR_IN_2_60_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_62
GLIB_DEPRECATED_ENUMERATOR_IN_2_62_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_64
GLIB_DEPRECATED_ENUMERATOR_IN_2_64_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_66
GLIB_DEPRECATED_ENUMERATOR_IN_2_66_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_68
GLIB_DEPRECATED_ENUMERATOR_IN_2_68_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_70
GLIB_DEPRECATED_ENUMERATOR_IN_2_70_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_72
GLIB_DEPRECATED_ENUMERATOR_IN_2_72_FOR
GLIB_DEPRECATED_ENUMERATOR_IN_2_74
GLIB_DEPRECATED_ENUMERATOR_IN_2_74_FOR
GLIB_DEPRECATED_IN_2_26
GLIB_DEPRECATED_IN_2_26_FOR
GLIB_DEPRECATED_IN_2_28
GLIB_DEPRECATED_IN_2_28_FOR
GLIB_DEPRECATED_IN_2_30
GLIB_DEPRECATED_IN_2_30_FOR
GLIB_DEPRECATED_IN_2_32
GLIB_DEPRECATED_IN_2_32_FOR
GLIB_DEPRECATED_IN_2_34
GLIB_DEPRECATED_IN_2_34_FOR
GLIB_DEPRECATED_IN_2_36
GLIB_DEPRECATED_IN_2_36_FOR
GLIB_DEPRECATED_IN_2_38
GLIB_DEPRECATED_IN_2_38_FOR
GLIB_DEPRECATED_IN_2_40
GLIB_DEPRECATED_IN_2_40_FOR
GLIB_DEPRECATED_IN_2_42
GLIB_DEPRECATED_IN_2_42_FOR
GLIB_DEPRECATED_IN_2_44
GLIB_DEPRECATED_IN_2_44_FOR
GLIB_DEPRECATED_IN_2_46
GLIB_DEPRECATED_IN_2_46_FOR
GLIB_DEPRECATED_IN_2_48
GLIB_DEPRECATED_IN_2_48_FOR
GLIB_DEPRECATED_IN_2_50
GLIB_DEPRECATED_IN_2_50_FOR
GLIB_DEPRECATED_IN_2_52
GLIB_DEPRECATED_IN_2_52_FOR
GLIB_DEPRECATED_IN_2_54
GLIB_DEPRECATED_IN_2_54_FOR
GLIB_DEPRECATED_IN_2_56
GLIB_DEPRECATED_IN_2_56_FOR
GLIB_DEPRECATED_IN_2_58
GLIB_DEPRECATED_IN_2_58_FOR
GLIB_DEPRECATED_IN_2_60
GLIB_DEPRECATED_IN_2_60_FOR
GLIB_DEPRECATED_IN_2_62
GLIB_DEPRECATED_IN_2_62_FOR
GLIB_DEPRECATED_IN_2_64
GLIB_DEPRECATED_IN_2_64_FOR
GLIB_DEPRECATED_IN_2_66
GLIB_DEPRECATED_IN_2_66_FOR
GLIB_DEPRECATED_IN_2_68
GLIB_DEPRECATED_IN_2_68_FOR
GLIB_DEPRECATED_IN_2_70
GLIB_DEPRECATED_IN_2_70_FOR
GLIB_DEPRECATED_IN_2_72
GLIB_DEPRECATED_IN_2_72_FOR
GLIB_DEPRECATED_IN_2_74
GLIB_DEPRECATED_IN_2_74_FOR
GLIB_DEPRECATED_MACRO
GLIB_DEPRECATED_MACRO_FOR
GLIB_DEPRECATED_MACRO_IN_2_26
GLIB_DEPRECATED_MACRO_IN_2_26_FOR
GLIB_DEPRECATED_MACRO_IN_2_28
GLIB_DEPRECATED_MACRO_IN_2_28_FOR
GLIB_DEPRECATED_MACRO_IN_2_30
GLIB_DEPRECATED_MACRO_IN_2_30_FOR
GLIB_DEPRECATED_MACRO_IN_2_32
GLIB_DEPRECATED_MACRO_IN_2_32_FOR
GLIB_DEPRECATED_MACRO_IN_2_34
GLIB_DEPRECATED_MACRO_IN_2_34_FOR
GLIB_DEPRECATED_MACRO_IN_2_36
GLIB_DEPRECATED_MACRO_IN_2_36_FOR
GLIB_DEPRECATED_MACRO_IN_2_38
GLIB_DEPRECATED_MACRO_IN_2_38_FOR
GLIB_DEPRECATED_MACRO_IN_2_40
GLIB_DEPRECATED_MACRO_IN_2_40_FOR
GLIB_DEPRECATED_MACRO_IN_2_42
GLIB_DEPRECATED_MACRO_IN_2_42_FOR
GLIB_DEPRECATED_MACRO_IN_2_44
GLIB_DEPRECATED_MACRO_IN_2_44_FOR
GLIB_DEPRECATED_MACRO_IN_2_46
GLIB_DEPRECATED_MACRO_IN_2_46_FOR
GLIB_DEPRECATED_MACRO_IN_2_48
GLIB_DEPRECATED_MACRO_IN_2_48_FOR
GLIB_DEPRECATED_MACRO_IN_2_50
GLIB_DEPRECATED_MACRO_IN_2_50_FOR
GLIB_DEPRECATED_MACRO_IN_2_52
GLIB_DEPRECATED_MACRO_IN_2_52_FOR
GLIB_DEPRECATED_MACRO_IN_2_54
GLIB_DEPRECATED_MACRO_IN_2_54_FOR
GLIB_DEPRECATED_MACRO_IN_2_56
GLIB_DEPRECATED_MACRO_IN_2_56_FOR
GLIB_DEPRECATED_MACRO_IN_2_58
GLIB_DEPRECATED_MACRO_IN_2_58_FOR
GLIB_DEPRECATED_MACRO_IN_2_60
GLIB_DEPRECATED_MACRO_IN_2_60_FOR
GLIB_DEPRECATED_MACRO_IN_2_62
GLIB_DEPRECATED_MACRO_IN_2_62_FOR
GLIB_DEPRECATED_MACRO_IN_2_64
GLIB_DEPRECATED_MACRO_IN_2_64_FOR
GLIB_DEPRECATED_MACRO_IN_2_66
GLIB_DEPRECATED_MACRO_IN_2_66_FOR
GLIB_DEPRECATED_MACRO_IN_2_68
GLIB_DEPRECATED_MACRO_IN_2_68_FOR
GLIB_DEPRECATED_MACRO_IN_2_70
GLIB_DEPRECATED_MACRO_IN_2_70_FOR
GLIB_DEPRECATED_MACRO_IN_2_72
GLIB_DEPRECATED_MACRO_IN_2_72_FOR
GLIB_DEPRECATED_MACRO_IN_2_74
GLIB_DEPRECATED_MACRO_IN_2_74_FOR
GLIB_DEPRECATED_TYPE
GLIB_DEPRECATED_TYPE_FOR
GLIB_DEPRECATED_TYPE_IN_2_26
GLIB_DEPRECATED_TYPE_IN_2_26_FOR
GLIB_DEPRECATED_TYPE_IN_2_28
GLIB_DEPRECATED_TYPE_IN_2_28_FOR
GLIB_DEPRECATED_TYPE_IN_2_30
GLIB_DEPRECATED_TYPE_IN_2_30_FOR
GLIB_DEPRECATED_TYPE_IN_2_32
GLIB_DEPRECATED_TYPE_IN_2_32_FOR
GLIB_DEPRECATED_TYPE_IN_2_34
GLIB_DEPRECATED_TYPE_IN_2_34_FOR
GLIB_DEPRECATED_TYPE_IN_2_36
GLIB_DEPRECATED_TYPE_IN_2_36_FOR
GLIB_DEPRECATED_TYPE_IN_2_38
GLIB_DEPRECATED_TYPE_IN_2_38_FOR
GLIB_DEPRECATED_TYPE_IN_2_40
GLIB_DEPRECATED_TYPE_IN_2_40_FOR
GLIB_DEPRECATED_TYPE_IN_2_42
GLIB_DEPRECATED_TYPE_IN_2_42_FOR
GLIB_DEPRECATED_TYPE_IN_2_44
GLIB_DEPRECATED_TYPE_IN_2_44_FOR
GLIB_DEPRECATED_TYPE_IN_2_46
GLIB_DEPRECATED_TYPE_IN_2_46_FOR
GLIB_DEPRECATED_TYPE_IN_2_48
GLIB_DEPRECATED_TYPE_IN_2_48_FOR
GLIB_DEPRECATED_TYPE_IN_2_50
GLIB_DEPRECATED_TYPE_IN_2_50_FOR
GLIB_DEPRECATED_TYPE_IN_2_52
GLIB_DEPRECATED_TYPE_IN_2_52_FOR
GLIB_DEPRECATED_TYPE_IN_2_54
GLIB_DEPRECATED_TYPE_IN_2_54_FOR
GLIB_DEPRECATED_TYPE_IN_2_56
GLIB_DEPRECATED_TYPE_IN_2_56_FOR
GLIB_DEPRECATED_TYPE_IN_2_58
GLIB_DEPRECATED_TYPE_IN_2_58_FOR
GLIB_DEPRECATED_TYPE_IN_2_60
GLIB_DEPRECATED_TYPE_IN_2_60_FOR
GLIB_DEPRECATED_TYPE_IN_2_62
GLIB_DEPRECATED_TYPE_IN_2_62_FOR
GLIB_DEPRECATED_TYPE_IN_2_64
GLIB_DEPRECATED_TYPE_IN_2_64_FOR
GLIB_DEPRECATED_TYPE_IN_2_66
GLIB_DEPRECATED_TYPE_IN_2_66_FOR
GLIB_DEPRECATED_TYPE_IN_2_68
GLIB_DEPRECATED_TYPE_IN_2_68_FOR
GLIB_DEPRECATED_TYPE_IN_2_70
GLIB_DEPRECATED_TYPE_IN_2_70_FOR
GLIB_DEPRECATED_TYPE_IN_2_72
GLIB_DEPRECATED_TYPE_IN_2_72_FOR
GLIB_DEPRECATED_TYPE_IN_2_74
GLIB_DEPRECATED_TYPE_IN_2_74_FOR
GLIB_VERSION_CUR_STABLE
GLIB_VERSION_PREV_STABLE
</SECTION>

View File

@ -38,6 +38,8 @@ if get_option('gtk_doc')
'gutilsprivate.h',
'gvalgrind.h',
'dirent.h',
'glib-visibility.h',
'gmodule-visibility.h',
]
docpath = join_paths(glib_datadir, 'gtk-doc', 'html')
@ -49,13 +51,20 @@ if get_option('gtk_doc')
configuration: version_conf
)
configure_file(
input: 'glib-sections.txt.in',
output: 'glib-sections.txt',
command: [gen_visibility_macros, meson.project_version(), 'doc-sections', '@INPUT@', '@OUTPUT@'],
)
gnome.gtkdoc('glib',
main_xml : 'glib-docs.xml',
namespace : 'g',
mode : 'none',
src_dir : [ 'glib', 'gmodule' ],
dependencies : libglib_dep,
scan_args : gtkdoc_common_scan_args + [
scan_args : [
'--ignore-decorators=' + ignore_decorators + '|' + ignore_decorators.replace('GLIB', 'GMODULE'),
'--ignore-headers=' + ' '.join(ignore_headers),
],
content_files : [

View File

@ -185,9 +185,6 @@ G_TYPE_RESERVED_GLIB_LAST
G_TYPE_RESERVED_BSE_FIRST
G_TYPE_RESERVED_BSE_LAST
G_TYPE_RESERVED_USER_FIRST
<SUBSECTION Private>
GOBJECT_VAR
</SECTION>
<SECTION>

View File

@ -8,6 +8,7 @@ if get_option('gtk_doc')
'gobject_trace.h',
'gtype-private.h',
'glib-enumtypes.h',
'gobject-visibility.h',
]
docpath = join_paths(glib_datadir, 'gtk-doc', 'html')
@ -28,7 +29,8 @@ if get_option('gtk_doc')
dependencies : [libgobject_dep, libglib_dep],
include_directories : [gtkdocincl],
src_dir : 'gobject',
scan_args : gtkdoc_common_scan_args + [
scan_args : [
'--ignore-decorators=' + '|'.join(ignore_decorators.replace('GLIB', 'GOBJECT')),
'--rebuild-types',
'--ignore-headers=' + ' '.join(ignore_headers),
],

View File

@ -37,9 +37,7 @@ foreach i : range(first_version, last_version + 2, 2)
]
endforeach
gtkdoc_common_scan_args = [
'--ignore-decorators=' + '|'.join(ignore_decorators),
]
ignore_decorators = '|'.join(ignore_decorators)
if get_option('gtk_doc')
# Check we have the minimum gtk-doc version required. Older versions won't

View File

@ -28,6 +28,7 @@
#endif
#include <glib-object.h>
#include <gio/gio-visibility.h>
G_BEGIN_DECLS

View File

@ -24,6 +24,7 @@
#define __GIO_ENUM_TYPES_H__
#include <glib-object.h>
#include <gio/gio-visibility.h>
G_BEGIN_DECLS
/*** END file-header ***/

View File

@ -22,6 +22,7 @@
#define __G_NETWORKING_H__
#include <glib.h>
#include <gio/gio-visibility.h>
#ifdef G_OS_WIN32
#include <winsock2.h>

View File

@ -22,6 +22,7 @@
#define __G_SETTINGS_SCHEMA_H__
#include <glib-object.h>
#include <gio/gio-visibility.h>
G_BEGIN_DECLS

View File

@ -6,8 +6,6 @@ gio_c_args = [
'-DLOCALSTATEDIR="@0@"'.format(glib_localstatedir),
]
gio_c_args += glib_hidden_visibility_args
# FIXME: Install empty glib_giomodulesdir
gnetworking_h_conf = configuration_data()
@ -742,6 +740,12 @@ gio_headers = files(
'gliststore.h',
)
gvisibility_h = configure_file(
output: 'gio-visibility.h',
command: [gen_visibility_macros, meson.project_version(), 'visibility-macros', 'GIO', '@OUTPUT@'],
)
gio_headers += gvisibility_h
gio_headers += application_headers
gio_headers += settings_headers
gio_headers += gdbus_headers
@ -835,6 +839,7 @@ libgio = library('gio-2.0',
gioenumtypes_dep, gvdb_dep],
c_args : gio_c_args,
objc_args : gio_c_args,
gnu_symbol_visibility : 'hidden',
# intl.lib is not compatible with SAFESEH
link_args : [noseh_link_args, glib_link_flags],
)

View File

@ -14,4 +14,6 @@ xdgmime_lib = static_library('xdgmime',
include_directories : [configinc],
pic : true,
c_args : [ '-DHAVE_CONFIG_H',
'-DXDG_PREFIX=_gio_xdg' ] + glib_hidden_visibility_args)
'-DXDG_PREFIX=_gio_xdg' ],
gnu_symbol_visibility : 'hidden',
)

View File

@ -12,17 +12,20 @@
#include <float.h>
#mesondefine GLIB_HAVE_ALLOCA_H
#mesondefine GLIB_STATIC_COMPILATION
#mesondefine GOBJECT_STATIC_COMPILATION
#mesondefine GIO_STATIC_COMPILATION
#mesondefine GMODULE_STATIC_COMPILATION
#mesondefine G_INTL_STATIC_COMPILATION
#mesondefine FFI_STATIC_BUILD
#include <glib/glib-visibility.h>
/* Specifies that GLib's g_print*() functions wrap the
* system printf functions. This is useful to know, for example,
* when using glibc's register_printf_function().
*/
#mesondefine GLIB_USING_SYSTEM_PRINTF
#mesondefine GLIB_STATIC_COMPILATION
#mesondefine GOBJECT_STATIC_COMPILATION
#mesondefine G_INTL_STATIC_COMPILATION
#mesondefine FFI_STATIC_BUILD
G_BEGIN_DECLS
#define G_MINFLOAT FLT_MIN

View File

@ -1227,28 +1227,12 @@
#define G_UNAVAILABLE(maj,min) G_DEPRECATED
#endif
#ifndef _GLIB_EXTERN
#define _GLIB_EXTERN extern
#endif
/* 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, use G_DEPRECATED
* or define your own wrappers around it.
*/
#ifdef GLIB_DISABLE_DEPRECATION_WARNINGS
#define GLIB_DEPRECATED _GLIB_EXTERN
#define GLIB_DEPRECATED_FOR(f) _GLIB_EXTERN
#define GLIB_UNAVAILABLE(maj,min) _GLIB_EXTERN
#define GLIB_UNAVAILABLE_STATIC_INLINE(maj,min)
#else
#define GLIB_DEPRECATED G_DEPRECATED _GLIB_EXTERN
#define GLIB_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _GLIB_EXTERN
#define GLIB_UNAVAILABLE(maj,min) G_UNAVAILABLE(maj,min) _GLIB_EXTERN
#define GLIB_UNAVAILABLE_STATIC_INLINE(maj,min) G_UNAVAILABLE(maj,min)
#endif
#if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
(G_GNUC_CHECK_VERSION(4, 6) || \
__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4))

View File

@ -366,6 +366,9 @@ gnulib_lib = static_library('gnulib', gnulib_sources,
dependencies : [libm],
include_directories : [configinc, glibinc, include_directories ('.')],
pic : true,
c_args : ['-DGCC_LINT=1', '-DLIBDIR="@0@"'.format(glib_libdir), '-DGLIB_COMPILATION', '-DG_LOG_DOMAIN="GLib"' ] + glib_hidden_visibility_args + extra_gnulib_args)
c_args : ['-DGCC_LINT=1', '-DLIBDIR="@0@"'.format(glib_libdir), '-DG_LOG_DOMAIN="GLib"',
glib_c_args_internal, extra_gnulib_args],
gnu_symbol_visibility : 'hidden',
)
gnulib_libm_dependency = [libm]

View File

@ -584,27 +584,4 @@ typedef gint gatomicrefcount; /* should be accessed only using atomics */
G_END_DECLS
/* We prefix variable declarations so they can
* properly get exported in Windows DLLs.
*/
#ifndef GLIB_VAR
# ifdef G_PLATFORM_WIN32
# ifdef GLIB_STATIC_COMPILATION
# define GLIB_VAR extern
# else /* !GLIB_STATIC_COMPILATION */
# ifdef GLIB_COMPILATION
# ifdef DLL_EXPORT
# define GLIB_VAR extern __declspec(dllexport)
# else /* !DLL_EXPORT */
# define GLIB_VAR extern
# endif /* !DLL_EXPORT */
# else /* !GLIB_COMPILATION */
# define GLIB_VAR extern __declspec(dllimport)
# endif /* !GLIB_COMPILATION */
# endif /* !GLIB_STATIC_COMPILATION */
# else /* !G_PLATFORM_WIN32 */
# define GLIB_VAR _GLIB_EXTERN
# endif /* !G_PLATFORM_WIN32 */
#endif /* GLIB_VAR */
#endif /* __G_TYPES_H__ */

File diff suppressed because it is too large Load Diff

140
glib/gversionmacros.h.in Normal file
View File

@ -0,0 +1,140 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __G_VERSION_MACROS_H__
#define __G_VERSION_MACROS_H__
#if !defined(__GLIB_H_INSIDE__) && !defined(GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
/* Version boundaries checks */
#define G_ENCODE_VERSION(major, minor) ((major) << 16 | (minor) << 8)
@GLIB_VERSIONS@
/**
* GLIB_VERSION_CUR_STABLE:
*
* A macro that evaluates to the current stable version of GLib, in a format
* that can be used by the C pre-processor.
*
* During an unstable development cycle, this evaluates to the next stable
* (unreleased) version which will be the result of the development cycle.
*
* Since: 2.32
*/
#if (GLIB_MINOR_VERSION % 2)
#define GLIB_VERSION_CUR_STABLE (G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION + 1))
#else
#define GLIB_VERSION_CUR_STABLE (G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION))
#endif
/**
* GLIB_VERSION_PREV_STABLE:
*
* A macro that evaluates to the previous stable version of GLib, in a format
* that can be used by the C pre-processor.
*
* During an unstable development cycle, this evaluates to the most recent
* released stable release, which preceded this development cycle.
*
* Since: 2.32
*/
#if (GLIB_MINOR_VERSION % 2)
#define GLIB_VERSION_PREV_STABLE (G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION - 1))
#else
#define GLIB_VERSION_PREV_STABLE (G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION - 2))
#endif
/**
* GLIB_VERSION_MIN_REQUIRED:
*
* A macro that should be defined by the user prior to including
* the glib.h header.
* The definition should be one of the predefined GLib version
* macros: %GLIB_VERSION_2_26, %GLIB_VERSION_2_28,...
*
* This macro defines the earliest version of GLib that the package is
* required to be able to compile against.
*
* If the compiler is configured to warn about the use of deprecated
* functions, then using functions that were deprecated in version
* %GLIB_VERSION_MIN_REQUIRED or earlier will cause warnings (but
* using functions deprecated in later releases will not).
*
* Since: 2.32
*/
/* If the package sets GLIB_VERSION_MIN_REQUIRED to some future
* GLIB_VERSION_X_Y value that we don't know about, it will compare as
* 0 in preprocessor tests.
*/
#ifndef GLIB_VERSION_MIN_REQUIRED
#define GLIB_VERSION_MIN_REQUIRED (GLIB_VERSION_CUR_STABLE)
#elif GLIB_VERSION_MIN_REQUIRED == 0
#undef GLIB_VERSION_MIN_REQUIRED
#define GLIB_VERSION_MIN_REQUIRED (GLIB_VERSION_CUR_STABLE + 2)
#endif
/**
* GLIB_VERSION_MAX_ALLOWED:
*
* A macro that should be defined by the user prior to including
* the glib.h header.
* The definition should be one of the predefined GLib version
* macros: %GLIB_VERSION_2_26, %GLIB_VERSION_2_28,...
*
* This macro defines the latest version of the GLib API that the
* package is allowed to make use of.
*
* If the compiler is configured to warn about the use of deprecated
* functions, then using functions added after version
* %GLIB_VERSION_MAX_ALLOWED will cause warnings.
*
* Unless you are using GLIB_CHECK_VERSION() or the like to compile
* different code depending on the GLib version, then this should be
* set to the same value as %GLIB_VERSION_MIN_REQUIRED.
*
* Since: 2.32
*/
#if !defined(GLIB_VERSION_MAX_ALLOWED) || (GLIB_VERSION_MAX_ALLOWED == 0)
#undef GLIB_VERSION_MAX_ALLOWED
#define GLIB_VERSION_MAX_ALLOWED (GLIB_VERSION_CUR_STABLE)
#endif
/* sanity checks */
#if GLIB_VERSION_MIN_REQUIRED > GLIB_VERSION_CUR_STABLE
#error "GLIB_VERSION_MIN_REQUIRED must be <= GLIB_VERSION_CUR_STABLE"
#endif
#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_MIN_REQUIRED
#error "GLIB_VERSION_MAX_ALLOWED must be >= GLIB_VERSION_MIN_REQUIRED"
#endif
#if GLIB_VERSION_MIN_REQUIRED < GLIB_VERSION_2_26
#error "GLIB_VERSION_MIN_REQUIRED must be >= GLIB_VERSION_2_26"
#endif
#endif /* __G_VERSION_MACROS_H__ */

View File

@ -1,4 +1,6 @@
charset_lib = static_library('charset', 'localcharset.c',
include_directories : configinc,
pic : true,
c_args : [ '-DGLIB_CHARSETALIAS_DIR="@0@"'.format(glib_charsetaliasdir) ] + glib_hidden_visibility_args)
c_args : [ '-DGLIB_CHARSETALIAS_DIR="@0@"'.format(glib_charsetaliasdir) ],
gnu_symbol_visibility : 'hidden',
)

View File

@ -3,6 +3,21 @@ glibconfig_h = configure_file(input : 'glibconfig.h.in', output : 'glibconfig.h'
install_tag : 'devel',
configuration : glibconfig_conf)
gversionmacros_h = configure_file(
input: 'gversionmacros.h.in',
output: 'gversionmacros.h',
command: [gen_visibility_macros, meson.project_version(), 'versions-macros', '@INPUT@', '@OUTPUT@'],
)
gvisibility_h = configure_file(
output: 'glib-visibility.h',
command: [gen_visibility_macros, meson.project_version(), 'visibility-macros', 'GLIB', '@OUTPUT@'],
)
glib_c_args_internal = [
'-DGLIB_COMPILATION',
]
subdir('libcharset')
# libsysprof-capture support
@ -212,10 +227,12 @@ glib_sub_headers = files(
'gvarianttype.h',
'gvariant.h',
'gversion.h',
'gversionmacros.h',
'gwin32.h',
'gprintf.h',
)
glib_sub_headers += [gversionmacros_h, gvisibility_h]
install_headers(glib_sub_headers, subdir : 'glib-2.0/glib')
deprecated_sources = files(
@ -368,7 +385,7 @@ if use_pcre2_static_flag
pcre2_static_args = ['-DPCRE2_STATIC']
endif
glib_c_args = ['-DG_LOG_DOMAIN="GLib"', '-DGLIB_COMPILATION'] + pcre2_static_args + glib_hidden_visibility_args
glib_c_args = ['-DG_LOG_DOMAIN="GLib"'] + glib_c_args_internal + pcre2_static_args
libglib = library('glib-2.0',
glib_dtrace_obj, glib_dtrace_hdr,
sources : [deprecated_sources, glib_sources],
@ -383,6 +400,7 @@ libglib = library('glib-2.0',
dependencies : [pcre2, thread_dep, librt] + libintl_deps + libiconv + platform_deps + [gnulib_libm_dependency, libm] + [libsysprof_capture_dep],
c_args : glib_c_args,
objc_args : glib_c_args,
gnu_symbol_visibility : 'hidden',
)
libglib_dep = declare_dependency(

View File

@ -28,6 +28,7 @@
#define __GMODULE_H__
#include <glib.h>
#include <gmodule/gmodule-visibility.h>
G_BEGIN_DECLS

View File

@ -66,6 +66,12 @@ gmodule_c = files('gmodule.c')
install_headers([gmodule_h], subdir : 'glib-2.0')
gvisibility_h = configure_file(
output: 'gmodule-visibility.h',
command: [gen_visibility_macros, meson.project_version(), 'visibility-macros', 'GMODULE', '@OUTPUT@'],
)
install_headers(gvisibility_h, subdir : 'glib-2.0/gmodule')
gmodule_sources = [gmodule_c]
if host_system == 'windows'
gmodule_win_rc = configure_file(
@ -85,7 +91,8 @@ libgmodule = library('gmodule-2.0',
install : true,
include_directories : [configinc, gmoduleinc],
dependencies : [libdl_dep, libglib_dep],
c_args : ['-DG_LOG_DOMAIN="GModule"'] + glib_hidden_visibility_args,
c_args : ['-DG_LOG_DOMAIN="GModule"', '-DGMODULE_COMPILATION'],
gnu_symbol_visibility : 'hidden',
link_args : [glib_link_flags],
)

View File

@ -1144,30 +1144,6 @@ GParamSpec* g_param_spec_variant (const gchar *name,
GVariant *default_value,
GParamFlags flags);
/* --- internal --- */
/* We prefix variable declarations so they can
* properly get exported in windows dlls.
*/
#ifndef GOBJECT_VAR
# ifdef G_PLATFORM_WIN32
# ifdef GOBJECT_STATIC_COMPILATION
# define GOBJECT_VAR extern
# else /* !GOBJECT_STATIC_COMPILATION */
# ifdef GOBJECT_COMPILATION
# ifdef DLL_EXPORT
# define GOBJECT_VAR extern __declspec(dllexport)
# else /* !DLL_EXPORT */
# define GOBJECT_VAR extern
# endif /* !DLL_EXPORT */
# else /* !GOBJECT_COMPILATION */
# define GOBJECT_VAR extern __declspec(dllimport)
# endif /* !GOBJECT_COMPILATION */
# endif /* !GOBJECT_STATIC_COMPILATION */
# else /* !G_PLATFORM_WIN32 */
# define GOBJECT_VAR _GLIB_EXTERN
# endif /* !G_PLATFORM_WIN32 */
#endif /* GOBJECT_VAR */
GOBJECT_VAR GType *g_param_spec_types;
G_END_DECLS

View File

@ -23,7 +23,8 @@
#error "Only <glib-object.h> can be included directly."
#endif
#include <glib.h>
#include <glib.h>
#include <gobject/gobject-visibility.h>
G_BEGIN_DECLS

View File

@ -22,6 +22,14 @@ gobject_install_headers = files(
'gvaluetypes.h',
'gobjectnotifyqueue.c', # sic
)
gvisibility_h = configure_file(
output: 'gobject-visibility.h',
command: [gen_visibility_macros, meson.project_version(), 'visibility-macros', 'GOBJECT', '@OUTPUT@'],
)
gobject_install_headers += gvisibility_h
install_headers(gobject_install_headers, subdir : 'glib-2.0/gobject')
gobject_sources = files(
@ -135,7 +143,8 @@ libgobject = library('gobject-2.0',
install : true,
include_directories : [configinc],
dependencies : [libffi_dep, libglib_dep],
c_args : ['-DG_LOG_DOMAIN="GLib-GObject"', '-DGOBJECT_COMPILATION'] + glib_hidden_visibility_args,
c_args : ['-DG_LOG_DOMAIN="GLib-GObject"', '-DGOBJECT_COMPILATION'],
gnu_symbol_visibility : 'hidden',
link_args : glib_link_flags,
)

View File

@ -19,7 +19,8 @@ libgthread = library('gthread-2.0',
darwin_versions : darwin_versions,
install : true,
dependencies : [libglib_dep],
c_args : ['-DG_LOG_DOMAIN="GThread"' ] + glib_hidden_visibility_args,
c_args : ['-DG_LOG_DOMAIN="GThread"', glib_c_args_internal],
gnu_symbol_visibility : 'hidden',
link_args : glib_link_flags,
)

View File

@ -210,29 +210,15 @@ if host_system == 'windows' and cc.get_id() != 'msvc' and cc.get_id() != 'clang-
glib_conf.set('_FILE_OFFSET_BITS', 64)
endif
# Detect and set symbol visibility
glib_hidden_visibility_args = []
if get_option('default_library') != 'static'
if host_system == 'windows' or host_system == 'cygwin'
if get_option('default_library') != 'shared'
error('On Windows default_library must be "shared" or "static" but not "both"')
endif
glib_conf.set('DLL_EXPORT', true)
if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
glib_conf.set('_GLIB_EXTERN', '__declspec(dllexport) extern')
elif cc.has_argument('-fvisibility=hidden')
glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
glib_hidden_visibility_args = ['-fvisibility=hidden']
endif
elif cc.has_argument('-fvisibility=hidden')
glib_conf.set('_GLIB_EXTERN', '__attribute__((visibility("default"))) extern')
glib_hidden_visibility_args = ['-fvisibility=hidden']
endif
if get_option('default_library') == 'both' and (host_system == 'windows' or host_system == 'cygwin')
error('On Windows default_library must be "shared" or "static" but not "both"')
endif
if get_option('default_library') == 'static'
glibconfig_conf.set('GLIB_STATIC_COMPILATION', '1')
glibconfig_conf.set('GOBJECT_STATIC_COMPILATION', '1')
glibconfig_conf.set('GIO_STATIC_COMPILATION', '1')
glibconfig_conf.set('GMODULE_STATIC_COMPILATION', '1')
glibconfig_conf.set('G_INTL_STATIC_COMPILATION', '1')
glibconfig_conf.set('FFI_STATIC_BUILD', '1')
endif
@ -2349,13 +2335,13 @@ test_timeout_slow = 180
pkg = import('pkgconfig')
windows = import('windows')
subdir('tools')
subdir('glib')
subdir('gobject')
subdir('gthread')
subdir('gmodule')
subdir('gio')
subdir('fuzzing')
subdir('tools')
# xgettext is optional (on Windows for instance)
if find_program('xgettext', required : get_option('nls')).found()

171
tools/gen-visibility-macros.py Executable file
View File

@ -0,0 +1,171 @@
#!/usr/bin/env python3
#
# Copyright © 2022 Collabora Inc.
#
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# Original author: Xavier Claessens <xclaesse@gmail.com>
import argparse
import textwrap
from pathlib import Path
def gen_versions_macros(args, current_minor_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 '@GLIB_VERSIONS@' in line:
for minor in range(2, current_minor_version + 2, 2):
ofile.write(textwrap.dedent(f'''\
/**
* GLIB_VERSION_2_{minor}:
*
* A macro that evaluates to the 2.{minor} version of GLib, in a format
* that can be used by the C pre-processor.
*
* Since: 2.{max(minor, 32)}
*/
#define GLIB_VERSION_2_{minor} (G_ENCODE_VERSION (2, {minor}))
'''))
else:
ofile.write(line)
def gen_doc_sections(args, current_minor_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 '@GLIB_VERSIONS@' in line:
for minor in range(2, current_minor_version + 2, 2):
ofile.write(textwrap.dedent(f'''\
GLIB_VERSION_2_{minor}
'''))
else:
ofile.write(line)
def gen_visibility_macros(args, current_minor_version):
'''
Generates a set of macros for each minor stable version of GLib
- GLIB_VAR
- GLIB_DEPRECATED
- GLIB_DEPRECATED_IN_
- GLIB_DEPRECATED_MACRO_IN_
- GLIB_DEPRECATED_ENUMERATOR_IN_
- GLIB_DEPRECATED_TYPE_IN_
- GLIB_AVAILABLE_IN_ALL
- GLIB_AVAILABLE_IN_
- GLIB_AVAILABLE_STATIC_INLINE_IN_
- GLIB_AVAILABLE_MACRO_IN_
- GLIB_AVAILABLE_ENUMERATOR_IN_
- GLIB_AVAILABLE_TYPE_IN_
- GLIB_UNAVAILABLE(maj,min)
- GLIB_UNAVAILABLE_STATIC_INLINE(maj,min)
The GLIB namespace can be replaced with one of GOBJECT, GIO, GMODULE.
'''
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 GLIB_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(26, current_minor_version + 2, 2):
f.write(textwrap.dedent(f'''
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_{minor}
#define {ns}_DEPRECATED_IN_2_{minor} {ns}_DEPRECATED
#define {ns}_DEPRECATED_IN_2_{minor}_FOR(f) {ns}_DEPRECATED_FOR (f)
#define {ns}_DEPRECATED_MACRO_IN_2_{minor} GLIB_DEPRECATED_MACRO
#define {ns}_DEPRECATED_MACRO_IN_2_{minor}_FOR(f) GLIB_DEPRECATED_MACRO_FOR (f)
#define {ns}_DEPRECATED_ENUMERATOR_IN_2_{minor} GLIB_DEPRECATED_ENUMERATOR
#define {ns}_DEPRECATED_ENUMERATOR_IN_2_{minor}_FOR(f) GLIB_DEPRECATED_ENUMERATOR_FOR (f)
#define {ns}_DEPRECATED_TYPE_IN_2_{minor} GLIB_DEPRECATED_TYPE
#define {ns}_DEPRECATED_TYPE_IN_2_{minor}_FOR(f) GLIB_DEPRECATED_TYPE_FOR (f)
#else
#define {ns}_DEPRECATED_IN_2_{minor} _{ns}_EXTERN
#define {ns}_DEPRECATED_IN_2_{minor}_FOR(f) _{ns}_EXTERN
#define {ns}_DEPRECATED_MACRO_IN_2_{minor}
#define {ns}_DEPRECATED_MACRO_IN_2_{minor}_FOR(f)
#define {ns}_DEPRECATED_ENUMERATOR_IN_2_{minor}
#define {ns}_DEPRECATED_ENUMERATOR_IN_2_{minor}_FOR(f)
#define {ns}_DEPRECATED_TYPE_IN_2_{minor}
#define {ns}_DEPRECATED_TYPE_IN_2_{minor}_FOR(f)
#endif
#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_{minor}
#define {ns}_AVAILABLE_IN_2_{minor} {ns}_UNAVAILABLE (2, {minor})
#define {ns}_AVAILABLE_STATIC_INLINE_IN_2_{minor} GLIB_UNAVAILABLE_STATIC_INLINE (2, {minor})
#define {ns}_AVAILABLE_MACRO_IN_2_{minor} GLIB_UNAVAILABLE_MACRO (2, {minor})
#define {ns}_AVAILABLE_ENUMERATOR_IN_2_{minor} GLIB_UNAVAILABLE_ENUMERATOR (2, {minor})
#define {ns}_AVAILABLE_TYPE_IN_2_{minor} GLIB_UNAVAILABLE_TYPE (2, {minor})
#else
#define {ns}_AVAILABLE_IN_2_{minor} _{ns}_EXTERN
#define {ns}_AVAILABLE_STATIC_INLINE_IN_2_{minor}
#define {ns}_AVAILABLE_MACRO_IN_2_{minor}
#define {ns}_AVAILABLE_ENUMERATOR_IN_2_{minor}
#define {ns}_AVAILABLE_TYPE_IN_2_{minor}
#endif
'''))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('glib_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)
doc_parser = subparsers.add_parser('doc-sections', help='Generate glib-sections.txt')
doc_parser.add_argument('in_path', help='input file', type=Path)
doc_parser.add_argument('out_path', help='output file', type=Path)
doc_parser.set_defaults(func=gen_doc_sections)
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.glib_version.split('.')]
assert version[0] == 2
args.func(args, version[1])
if __name__ == '__main__':
main()

View File

@ -22,3 +22,5 @@ if host_system != 'windows'
install_tag : 'devel',
)
endif
gen_visibility_macros = find_program('gen-visibility-macros.py')