portability: fix usage of TVG_API

Rule of thumb on Windows:
  * for a DLL:
    * if the library is built, set TVG_API to __declspec(dllexport)
    * if the library is used, set TVG_API to __declspec(dllimport)
  * for a static library, set TVG_API to nothing

To set TVG_API for a static library, TVG_STATIC is defined when the stataic library is built.
Otherwise, TVG_API is correctly set for a DLL.
Also sun and intel compilers are handled

@issue: https://github.com/thorvg/thorvg/issues/1446
This commit is contained in:
Vincent Torri 2023-05-13 09:38:53 +02:00 committed by Hermet Park
parent 41c41b538d
commit be2de28312
8 changed files with 57 additions and 33 deletions

View file

@ -23,28 +23,36 @@
#undef TVG_API
#endif
#if defined(_WIN32) && !defined(__clang__)
#ifndef TVG_STATIC
#ifdef _WIN32
#if TVG_BUILD
#if TVG_EXPORT
#define TVG_API __declspec(dllexport)
#else
#define TVG_API
#endif
#else
#define TVG_API __declspec(dllimport)
#endif
#define TVG_DEPRECATED __declspec(deprecated)
#elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC))
#define TVG_API __global
#else
#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__INTEL_COMPILER)
#define TVG_API __attribute__ ((visibility("default")))
#else
#define TVG_API
#endif
#endif
#else
#if TVG_BUILD
#if TVG_EXPORT
#define TVG_API __attribute__ ((visibility ("default")))
#else
#define TVG_API
#endif
#else
#define TVG_API
#endif
#endif
#ifdef TVG_DEPRECATED
#undef TVG_DEPRECATED
#endif
#ifdef _WIN32
#define TVG_DEPRECATED __declspec(deprecated)
#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#define TVG_DEPRECATED __attribute__ ((__deprecated__))
#else
#define TVG_DEPRECATED
#endif
#define _TVG_DECLARE_PRIVATE(A) \

View file

@ -1,4 +1,6 @@
compiler_flags = ['-DTVG_BUILD']
if (lib_type == 'static')
compiler_flags += ['-DTVG_STATIC']
endif
if all_tools or get_option('tools').contains('svg2png') == true
subdir('svg2png')

View file

@ -3,5 +3,5 @@ svg2png_src = files('svg2png.cpp', 'lodepng.cpp')
executable('svg2png',
svg2png_src,
include_directories : headers,
cpp_args: compiler_flags,
cpp_args : compiler_flags,
link_with : thorvg_lib)

View file

@ -3,5 +3,5 @@ svg2tvg_src = files('svg2tvg.cpp')
executable('svg2tvg',
svg2tvg_src,
include_directories : headers,
cpp_args: compiler_flags,
cpp_args : compiler_flags,
link_with : thorvg_lib)

View file

@ -25,28 +25,36 @@
#undef TVG_API
#endif
#if defined(_WIN32) && !defined(__clang__)
#ifndef TVG_STATIC
#ifdef _WIN32
#if TVG_BUILD
#if TVG_EXPORT
#define TVG_API __declspec(dllexport)
#else
#define TVG_API
#endif
#else
#define TVG_API __declspec(dllimport)
#endif
#define TVG_DEPRECATED __declspec(deprecated)
#elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC))
#define TVG_API __global
#else
#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__INTEL_COMPILER)
#define TVG_API __attribute__ ((visibility("default")))
#else
#define TVG_API
#endif
#endif
#else
#if TVG_BUILD
#if TVG_EXPORT
#define TVG_API __attribute__ ((visibility ("default")))
#else
#define TVG_API
#endif
#else
#define TVG_API
#endif
#endif
#ifdef TVG_DEPRECATED
#undef TVG_DEPRECATED
#endif
#ifdef _WIN32
#define TVG_DEPRECATED __declspec(deprecated)
#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#define TVG_DEPRECATED __attribute__ ((__deprecated__))
#else
#define TVG_DEPRECATED
#endif
#ifdef __cplusplus

View file

@ -1,4 +1,6 @@
compiler_flags = ['-DTVG_BUILD']
if (lib_type == 'static')
compiler_flags += ['-DTVG_STATIC']
endif
examples_dep = dependency('elementary', required : true)

View file

@ -1,10 +1,12 @@
compiler_flags = ['-DTVG_BUILD']
compiler_flags = []
override_options = []
lib_type = get_option('default_library')
if (lib_type == 'shared')
compiler_flags += ['-DTVG_EXPORT']
compiler_flags += ['-DTVG_EXPORT', '-DTVG_BUILD']
else
compiler_flags += ['-DTVG_STATIC']
endif
cc = meson.get_compiler('cpp')

View file

@ -1,4 +1,6 @@
compiler_flags = ['-DTVG_BUILD']
if (lib_type == 'static')
compiler_flags += ['-DTVG_STATIC']
endif
test_file = [
'testAccessor.cpp',