Skip to content

Commit d0e7cb0

Browse files
authored
only export interface symbols from shared libraries on non-Windows (#82)
* only export interface symbols from shared libraries on non-Windows systems * move visibility preset to root project file. * also set CMAKE_VISIBILITY_INLINES_HIDDEN * do not define LIBGME_VISIBILITY
1 parent dd4f39a commit d0e7cb0

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
cmake_minimum_required(VERSION 3.13...3.19)
22

3+
set(CMAKE_C_VISIBILITY_PRESET hidden)
4+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
5+
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
6+
37
if (VCPKG_LIBSNDFILE)
48
list(APPEND VCPKG_MANIFEST_FEATURES "vcpkg-libsndfile")
59
endif()

source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# added as interface sources. Thus whatever links to zmusic-obj will be in
33
# charge of compiling. As a result any properties set on zmusic-obj should be
44
# interface.
5+
56
add_library(zmusic-obj INTERFACE)
67
target_sources(zmusic-obj
78
INTERFACE

source/zmusic/zmusic_internal.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#pragma once
22
#define ZMUSIC_INTERNAL
33

4-
#if defined(_MSC_VER) && !defined(ZMUSIC_STATIC)
5-
#define DLL_EXPORT __declspec(dllexport)
6-
#define DLL_IMPORT __declspec(dllexport) // without this the compiler complains.
4+
#if !defined(ZMUSIC_STATIC)
5+
#if defined(_MSC_VER)
6+
#define DLL_EXPORT __declspec(dllexport)
7+
#define DLL_IMPORT __declspec(dllexport) // without this the compiler complains.
8+
#else
9+
#define DLL_EXPORT __attribute__((visibility("default")))
10+
#define DLL_IMPORT
11+
#endif
712
#else
8-
#define DLL_EXPORT
9-
#define DLL_IMPORT
13+
#define DLL_EXPORT
14+
#define DLL_IMPORT
1015
#endif
1116

1217
typedef class MIDISource *ZMusic_MidiSource;

thirdparty/game-music-emu/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ if (COMPILER_IS_GNUCXX_COMPATIBLE)
8484
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wextra")
8585
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
8686

87-
# Assume we have visibility support on any compiler that supports C++11
88-
add_definitions (-DLIBGME_VISIBILITY)
87+
# Assume we have visibility support on any compiler that supports C++11
88+
# [ZMusic] we do not want to export this interface, so do not unhide the API functions.
89+
#add_definitions (-DLIBGME_VISIBILITY)
8990
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
9091

9192
# Try to protect against undefined behavior from signed integer overflow

thirdparty/game-music-emu/gme/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(libgme_SRCS Blip_Buffer.cpp
88
Effects_Buffer.cpp
99
Fir_Resampler.cpp
1010
gme.cpp
11+
gme.h
1112
Gme_File.cpp
1213
M3u_Playlist.cpp
1314
Multi_Buffer.cpp

0 commit comments

Comments
 (0)