Skip to content

Commit

Permalink
The remaining CMake & Jenkins changes for the Edge Server PR
Browse files Browse the repository at this point in the history
Almost all of this was done by Jim
  • Loading branch information
snej committed Feb 5, 2025
1 parent af5e4e5 commit 4788ebe
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 176 deletions.
2 changes: 2 additions & 0 deletions C/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ target_include_directories(
${TOP}vendor/fleece/API
${TOP}vendor/fleece/Fleece/Support
${TOP}C
${TOP}C/include
${TOP}C/Cpp_include
${TOP}Crypto
${TOP}Replicator
${TOP}Replicator/tests
Expand Down
4 changes: 2 additions & 2 deletions C/tests/cmake/platform_linux.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function(setup_build)
target_sources(
C4Tests PRIVATE
${TOP}Crypto/mbedUtils.cc
${TOP}LiteCore/Unix/strlcat.c
${TOP}Crypto/mbedUtils.cc
${TOP}LiteCore/Unix/strlcat.c
)

target_link_libraries(
Expand Down
64 changes: 35 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ Platform logic is largely separated into the cmake/platform_*.cmake files. Plat
- platform_win_desktop
]]#

cmake_minimum_required (VERSION 3.9)
cmake_policy(VERSION 3.9)
cmake_policy(SET CMP0057 NEW)
cmake_minimum_required (VERSION 3.20.3)

# Mac/apple setup -- must appear before the first "project()" line"
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0")
Expand Down Expand Up @@ -96,6 +94,8 @@ option(DISABLE_LTO_BUILD "Disable build with Link-time optimization" OFF)
option(LITECORE_BUILD_TESTS "Builds C4Tests and CppTests" ON)
option(LITECORE_WARNINGS_HARDCORE "Enables tons of warnings and makes them errors (Clang only)" OFF)
option(LITECORE_SANITIZE "Enables address and undefined-behavior sanitizers (Clang only)" OFF)
option(LITECORE_BUILD_SHARED "Enables building the LiteCore shared library" ON)
option(LITECORE_BUILD_STATIC "Enables building the LiteCore static library" ON)

set(LITECORE_PREBUILT_LIB "" CACHE STRING "If set, C4Tests will use the prebuilt LiteCore instead of building it from source")

