diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2023-01-31 01:07:14 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2023-08-16 16:33:04 +0100 |
commit | ba4d5fbd5dad46c84e38ffbb032799a7a9380f42 (patch) | |
tree | 95df3dcf55174b6da5064ed8a2ebb1bd6e25e694 | |
parent | ff02c2c2684d9eecb2f5fefe689fe60ff8e98280 (diff) |
Build with hidden symbols by default
We should default on every platform we care about to hidden symbols, to
avoid leaking private symbols.
On Windows this is the default state of affairs with the MSVC toolchain;
with GCC and GCC-compatible toolchains, we need to opt into this
behaviour. Luckily for us, Cairo already has an annotation for public
symbols, so we can easily tweak it to include the visibility attribute.
When building ancillary libraries as part of the Cairo compilation on
Windows, we use a pre-processor symbol to ensure that we keep the
dllexport annotation. This avoids including the cairoint.h header file.
Fixes: #582
-rw-r--r-- | boilerplate/meson.build | 1 | ||||
-rw-r--r-- | src/cairo.h | 23 | ||||
-rw-r--r-- | src/cairoint.h | 4 | ||||
-rw-r--r-- | src/meson.build | 30 | ||||
-rw-r--r-- | util/cairo-fdr/meson.build | 4 | ||||
-rw-r--r-- | util/cairo-gobject/meson.build | 3 | ||||
-rw-r--r-- | util/cairo-script/cairo-script-interpreter.c | 3 | ||||
-rw-r--r-- | util/cairo-script/meson.build | 2 | ||||
-rw-r--r-- | util/cairo-sphinx/meson.build | 3 | ||||
-rw-r--r-- | util/cairo-trace/meson.build | 5 |
10 files changed, 36 insertions, 42 deletions
diff --git a/boilerplate/meson.build b/boilerplate/meson.build index 450eabf3e..544bfcc09 100644 --- a/boilerplate/meson.build +++ b/boilerplate/meson.build @@ -28,6 +28,7 @@ cairo_boilerplate_constructors = custom_target('cairo-boilerplate-constructors.c libcairoboilerplate = static_library('cairoboilerplate', cairo_boilerplate_sources + [cairo_boilerplate_constructors], include_directories: [incbase], dependencies: deps + [libcairo_dep], + c_args: ['-DCAIRO_COMPILATION'], install: false, build_by_default: false, ) diff --git a/src/cairo.h b/src/cairo.h index a2c955281..f6028a243 100644 --- a/src/cairo.h +++ b/src/cairo.h @@ -50,14 +50,25 @@ # define CAIRO_END_DECLS #endif -#ifndef cairo_public -# if defined (_MSC_VER) && ! defined (CAIRO_WIN32_STATIC_BUILD) -# define cairo_public __declspec(dllimport) -# else -# define cairo_public -# endif +#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(CAIRO_WIN32_STATIC_BUILD) +# define _cairo_export __declspec(dllexport) +# define _cairo_import __declspec(dllimport) +#elif defined(__GNUC__) && (__GNUC__ >= 4) +# define _cairo_export __attribute__((__visibility__("default"))) +# define _cairo_import +#else +# define _cairo_export +# define _cairo_import #endif +#ifdef CAIRO_COMPILATION +# define _cairo_api _cairo_export +#else +# define _cairo_api _cairo_import +#endif + +#define cairo_public _cairo_api extern + CAIRO_BEGIN_DECLS #define CAIRO_VERSION_ENCODE(major, minor, micro) ( \ diff --git a/src/cairoint.h b/src/cairoint.h index c94ed9b8c..c906c25c1 100644 --- a/src/cairoint.h +++ b/src/cairoint.h @@ -49,10 +49,6 @@ #include "config.h" -#ifdef _MSC_VER -#define cairo_public __declspec(dllexport) -#endif - #include <assert.h> #include <stdlib.h> #include <string.h> diff --git a/src/meson.build b/src/meson.build index f777fcd1c..ac06ac61a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -242,9 +242,10 @@ endif libcairo = library('cairo', cairo_sources, dependencies: deps, - c_args: cairo_no_warn_c_args + pthread_c_args, - cpp_args: cairo_no_warn_c_args + pthread_c_args, + c_args: cairo_no_warn_c_args + pthread_c_args + ['-DCAIRO_COMPILATION'], + cpp_args: cairo_no_warn_c_args + pthread_c_args + ['-DCAIRO_COMPILATION'], link_args: extra_link_args, + gnu_symbol_visibility: 'hidden', soversion: cairo_version_sonum, version: cairo_libversion, install: true, @@ -283,29 +284,4 @@ if shell.found() suite: ['fast', 'lint'], workdir: meson.current_source_dir()) endforeach - - env = environment() - env.set('CAIRO_HAS_HIDDEN_SYMBOLS', '1') - - cairo_def = custom_target('make-cairo-def', - input : cairo_headers, - output : 'cairo.def', - command : [ shell, - meson.current_source_dir()/'make-cairo-def.sh', - '@OUTPUT@', - cairo_features_file, - '@INPUT@' - ]) - - test('check-def', shell, - args: ['meson-check-def.sh', cairo_def, libcairo ], - env: env, - workdir: meson.current_source_dir()) - - test('check-plt.sh', shell, - args: ['check-plt.sh', libcairo ], - env: env, - suite: ['fast', 'plt'], - workdir: meson.current_source_dir()) - endif diff --git a/util/cairo-fdr/meson.build b/util/cairo-fdr/meson.build index 001af27bc..0d00e43f7 100644 --- a/util/cairo-fdr/meson.build +++ b/util/cairo-fdr/meson.build @@ -5,6 +5,8 @@ cairo_fdr_sources = [ libcairofdr = library('cairo-fdr', cairo_fdr_sources, include_directories: [incbase, incsrc], dependencies: deps, + gnu_symbol_visibility: 'hidden', + link_args: extra_link_args, install: true, - install_dir: join_paths(get_option('prefix'), get_option('libdir'), 'cairo'), + install_dir: get_option('libdir') / 'cairo', ) diff --git a/util/cairo-gobject/meson.build b/util/cairo-gobject/meson.build index 0a525b6fa..660088771 100644 --- a/util/cairo-gobject/meson.build +++ b/util/cairo-gobject/meson.build @@ -12,6 +12,9 @@ libcairogobject = library('cairo-gobject', cairo_gobject_sources, dependencies: [glib_dep, gobject_dep, libcairo_dep], soversion: cairo_version_sonum, version: cairo_libversion, + gnu_symbol_visibility: 'hidden', + c_args: ['-DCAIRO_COMPILATION'], + link_args: extra_link_args, install: true, ) diff --git a/util/cairo-script/cairo-script-interpreter.c b/util/cairo-script/cairo-script-interpreter.c index 04f12e8f9..e3aa3bae8 100644 --- a/util/cairo-script/cairo-script-interpreter.c +++ b/util/cairo-script/cairo-script-interpreter.c @@ -34,9 +34,10 @@ #include "config.h" -#include "cairo-script-private.h" #include "cairo.h" +#include "cairo-script-private.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/util/cairo-script/meson.build b/util/cairo-script/meson.build index 51e0ce7cd..60cec2b6e 100644 --- a/util/cairo-script/meson.build +++ b/util/cairo-script/meson.build @@ -30,6 +30,8 @@ libcairoscript = library('cairo-script-interpreter', dependencies: deps + [libcairo_dep, lzo_dep], soversion: cairo_version_sonum, version: cairo_libversion, + c_args: ['-DCAIRO_COMPILATION'], + link_args: extra_link_args, install: true, ) diff --git a/util/cairo-sphinx/meson.build b/util/cairo-sphinx/meson.build index 20ea04d7f..467ad3b75 100644 --- a/util/cairo-sphinx/meson.build +++ b/util/cairo-sphinx/meson.build @@ -10,7 +10,7 @@ libcairosphinx = library('cairo-sphinx', libcairo_sphinx_sources, include_directories: [incbase, incsrc], dependencies: deps, install: true, - install_dir: join_paths(get_option('prefix'), get_option('libdir'), 'cairo'), + install_dir: get_option('libdir') / 'cairo', ) libdir = join_paths(get_option('prefix'), get_option('libdir')) @@ -21,5 +21,6 @@ cairosphinx_exe = executable('cairo-sphinx', cairo_sphinx_sources, dependencies: deps + [glib_dep, rt_dep, libcairo_dep, cairoboilerplate_dep, libcairoscript_dep], link_with: [libcairosphinx], link_args: extra_link_args, + gnu_symbol_visibility: 'hidden', install: true, ) diff --git a/util/cairo-trace/meson.build b/util/cairo-trace/meson.build index c4a504759..8d4ac131b 100644 --- a/util/cairo-trace/meson.build +++ b/util/cairo-trace/meson.build @@ -11,10 +11,11 @@ shared_lib_ext = libcairo.full_path().split('.')[-1] libcairotrace = library('cairo-trace', cairo_trace_sources, include_directories: [incbase, incsrc], dependencies: deps, - link_args: extra_link_args, c_args: ['-DSHARED_LIB_EXT="@0@"'.format(shared_lib_ext),] + pthread_c_args, + link_args: extra_link_args, + gnu_symbol_visibility: 'hidden', install: true, - install_dir: join_paths(get_option('prefix'), get_option('libdir'), 'cairo'), + install_dir: get_option('libdir') / 'cairo', ) trace_conf = configuration_data() |