Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust CMake files to used by vcpkg #7334

Merged
merged 8 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 42 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

Expand Down Expand Up @@ -279,19 +281,7 @@ if(CMAKE_USE_PTHREADS_INIT)
endif()

find_package(Backtrace)
if(Backtrace_FOUND)
add_library(Backtrace::Backtrace INTERFACE IMPORTED)
if(Backtrace_LIBRARIES AND NOT CMAKE_GENERATOR STREQUAL Xcode)
# Apple platforms always have backtrace. We disregard the `Backtrace_*` variables
# because their paths are hardcoded to one SDK within Xcode (e.g. macosx),
# whereas we build for several different SDKs and thus we can't use the include path from one in the other.
# Otherwise if CMake found that the backtrace facility is provided by an external library and not built-in
# we need to configure the interface target with the library include and link path.
target_include_directories(Backtrace::Backtrace INTERFACE ${Backtrace_INCLUDE_DIRS})
target_link_libraries(Backtrace::Backtrace INTERFACE ${Backtrace_LIBRARIES})
endif()
set(REALM_HAVE_BACKTRACE ON)
endif()
set(REALM_HAVE_BACKTRACE ${Backtrace_FOUND})

if(REALM_ENABLE_SYNC)
option(REALM_FORCE_OPENSSL "Always use OpenSSL for SSL needs, regardless of target platform." OFF)
Expand All @@ -313,9 +303,6 @@ if(REALM_NEEDS_OPENSSL OR REALM_FORCE_OPENSSL)
include(${OPENSSL_CMAKE_INCLUDE_FILE})
endif()

if(NOT DEFINED OPENSSL_USE_STATIC_LIBS)
set(OPENSSL_USE_STATIC_LIBS ON)
endif()
find_package(OpenSSL REQUIRED)
set(REALM_HAVE_OPENSSL ON)
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)" OPENSSL_VERSION_MAJOR_MINOR "${OPENSSL_VERSION}")
Expand All @@ -330,8 +317,11 @@ endif()
# Emscripten does provide Zlib, but it doesn't work with find_package and is handled specially
if(NOT APPLE AND NOT EMSCRIPTEN AND NOT TARGET ZLIB::ZLIB)
if(WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND REALM_LINUX_TOOLCHAIN))
realm_acquire_dependency(zlib ${DEP_ZLIB_VERSION} ZLIB_CMAKE_INCLUDE_FILE)
include(${ZLIB_CMAKE_INCLUDE_FILE})
find_package(ZLIB)
if (NOT ZLIB_FOUND)
realm_acquire_dependency(zlib ${DEP_ZLIB_VERSION} ZLIB_CMAKE_INCLUDE_FILE)
include(${ZLIB_CMAKE_INCLUDE_FILE})
endif()
elseif(ANDROID)
# On Android FindZLIB chooses the static libz over the dynamic one, but this leads to issues
# (see https://github.com/android/ndk/issues/1179)
Expand Down Expand Up @@ -369,6 +359,39 @@ add_subdirectory(bindgen)
# Install the licence and changelog files
install(FILES LICENSE CHANGELOG.md DESTINATION "doc/realm" COMPONENT devel)

# Make the project importable from the build directory
set(REALM_EXPORTED_TARGETS
Storage
QueryParser
ObjectStore
RealmFFI
RealmFFIStatic
)
if(REALM_ENABLE_SYNC)
list(APPEND REALM_EXPORTED_TARGETS Sync)
endif()
export(TARGETS ${REALM_EXPORTED_TARGETS} NAMESPACE Realm:: FILE RealmTargets.cmake)
configure_file(tools/cmake/RealmConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/RealmConfig.cmake @ONLY)
configure_file(tools/cmake/AcquireRealmDependency.cmake ${CMAKE_CURRENT_BINARY_DIR}/AcquireRealmDependency.cmake @ONLY)

# Make the project importable from the install directory
install(EXPORT realm
NAMESPACE Realm::
FILE RealmTargets.cmake
DESTINATION share/cmake/Realm
COMPONENT devel
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/RealmConfig.cmake
DESTINATION share/cmake/Realm
COMPONENT devel
)

install(FILES tools/cmake/AcquireRealmDependency.cmake
DESTINATION share/cmake/Realm
COMPONENT devel
)