Expand Down Expand Up @@ -209,7 +209,7 @@ target_compile_definitions(

set_litecore_source(RESULT ALL_SRC_FILES)
add_library(LiteCoreObjects OBJECT ${ALL_SRC_FILES})
add_library(LiteCoreUnitTesting OBJECT ${ALL_SRC_FILES})
add_library(LiteCoreUnitTesting OBJECT EXCLUDE_FROM_ALL ${ALL_SRC_FILES})
set(LiteCoreObjectsDefines
LITECORE_IMPL
LITECORE_CPP_API=1
Expand Down Expand Up @@ -276,11 +276,6 @@ target_include_directories(
${LiteCoreObjectsIncludes}
)

add_library(LiteCore SHARED $<TARGET_OBJECTS:LiteCoreObjects>)

add_library(LiteCoreStatic STATIC EXCLUDE_FROM_ALL $<TARGET_OBJECTS:LiteCoreObjects>)
target_link_libraries(LiteCoreStatic PRIVATE LiteCoreObjects)

# Library flags defined in platform_linux
set(
LITECORE_LIBRARIES_PRIVATE
Expand All @@ -298,12 +293,36 @@ if(BUILD_ENTERPRISE)
)
endif()

target_include_directories(
LiteCore INTERFACE
C/include
C/Cpp_include
)
target_link_libraries(LiteCore PRIVATE ${LITECORE_LIBRARIES_PRIVATE})
if(LITECORE_BUILD_SHARED)
add_library(LiteCore SHARED $<TARGET_OBJECTS:LiteCoreObjects>)
target_include_directories(
LiteCore INTERFACE
C/include
C/Cpp_include
)
target_link_libraries(LiteCore PRIVATE ${LITECORE_LIBRARIES_PRIVATE})

install (
TARGETS LiteCore
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
OPTIONAL
)

file(GLOB LITECORE_HEADERS ${PROJECT_SOURCE_DIR}/C/include/*.h ${PROJECT_SOURCE_DIR}/C/Cpp_include/*.hh)
file(GLOB FLEECE_HEADERS ${PROJECT_SOURCE_DIR}/vendor/fleece/API/fleece/*.h ${PROJECT_SOURCE_DIR}/vendor/fleece/API/fleece/*.hh)

install(FILES ${LITECORE_HEADERS} DESTINATION include)
install(FILES ${FLEECE_HEADERS} DESTINATION include/fleece)
endif()

if(LITECORE_BUILD_STATIC)
add_library(LiteCoreStatic STATIC EXCLUDE_FROM_ALL $<TARGET_OBJECTS:LiteCoreObjects>)
target_link_libraries(LiteCoreStatic PRIVATE LiteCoreObjects)
endif()


target_link_libraries(
LiteCoreObjects INTERFACE
SQLite3_UnicodeSN
Expand All @@ -330,20 +349,6 @@ if(USE_COUCHBASE_SQLITE)
)
endif()

install (
TARGETS LiteCore
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
OPTIONAL
)

file(GLOB LITECORE_HEADERS ${PROJECT_SOURCE_DIR}/C/include/*.h ${PROJECT_SOURCE_DIR}/C/Cpp_include/*.hh)
file(GLOB FLEECE_HEADERS ${PROJECT_SOURCE_DIR}/vendor/fleece/API/fleece/*.h ${PROJECT_SOURCE_DIR}/vendor/fleece/API/fleece/*.hh)

install(FILES ${LITECORE_HEADERS} DESTINATION include)
install(FILES ${FLEECE_HEADERS} DESTINATION include/fleece)

### Support Libraries (Add functionality, but add nothing to official API)

add_subdirectory(REST EXCLUDE_FROM_ALL)
Expand Down Expand Up @@ -375,6 +380,7 @@ target_include_directories(
C/include
C/Cpp_include
Crypto
LiteCore/Database
LiteCore/Support
Networking
Networking/BLIP/
Expand Down
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pipeline {
agent { label 's61113u16 (litecore)' }
environment {
BRANCH = "${BRANCH_NAME}"
CC = "gcc-10"
CXX = "g++-10"
CC = "gcc-11"
CXX = "g++-11"
}
steps {
sh 'jenkins/jenkins_unix.sh'
Expand Down
21 changes: 7 additions & 14 deletions cmake/platform_android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ function(setup_litecore_build)
-DSQLITE_UNLINK_AFTER_CLOSE
)

target_link_libraries(
LiteCore PUBLIC
log
atomic
)
if(LITECORE_BUILD_SHARED)
target_link_libraries(
LiteCore PUBLIC
log
atomic
)
endif()

target_include_directories(
LiteCoreWebSocket
Expand All @@ -83,15 +85,6 @@ function(setup_litecore_build)
)
endfunction()

function(setup_support_build)
setup_support_build_linux()

target_include_directories(
Support PRIVATE
LiteCore/Android
)
endfunction()

function(setup_rest_build)
# No-op
endfunction()
5 changes: 0 additions & 5 deletions cmake/platform_linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ function(setup_litecore_build_linux)
${liteCoreVariant} PRIVATE
-DLITECORE_USES_ICU=1
)

target_link_libraries(
${liteCoreVariant} INTERFACE
${ICU_LIBS}
)
endforeach()
endif()

Expand Down
92 changes: 54 additions & 38 deletions cmake/platform_linux_desktop.cmake
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
include("${CMAKE_CURRENT_LIST_DIR}/platform_linux.cmake")

MACRO (_install_gcc_file GCCFILENAME)
IF (UNIX AND NOT APPLE)
EXECUTE_PROCESS(
COMMAND "${CMAKE_CXX_COMPILER}" ${CMAKE_CXX_FLAGS} -print-file-name=${GCCFILENAME}
OUTPUT_VARIABLE _gccfile OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE _errormsg
RESULT_VARIABLE _failure)
IF (_failure)
MESSAGE (FATAL_ERROR "Error (${_failure}) determining path to ${GCCFILENAME}: ${_errormsg}")
ENDIF ()
# We actually need to copy any files with longer filenames - this can be eg.
# libstdc++.so.6, or libgcc_s.so.1.
# Note: RPM demands that .so files be executable or else it won't
# extract debug info from them.
FILE (GLOB _gccfiles "${_gccfile}*")
FOREACH (_gccfile ${_gccfiles})
# Weird extraneous file not desired
IF (_gccfile MATCHES ".py$")
CONTINUE ()
ENDIF ()
INSTALL (FILES "${_gccfile}" DESTINATION lib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
ENDFOREACH ()
ENDIF ()
ENDMACRO (_install_gcc_file)

_install_gcc_file(libstdc++.so.6)
_install_gcc_file(libgcc_s.so.1)

IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE STRING
"The install location" FORCE)
LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}")
ENDIF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

INCLUDE (${CMAKE_CURRENT_LIST_DIR}/../jenkins/CBDeps.cmake)

if(NOT LITECORE_DISABLE_ICU AND NOT LITECORE_DYNAMIC_ICU)
# Install cbdeps packages using cbdep tool
CBDEP_INSTALL (PACKAGE icu4c VERSION 76.1-1)
FILE (COPY "${CBDEP_icu4c_DIR}/lib" DESTINATION "${CMAKE_INSTALL_PREFIX}")
endif()

function(setup_globals)
setup_globals_linux()

# Enable relative RPATHs for installed bits
set (CMAKE_INSTALL_RPATH "\$ORIGIN" PARENT_SCOPE)

# NOTE: We used to do a whole dog and pony show here to get clang to use libc++. Now we don't care
# and if the person using this project wants to do so then they will have to set the options
# accordingly

if(NOT LITECORE_DISABLE_ICU AND NOT LITECORE_DYNAMIC_ICU)
set (_icu_libs)
foreach (_lib icuuc icui18n icudata)
unset (_iculib CACHE)
find_library(_iculib ${_lib} HINTS "${CBDEP_icu4c_DIR}/lib")
if (NOT _iculib)
message(FATAL_ERROR "${_lib} not found")
endif()
list(APPEND _icu_libs ${_iculib})
endforeach()
set (ICU_LIBS ${_icu_libs} CACHE STRING "ICU libraries" FORCE)
message("Found ICU libs at ${ICU_LIBS}")

find_path(LIBICU_INCLUDE unicode/ucol.h
HINTS "${CBDEP_icu4c_DIR}"
PATH_SUFFIXES include)
if (NOT LIBICU_INCLUDE)
message(FATAL_ERROR "libicu header files not found")
endif()
message("Using libicu header files in ${LIBICU_INCLUDE}")
include_directories("${LIBICU_INCLUDE}")
mark_as_advanced(ICU_LIBS LIBICU_INCLUDE)
endif()

find_library(ZLIB_LIB z)
if (NOT ZLIB_LIB)
message(FATAL_ERROR "libz not found")
Expand All @@ -47,7 +63,7 @@ function(setup_globals)
message("Using libz header files in ${ZLIB_INCLUDE}")

mark_as_advanced(
ICU_LIBS LIBICU_INCLUDE ZLIB_LIB ZLIB_INCLUDE
ZLIB_LIB ZLIB_INCLUDE
)
endfunction()

Expand Down Expand Up @@ -76,15 +92,6 @@ function(setup_litecore_build)
${target} PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:-Wno-psabi;-Wno-odr>"
)

# Enough is enough, we keep bumping the compiler to get newer C++ stuff
# and then suffering the consequences of that stuff not being available
# everywhere that we need. Just build it into the product directly
target_link_options(
${target} PRIVATE
"-static-libstdc++"
"-static-libgcc"
)
endforeach()

foreach(liteCoreVariant LiteCoreObjects LiteCoreUnitTesting)
Expand All @@ -93,6 +100,15 @@ function(setup_litecore_build)
Threads::Threads
)
endforeach()

if(NOT LITECORE_DISABLE_ICU AND NOT LITECORE_DYNAMIC_ICU)
foreach(liteCoreVariant LiteCoreObjects LiteCoreUnitTesting)
target_link_libraries(
${liteCoreVariant} PUBLIC
icu::icu4c
)
endforeach()
endif()
endfunction()

function(setup_rest_build)
Expand Down
19 changes: 11 additions & 8 deletions cmake/platform_unix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ function(setup_litecore_build_unix)
set_property(TARGET FleeceStatic PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

set_property(TARGET LiteCore PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
if(LITECORE_BUILD_SHARED)
set_property(TARGET LiteCore PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "^armv[67]")
if(LITECORE_BUILD_SHARED AND CMAKE_SYSTEM_PROCESSOR MATCHES "^armv[67]")
# C/C++ atomic operations on ARM6/7 emit calls to functions in libatomic
target_link_libraries(
LiteCore PRIVATE
Expand All @@ -65,12 +67,13 @@ function(setup_litecore_build_unix)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LITECORE_SAN_FLAGS}" CACHE INTERNAL "")

# The linker also needs to be told, so it can link the appropriate sanitizer runtime libs:
foreach(target LiteCore CppTests C4Tests)
target_link_options(${target} PRIVATE
-fsanitize=address
-fsanitize=undefined
)
endforeach ()
if (LITECORE_BUILD_SHARED)
target_link_options(LiteCore PRIVATE -fsanitize=address -fsanitize=undefined)
endif()
if (LITECORE_BUILD_TESTS)
target_link_options(CppTests PRIVATE -fsanitize=address -fsanitize=undefined)
target_link_options(C4Tests PRIVATE -fsanitize=address -fsanitize=undefined)
endif()
else()
set(LITECORE_COMPILE_OPTIONS
-fstack-protector
Expand Down
6 changes: 5 additions & 1 deletion jenkins/CBDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ IF (NOT CBDeps_INCLUDED)
EXECUTE_PROCESS (
COMMAND "${CBDEP_EXE}"
-p linux
install -d "${cbdep_INSTALL_DIR}"
install -C -d "${cbdep_INSTALL_DIR}"
${cbdep_PACKAGE} ${cbdep_VERSION}
RESULT_VARIABLE _cbdep_result
OUTPUT_VARIABLE _cbdep_out
Expand All @@ -72,6 +72,10 @@ IF (NOT CBDeps_INCLUDED)
CACHE STRING "Version of cbdep package '${cbdep_PACKAGE}'" FORCE)
SET (CBDEP_${cbdep_PACKAGE}_DIR "${cbdep_TARGET_DIR}"
CACHE STRING "Install location of cbdep package '${cbdep_PACKAGE}'" FORCE)
IF (IS_DIRECTORY "${cbdep_TARGET_DIR}/cmake")
SET ("${cbdep_PACKAGE}_ROOT" "${cbdep_TARGET_DIR}")
FIND_PACKAGE (${cbdep_PACKAGE} REQUIRED)
ENDIF ()
MESSAGE (STATUS "Using cbdeps package ${cbdep_PACKAGE} ${cbdep_VERSION}")
ENDFUNCTION (CBDEP_INSTALL)

Expand Down
Loading

0 comments on commit 4788ebe

Please sign in to comment.