modules: Fix build on Visual Studio

Visual Studio does not allow decorating functions with '__declspec (dllexport)'
if a prototype exists and is not decorated with '__declspec (dllexport)' as
well, so we cannot just decorate g_io_module_[load|unload|query] in the various
module sources with G_MODULE_EXPORT because the prototypes of these functions
have been marked with _GLIB_EXTERN, which equates to 'extern' unless overridden

Fix this by overriding _GLIB_EXTERN with the appropriate visibility flag, as we
have used to define _GDK_EXTERN.  Unfortunately, we can't just use _GDK_EXTERN
G_MODULE_EXPORT as they may have not been defined yet for our use

Do this across the board for all modules, even if they are not buildable on
Visual Studio nor Windows, for consistency's sake.
This commit is contained in:
Chun-wei Fan 2020-06-04 16:27:56 +08:00
parent 5535b26395
commit acd9c12667
8 changed files with 16 additions and 22 deletions

View File

@ -286,15 +286,19 @@ endif
common_cflags = cc.get_supported_arguments(test_cflags) common_cflags = cc.get_supported_arguments(test_cflags)
# Symbol visibility # Symbol visibility
if os_win32
visibility_define = '__declspec(dllexport) extern'
else
visibility_define = '__attribute__((visibility("default"))) extern'
endif
if get_option('default_library') != 'static' if get_option('default_library') != 'static'
cdata.set('_GDK_EXTERN', visibility_define)
if os_win32 if os_win32
cdata.set('DLL_EXPORT', true) cdata.set('DLL_EXPORT', true)
cdata.set('_GDK_EXTERN', '__declspec(dllexport) extern') endif
if cc.get_id() != 'msvc' if cc.get_id() != 'msvc'
common_cflags += ['-fvisibility=hidden']
endif
else
cdata.set('_GDK_EXTERN', '__attribute__((visibility("default"))) extern')
common_cflags += ['-fvisibility=hidden'] common_cflags += ['-fvisibility=hidden']
endif endif
endif endif

View File

