Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: support gnu symbol visibility when building DSO #80

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ set_target_properties("Zycore" PROPERTIES
LINKER_LANGUAGE C
VERSION "${Zycore_VERSION}"
SOVERSION "${Zycore_VERSION_MAJOR}.${Zycore_VERSION_MINOR}"
DEFINE_SYMBOL "ZYCORE_SHOULD_EXPORT")
DEFINE_SYMBOL "ZYCORE_SHOULD_EXPORT"
C_VISIBILITY_PRESET hidden)
target_include_directories("Zycore"
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
17 changes: 13 additions & 4 deletions include/Zycore/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,17 @@
/* Generic DLL import/export helpers */
/* ============================================================================================== */

#if defined(ZYAN_MSVC)
#if defined(ZYAN_MSVC) || (defined(ZYAN_WINDOWS) && defined(ZYAN_GNUC))
# define ZYAN_DLLEXPORT __declspec(dllexport)
# define ZYAN_DLLIMPORT __declspec(dllimport)
#else
# define ZYAN_DLLEXPORT
# define ZYAN_DLLIMPORT
# if defined(ZYAN_GNUC)
# define ZYAN_DLLEXPORT __attribute__((__visibility__("default")))
# define ZYAN_DLLIMPORT extern
# else
# define ZYAN_DLLEXPORT
# define ZYAN_DLLIMPORT
# endif
#endif

/* ============================================================================================== */
Expand Down Expand Up @@ -243,7 +248,11 @@
/**
* Symbol is not exported and for internal use only.
*/
#define ZYCORE_NO_EXPORT
#if defined(ZYAN_GNUC)
# define ZYCORE_NO_EXPORT __attribute__((__visibility__("hidden")))
#else
# define ZYCORE_NO_EXPORT
#endif

/* ============================================================================================== */
/* Misc compatibility macros */
Expand Down
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ if nolibc
'-fno-stack-protector',
language: 'c',
)
dep += declare_dependency(link_args: ['-nostdlib', '-nodefaultlibs'])
elif host_machine.system() == 'linux'
add_project_arguments(
'-D_GNU_SOURCE',
Expand All @@ -125,6 +124,8 @@ zycore_lib = library(
src + hdrs,
c_static_args: ['-DZYCORE_STATIC_BUILD'],
c_shared_args: ['-DZYCORE_SHOULD_EXPORT'],
link_args: (nolibc and cc.get_linker_id().startswith('ld.')) ? ['-nostdlib', '-nodefaultlibs'] : [],
gnu_symbol_visibility: 'hidden',
include_directories: inc,
implicit_include_directories: false,
dependencies: dep,
Expand Down