# Only prepare test/install/package targets if we're not a submodule
if(REALM_CORE_SUBMODULE_BUILD)
return()
Expand Down Expand Up @@ -400,39 +423,6 @@ if (REALM_BUILD_TEST_CLIENT)
add_subdirectory(test/client)
endif()

# Make the project importable from the build directory
set(REALM_EXPORTED_TARGETS
Storage
QueryParser
ObjectStore
RealmFFI
RealmFFIStatic
)
if(REALM_ENABLE_SYNC)
list(APPEND REALM_EXPORTED_TARGETS Sync)
endif()
export(TARGETS ${REALM_EXPORTED_TARGETS} NAMESPACE Realm:: FILE RealmTargets.cmake)
configure_file(tools/cmake/RealmConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/RealmConfig.cmake @ONLY)
configure_file(tools/cmake/AcquireRealmDependency.cmake ${CMAKE_CURRENT_BINARY_DIR}/AcquireRealmDependency.cmake @ONLY)

# Make the project importable from the install directory
install(EXPORT realm
NAMESPACE Realm::
FILE RealmTargets.cmake
DESTINATION lib/cmake/Realm
COMPONENT devel
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/RealmConfig.cmake
DESTINATION lib/cmake/Realm
COMPONENT devel
)

install(FILES tools/cmake/AcquireRealmDependency.cmake
DESTINATION lib/cmake/Realm
COMPONENT devel
)

# CPack
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_VERSION ${REALM_VERSION})
Expand Down
10 changes: 8 additions & 2 deletions src/realm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,14 @@ endif()

target_link_libraries(Storage INTERFACE Threads::Threads)

if(TARGET Backtrace::Backtrace)
target_link_libraries(Storage PUBLIC Backtrace::Backtrace)
if(REALM_HAVE_BACKTRACE AND NOT CMAKE_GENERATOR STREQUAL Xcode)
# Apple platforms always have backtrace. We disregard the `Backtrace_*` variables
# because their paths are hardcoded to one SDK within Xcode (e.g. macosx),
# whereas we build for several different SDKs and thus we can't use the include path from one in the other.
# Otherwise if CMake found that the backtrace facility is provided by an external library and not built-in
# we need to configure the interface target with the library include and link path.
target_include_directories(Storage PRIVATE ${Backtrace_INCLUDE_DIRS})
target_link_libraries(Storage PUBLIC ${Backtrace_LIBRARIES})
endif()

if(REALM_ENABLE_ENCRYPTION AND UNIX AND NOT APPLE AND REALM_HAVE_OPENSSL)
Expand Down
11 changes: 6 additions & 5 deletions tools/cmake/RealmConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ include("${CMAKE_CURRENT_LIST_DIR}/AcquireRealmDependency.cmake")
include(CMakeFindDependencyMacro)

if(@REALM_HAVE_OPENSSL@)
if(NOT REALM_USE_SYSTEM_OPENSSL AND (ANDROID OR WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux"))
if(NOT @REALM_USE_SYSTEM_OPENSSL@ AND (ANDROID OR WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux"))
# Use our own prebuilt OpenSSL
realm_acquire_dependency(openssl @OPENSSL_VERSION@ OPENSSL_CMAKE_INCLUDE_FILE)

include(${OPENSSL_CMAKE_INCLUDE_FILE})
endif()

set(OPENSSL_USE_STATIC_LIBS ON)
find_dependency(OpenSSL @OPENSSL_VERSION@)
endif()

Expand All @@ -25,8 +23,11 @@ find_dependency(Threads)
# Just use -lz and let Xcode figure it out
if(TARGET Realm::Sync AND NOT APPLE AND NOT TARGET ZLIB::ZLIB)
if(WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND REALM_LINUX_TOOLCHAIN))
realm_acquire_dependency(zlib @DEP_ZLIB_VERSION@ ZLIB_CMAKE_INCLUDE_FILE)
include(${ZLIB_CMAKE_INCLUDE_FILE})
find_package(ZLIB)
if (NOT ZLIB_FOUND)
realm_acquire_dependency(zlib @DEP_ZLIB_VERSION@ ZLIB_CMAKE_INCLUDE_FILE)
include(${ZLIB_CMAKE_INCLUDE_FILE})
endif()
elseif(ANDROID)
# On Android FindZLIB chooses the static libz over the dynamic one, but this leads to issues
# (see https://github.com/android/ndk/issues/1179)
Expand Down
Loading