[glib-networking] Fix static link on Windows



commit 2ba1cdd916e2e3d64c3065f55fe26c8438c20424
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Thu Oct 6 11:25:02 2022 -0400

    Fix static link on Windows
    
    When making a static module on Windows, we should not have `dllexport`
    on g_io_* functions. However, G_MODULE_EXPORT is defined to always have
    `dllexport` on Windows because it is made for shared modules only.
    
    Building both shared and static modules is not supported on Windows.
    
    Part-of: <https://gitlab.gnome.org/GNOME/glib-networking/-/merge_requests/223>

 meson.build                      | 6 ++++++
 proxy/gnome/gnome-proxy-module.c | 7 ++++---
 tls/gnutls/gnutls-module.c       | 7 ++++---
 tls/openssl/openssl-module.c     | 7 ++++---
 visibility.h                     | 9 +++++++++
 5 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/meson.build b/meson.build
index 349d5c99..0070052c 100644
--- a/meson.build
+++ b/meson.build
@@ -35,6 +35,12 @@ common_flags = [
 
 build_static = get_option('static_modules') or get_option('default_library') != 'shared'
 build_shared = get_option('default_library') != 'static'
+if build_static and build_shared and (host_system == 'windows' or host_system == 'cygwin')
+  error('On Windows default_library must be "shared" or "static" but not "both"')
+endif
+if build_static and not build_shared
+  common_flags += '-DGLIB_NETWORKING_STATIC_COMPILATION'
+endif
 
 add_project_arguments(common_flags, language: 'c')
 
diff --git a/proxy/gnome/gnome-proxy-module.c b/proxy/gnome/gnome-proxy-module.c
index b125810e..bde925ea 100644
--- a/proxy/gnome/gnome-proxy-module.c
+++ b/proxy/gnome/gnome-proxy-module.c
@@ -24,9 +24,10 @@
 #include <glib/gi18n-lib.h>
 
 #include "gproxyresolvergnome.h"
+#include "visibility.h"
 
 
-G_MODULE_EXPORT void
+GLIB_NETWORKING_EXPORT void
 g_io_gnomeproxy_load (GIOModule *module)
 {
   gchar *locale_dir;
@@ -49,12 +50,12 @@ g_io_gnomeproxy_load (GIOModule *module)
   g_free (locale_dir);
 }
 
-G_MODULE_EXPORT void
+GLIB_NETWORKING_EXPORT void
 g_io_gnomeproxy_unload (GIOModule *module)
 {
 }
 
-G_MODULE_EXPORT gchar **
+GLIB_NETWORKING_EXPORT gchar **
 g_io_gnomeproxy_query (void)
 {
   gchar *eps[] = {
diff --git a/tls/gnutls/gnutls-module.c b/tls/gnutls/gnutls-module.c
index 8dd09ca5..e7b624fd 100644
--- a/tls/gnutls/gnutls-module.c
+++ b/tls/gnutls/gnutls-module.c
@@ -28,9 +28,10 @@
 #include <glib/gi18n-lib.h>
 
 #include "gtlsbackend-gnutls.h"
+#include "visibility.h"
 
 
-G_MODULE_EXPORT void
+GLIB_NETWORKING_EXPORT void
 g_io_gnutls_load (GIOModule *module)
 {
   gchar *locale_dir;
@@ -53,12 +54,12 @@ g_io_gnutls_load (GIOModule *module)
   g_free (locale_dir);
 }
 
-G_MODULE_EXPORT void
+GLIB_NETWORKING_EXPORT void
 g_io_gnutls_unload (GIOModule *module)
 {
 }
 
-G_MODULE_EXPORT gchar **
+GLIB_NETWORKING_EXPORT gchar **
 g_io_gnutls_query (void)
 {
   gchar *eps[] = {
diff --git a/tls/openssl/openssl-module.c b/tls/openssl/openssl-module.c
index 374e4240..a4367749 100644
--- a/tls/openssl/openssl-module.c
+++ b/tls/openssl/openssl-module.c
@@ -29,9 +29,10 @@
 #include <gio/gio.h>
 
 #include "gtlsbackend-openssl.h"
+#include "visibility.h"
 
 
-G_MODULE_EXPORT void
+GLIB_NETWORKING_EXPORT void
 g_io_openssl_load (GIOModule *module)
 {
   gchar *locale_dir;
@@ -54,12 +55,12 @@ g_io_openssl_load (GIOModule *module)
   g_free (locale_dir);
 }
 
-G_MODULE_EXPORT void
+GLIB_NETWORKING_EXPORT void
 g_io_openssl_unload (GIOModule *module)
 {
 }
 
-G_MODULE_EXPORT gchar **
+GLIB_NETWORKING_EXPORT gchar **
 g_io_openssl_query (void)
 {
   return g_strsplit (G_TLS_BACKEND_EXTENSION_POINT_NAME, "!", -1);
diff --git a/visibility.h b/visibility.h
new file mode 100644
index 00000000..9f7c1d54
--- /dev/null
+++ b/visibility.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(GLIB_NETWORKING_STATIC_COMPILATION)
+#  define GLIB_NETWORKING_EXPORT __declspec(dllexport)
+#elif __GNUC__ >= 4
+#  define GLIB_NETWORKING_EXPORT __attribute__((visibility("default")))
+#else
+#  define GLIB_NETWORKING_EXPORT
+#endif


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