Skip to content

Commit bc64a4d

Browse files
authored
Tweaks for a full static build of LiteCore (#2391)
1. Add LITECORE_STATIC and use FLEECE_STATIC to ensure that objects don't try to use shared library importing in a static build on Windows 2. Remove LiteCoreP2P from platforms that don't support it 3. Add LiteCoreFull as a static library containing all of the needed bits for using LiteCore
1 parent 7d816aa commit bc64a4d

File tree

6 files changed

+60
-5
lines changed

6 files changed

+60
-5
lines changed

C/include/c4Compat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@
121121
#ifdef _MSC_VER
122122
# ifdef LITECORE_EXPORTS
123123
# define CBL_CORE_API __declspec(dllexport)
124-
# else
124+
# elif !defined(LITECORE_STATIC)
125125
# define CBL_CORE_API __declspec(dllimport)
126+
# else
127+
# define CBL_CORE_API
126128
# endif
127129
# define CBL_CORE_API_IMPL CBL_CORE_API
128130
#else

CMakeLists.txt

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ add_library(LiteCoreUnitTesting OBJECT EXCLUDE_FROM_ALL ${ALL_SRC_FILES})
223223
set(LiteCoreObjectsDefines
224224
LITECORE_IMPL
225225
LITECORE_CPP_API=1
226+
FLEECE_STATIC
226227
HAS_UNCAUGHT_EXCEPTIONS # date.h use std::uncaught_exceptions instead of std::uncaught_exception
227228
)
228229
target_compile_definitions(
@@ -297,14 +298,19 @@ set(
297298
)
298299

299300
if(BUILD_ENTERPRISE)
300-
set(
301+
list(APPEND
301302
LITECORE_LIBRARIES_PRIVATE
302-
${LITECORE_LIBRARIES_PRIVATE}
303303
LiteCoreREST_Objects
304304
LiteCoreWebSocket
305305
LiteCoreListener_Objects
306-
LiteCoreP2P
307306
)
307+
308+
if (APPLE OR ANDROID)
309+
list(APPEND
310+
LITECORE_LIBRARIES_PRIVATE
311+
LiteCoreP2P
312+
)
313+
endif()
308314
endif()
309315

310316
if(LITECORE_BUILD_SHARED)
@@ -420,6 +426,11 @@ target_include_directories(
420426
vendor/mbedtls/include
421427
)
422428

429+
target_compile_definitions(
430+
LiteCoreWebSocket PRIVATE
431+
FLEECE_STATIC
432+
)
433+
423434
target_link_libraries(
424435
LiteCoreWebSocket PUBLIC
425436
LiteCoreObjects
@@ -435,6 +446,39 @@ endif()
435446

436447
add_subdirectory(tool_support EXCLUDE_FROM_ALL)
437448

449+
if(LITECORE_BUILD_STATIC)
450+
set(LC_MONOLITHIC_OBJECTS
451+
$<TARGET_OBJECTS:LiteCoreObjects>
452+
$<TARGET_OBJECTS:BLIPObjects>
453+
$<TARGET_OBJECTS:FleeceObjects>
454+
)
455+
456+
if(BUILD_ENTERPRISE)
457+
list(APPEND LC_MONOLITHIC_OBJECTS
458+
$<TARGET_OBJECTS:LiteCoreREST_Objects>
459+
$<TARGET_OBJECTS:LiteCoreListener_Objects>
460+
)
461+
462+
if(APPLE OR ANDROID)
463+
list(APPEND LC_MONOLITHIC_OBJECTS
464+
$<TARGET_OBJECTS:LiteCoreP2P>
465+
)
466+
endif()
467+
endif()
468+
469+
add_library(LiteCoreFull STATIC ${LC_MONOLITHIC_OBJECTS})
470+
471+
# Link external (non object) libraries
472+
target_link_libraries(
473+
LiteCoreFull PRIVATE
474+
LiteCoreWebSocket
475+
SQLite3_UnicodeSN
476+
mbedcrypto
477+
mbedtls
478+
mbedx509
479+
CouchbaseSqlite3
480+
)
481+
endif()
438482

439483
### TESTS:
440484

LiteCore/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ setup_build()
131131
target_compile_definitions(
132132
CppTests PRIVATE
133133
-DLITECORE_CPP_TESTS=1
134+
-DFLEECE_STATIC
135+
-DLITECORE_STATIC
134136
-D_USE_MATH_DEFINES # Define math constants like PI
135137
-DNOMINMAX # Get rid of min/max macros that interfere with std::min/std::max
136138
-DCATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK

Networking/BLIP/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ target_include_directories(
6666
${LITECORE_LOCATION}/C/include
6767
${LITECORE_LOCATION}/C/Cpp_include
6868
)
69+
70+
target_compile_definitions(
71+
BLIPObjects PRIVATE
72+
-DFLEECE_STATIC
73+
-DLITECORE_STATIC
74+
)

REST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ target_include_directories(
4545

4646
target_compile_definitions(
4747
LiteCoreREST_Objects PRIVATE
48+
FLEECE_STATIC
4849
LITECORE_CPP_API=1
4950
HAS_UNCAUGHT_EXCEPTIONS # date.h use std::uncaught_exceptions instead of std::uncaught_exception
5051
)

vendor/fleece

0 commit comments

Comments
 (0)