Skip to content

Commit 75070a6

Browse files
authored
feat: Ensure correct shared library exports and build configuration. (#105)
1 parent be59e19 commit 75070a6

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

CMakeLists.txt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/[email protected]")
5656
find_package(OpenSSL REQUIRED)
5757
message(STATUS "LaunchDarkly: using OpenSSL v${OPENSSL_VERSION}")
5858

59-
if (MSVC)
60-
set(Boost_USE_STATIC_LIBS ON)
61-
else ()
62-
if (BUILD_SHARED_LIBS)
63-
set(Boost_USE_STATIC_LIBS OFF)
64-
else ()
65-
set(Boost_USE_STATIC_LIBS ON)
66-
endif ()
67-
endif ()
59+
set(Boost_USE_STATIC_LIBS ON)
60+
61+
if(BUILD_SHARED_LIBS)
62+
# When building a shared library we hide all symbols
63+
# aside from this we have specifically exported for the C-API.
64+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
65+
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
66+
endif()
6867

6968
set(Boost_USE_MULTITHREADED ON)
7069
set(Boost_USE_STATIC_RUNTIME OFF)

libs/client-sdk/src/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,23 @@ add_library(${LIBNAME}
4343
flag_manager/flag_persistence.cpp
4444
bindings/c/sdk.cpp)
4545

46-
target_link_libraries(${LIBNAME}
46+
if(MSVC OR (NOT BUILD_SHARED_LIBS))
47+
target_link_libraries(${LIBNAME}
48+
PUBLIC launchdarkly::common
49+
PRIVATE Boost::headers Boost::json Boost::url launchdarkly::sse launchdarkly::internal foxy)
50+
else()
51+
# The default static lib builds, for linux, are positition independent.
52+
# So they do not link into a shared object without issues. So, when
53+
# building shared objects do not link the static libraries and instead
54+
# use the "src.hpp" files for required libraries.
55+
# macOS shares the same path for simplicity.
56+
target_link_libraries(${LIBNAME}
4757
PUBLIC launchdarkly::common
4858
PRIVATE Boost::headers launchdarkly::sse launchdarkly::internal foxy)
4959

60+
target_sources(${LIBNAME} PRIVATE boost.cpp)
61+
endif ()
62+
5063
add_library(launchdarkly::client ALIAS ${LIBNAME})
5164

5265

libs/client-sdk/src/boost.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file is used to include boost url/json when building a shared library on linux/mac.
2+
// Windows links static libs in this case and does not include these src files, as there
3+
// are issues compiling the value.ipp file from JSON with MSVC.
4+
#include <boost/url/src.hpp>
5+
#include <boost/json/src.hpp>

libs/client-sdk/src/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Client::Client(Config config, Context context)
99
std::move(context),
1010
kVersion)) {}
1111
bool Client::Initialized() const {
12-
return false;
12+
return client->Initialized();
1313
}
1414

1515
using FlagKey = std::string;

libs/server-sent-events/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_library(${LIBNAME} OBJECT
1111
parser.cpp
1212
event.cpp
1313
backoff.cpp)
14+
1415
target_link_libraries(${LIBNAME}
1516
PUBLIC OpenSSL::SSL Boost::headers foxy
1617
PRIVATE Boost::url Boost::disable_autolinking

0 commit comments

Comments
 (0)