@ -97,7 +97,6 @@ G_DEFINE_TYPE_EXTENDED (GtkGstMediaFile, gtk_gst_media_file, GTK_TYPE_MEDIA_FILE
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE, G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
gtk_gst_media_file_paintable_init)) gtk_gst_media_file_paintable_init))
G_MODULE_EXPORT
void void
g_io_module_load (GIOModule *module) g_io_module_load (GIOModule *module)
{ {
@ -109,7 +108,6 @@ g_io_module_load (GIOModule *module)
10); 10);
} }
G_MODULE_EXPORT
G_GNUC_NORETURN G_GNUC_NORETURN
void void
g_io_module_unload (GIOModule *module) g_io_module_unload (GIOModule *module)
@ -117,7 +115,6 @@ g_io_module_unload (GIOModule *module)
g_assert_not_reached (); g_assert_not_reached ();
} }
G_MODULE_EXPORT
char ** char **
g_io_module_query (void) g_io_module_query (void)
{ {

View File

@ -23,7 +23,11 @@ endif
media_subdir = 'gtk-4.0/@0@/media'.format(gtk_binary_version) media_subdir = 'gtk-4.0/@0@/media'.format(gtk_binary_version)
media_install_dir = join_paths(get_option('libdir'), media_subdir) media_install_dir = join_paths(get_option('libdir'), media_subdir)
extra_c_args = ['-DGTK_COMPILATION'] extra_c_args = [
'-DGTK_COMPILATION',
'-D_GLIB_EXTERN=@0@'.format(visibility_define),
]
extra_c_args += common_cflags extra_c_args += common_cflags
if media_backends.contains('ffmpeg') if media_backends.contains('ffmpeg')

View File

@ -103,7 +103,6 @@ void t_goa_account_free (gpointer data);
G_DEFINE_DYNAMIC_TYPE (GtkPrintBackendCloudprint, gtk_print_backend_cloudprint, GTK_TYPE_PRINT_BACKEND) G_DEFINE_DYNAMIC_TYPE (GtkPrintBackendCloudprint, gtk_print_backend_cloudprint, GTK_TYPE_PRINT_BACKEND)
G_MODULE_EXPORT
void void
g_io_module_load (GIOModule *module) g_io_module_load (GIOModule *module)
{ {
@ -119,13 +118,11 @@ g_io_module_load (GIOModule *module)
10); 10);
} }
G_MODULE_EXPORT
void void
g_io_module_unload (GIOModule *module) g_io_module_unload (GIOModule *module)
{ {
} }
G_MODULE_EXPORT
char ** char **
g_io_module_query (void) g_io_module_query (void)
{ {

View File

@ -236,7 +236,6 @@ static void secrets_service_vanished_cb (GDBusConnec
G_DEFINE_DYNAMIC_TYPE(GtkPrintBackendCups, gtk_print_backend_cups, GTK_TYPE_PRINT_BACKEND) G_DEFINE_DYNAMIC_TYPE(GtkPrintBackendCups, gtk_print_backend_cups, GTK_TYPE_PRINT_BACKEND)
G_MODULE_EXPORT
void void
g_io_module_load (GIOModule *module) g_io_module_load (GIOModule *module)
{ {
@ -251,13 +250,11 @@ g_io_module_load (GIOModule *module)
10); 10);
} }
G_MODULE_EXPORT
void void
g_io_module_unload (GIOModule *module) g_io_module_unload (GIOModule *module)
{ {
} }
G_MODULE_EXPORT
char ** char **
g_io_module_query (void) g_io_module_query (void)
{ {

View File

@ -102,7 +102,6 @@ static GtkPageSetup * file_printer_get_default_page_size (GtkPrinter
G_DEFINE_DYNAMIC_TYPE(GtkPrintBackendFile, gtk_print_backend_file, GTK_TYPE_PRINT_BACKEND) G_DEFINE_DYNAMIC_TYPE(GtkPrintBackendFile, gtk_print_backend_file, GTK_TYPE_PRINT_BACKEND)
G_MODULE_EXPORT
void void
g_io_module_load (GIOModule *module) g_io_module_load (GIOModule *module)
{ {
@ -116,13 +115,11 @@ g_io_module_load (GIOModule *module)
10); 10);
} }
G_MODULE_EXPORT
void void
g_io_module_unload (GIOModule *module) g_io_module_unload (GIOModule *module)
{ {
} }
G_MODULE_EXPORT
char ** char **
g_io_module_query (void) g_io_module_query (void)
{ {

View File

@ -83,7 +83,6 @@ static void gtk_print_backend_lpr_print_stream (GtkPrintBacke
G_DEFINE_DYNAMIC_TYPE (GtkPrintBackendLpr, gtk_print_backend_lpr, GTK_TYPE_PRINT_BACKEND) G_DEFINE_DYNAMIC_TYPE (GtkPrintBackendLpr, gtk_print_backend_lpr, GTK_TYPE_PRINT_BACKEND)
G_MODULE_EXPORT
void void
g_io_module_load (GIOModule *module) g_io_module_load (GIOModule *module)
{ {
@ -97,13 +96,11 @@ g_io_module_load (GIOModule *module)
10); 10);
} }
G_MODULE_EXPORT
void void
g_io_module_unload (GIOModule *module) g_io_module_unload (GIOModule *module)
{ {
} }
G_MODULE_EXPORT
char ** char **
g_io_module_query (void) g_io_module_query (void)
{ {

View File

@ -68,6 +68,7 @@ printbackends_args = [
'-DGTK_COMPILATION', '-DGTK_COMPILATION',
'-DGTK_DISABLE_DEPRECATION_WARNINGS', '-DGTK_DISABLE_DEPRECATION_WARNINGS',
'-DGTK_PRINT_BACKEND_ENABLE_UNSUPPORTED', '-DGTK_PRINT_BACKEND_ENABLE_UNSUPPORTED',
'-D_GLIB_EXTERN=@0@'.format(visibility_define),
] + common_cflags ] + common_cflags
if print_backends.contains('cups') if print_backends.contains('cups')