Skip to content

Commit 16cf359

Browse files
authored
Add an option to control dependency linking for static build (#952)
1 parent 63a5d2a commit 16cf359

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ message(STATUS "-- SDK version: ${SDK_VERSION_PREFIX}-${MATSDK_BUILD_VERSION}")
218218

219219
# Only use custom curl if compiling with CPP11 PAL
220220
if (PAL_IMPLEMENTATION STREQUAL "CPP11")
221-
221+
222222
if(NOT BUILD_IOS)
223223
include(FindCURL)
224224
find_package(CURL REQUIRED)
@@ -245,6 +245,7 @@ option(BUILD_PACKAGE "Build package" YES)
245245
option(BUILD_PRIVACYGUARD "Build Privacy Guard" YES)
246246
option(BUILD_CDS "Build CDS - Common Diagnostic Stack" YES)
247247
option(BUILD_LIVEEVENTINSPECTOR "Build Live Event Inspector" YES)
248+
option(LINK_STATIC_DEPENDS "Link dependencies for static build" YES)
248249

249250
# Enable Azure Monitor / Application Insights end-point support
250251
option(BUILD_AZMON "Build for Azure Monitor" YES)
@@ -258,7 +259,7 @@ if(BUILD_UNIT_TESTS OR BUILD_FUNC_TESTS)
258259
add_library(gtest STATIC IMPORTED GLOBAL)
259260
message("Adding gmock")
260261
add_library(gmock STATIC IMPORTED GLOBAL)
261-
262+
262263
# message("Building libraries! - Path: ${CMAKE_CURRENT_SOURCE_DIR} ")
263264
# message("Building gtest")
264265
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/googletest/googletest/)

lib/CMakeLists.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Honor visibility properties for all target types
2+
cmake_policy(SET CMP0063 NEW)
3+
14
include_directories( . ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include/public ${CMAKE_CURRENT_SOURCE_DIR}/include/public ${CMAKE_CURRENT_SOURCE_DIR}/include/mat ${CMAKE_CURRENT_SOURCE_DIR}/pal ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/modules/exp ${CMAKE_CURRENT_SOURCE_DIR}/modules/dataviewer ${CMAKE_CURRENT_SOURCE_DIR}/modules/privacyguard ${CMAKE_CURRENT_SOURCE_DIR}/modules/liveeventinspector ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/Reachability ${CMAKE_CURRENT_SOURCE_DIR}/modules/cds /usr/local/include )
25

36
set(SRCS decorators/BaseDecorator.cpp
@@ -217,7 +220,7 @@ endif()
217220

218221
if(BUILD_SHARED_LIBS STREQUAL "ON")
219222
message("-- Building shared SDK library")
220-
223+
221224
# include(FindCURL)
222225
# find_package(CURL REQUIRED)
223226
# set(CMAKE_REQUIRED_LIBRARIES "${CURL_LIBRARIES}")
@@ -253,15 +256,17 @@ if(BUILD_SHARED_LIBS STREQUAL "ON")
253256
else()
254257
message("-- Building static SDK library")
255258
add_library(mat STATIC ${SRCS})
256-
if(PAL_IMPLEMENTATION STREQUAL "WIN32")
257-
target_link_libraries(mat ${LIBS} "${CMAKE_THREAD_LIBS_INIT}" "${CMAKE_DL_LIBS}" )
258-
else()
259-
add_library(sqlite3 STATIC IMPORTED GLOBAL)
260-
add_library(z STATIC IMPORTED GLOBAL)
261-
#
262-
# TODO: allow adding "${Tcmalloc_LIBRARIES}" to target_link_libraries for memory leak debugging
263-
#
264-
target_link_libraries(mat PRIVATE libsqlite3.a PUBLIC libz.a ${LIBS} "${CMAKE_THREAD_LIBS_INIT}" "${CMAKE_DL_LIBS}" )
259+
if(LINK_STATIC_DEPENDS)
260+
if(PAL_IMPLEMENTATION STREQUAL "WIN32")
261+
target_link_libraries(mat ${LIBS} "${CMAKE_THREAD_LIBS_INIT}" "${CMAKE_DL_LIBS}" )
262+
else()
263+
add_library(sqlite3 STATIC IMPORTED GLOBAL)
264+
add_library(z STATIC IMPORTED GLOBAL)
265+
#
266+
# TODO: allow adding "${Tcmalloc_LIBRARIES}" to target_link_libraries for memory leak debugging
267+
#
268+
target_link_libraries(mat PRIVATE libsqlite3.a PUBLIC libz.a ${LIBS} "${CMAKE_THREAD_LIBS_INIT}" "${CMAKE_DL_LIBS}" )
269+
endif()
265270
endif()
266271
install(TARGETS mat EXPORT mat ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
267272
endif()

0 commit comments

Comments
 (0)