From c0ec70780f8458badad7aaf409675ad5d421c714 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Fri, 26 Jan 2024 13:33:53 +0000 Subject: [PATCH 1/8] working state --- CMakeLists.txt | 70 ++++++++++++++++---------------- tools/cmake/RealmConfig.cmake.in | 14 +++++++ 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b67258aba8..17ec3d15ad3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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$<$:Debug>") + if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif() string(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() @@ -369,6 +371,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() @@ -400,39 +435,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}) diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index 14dc24a17dc..7bb37cebb01 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -19,6 +19,20 @@ endif() set(THREADS_PREFER_PTHREAD_FLAG ON) find_dependency(Threads) +if(@REALM_HAVE_BACKTRACE@) + find_dependency(Backtrace) + add_library(Backtrace::Backtrace INTERFACE IMPORTED) + if(Backtrace_LIBRARIES) + # 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() +endif() + # Use Zlib for Sync, but allow integrators to override it # Don't use find_library(ZLIB) on Apple platforms - it hardcodes the path per platform, # so for an iOS build it'll use the path from the Device plaform, which is an error on Simulator. From 9ed5a38ef1ce573a5ea6e7b376a3a83f1d3700fe Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Tue, 30 Jan 2024 15:07:33 +0000 Subject: [PATCH 2/8] modify cmake files --- CMakeLists.txt | 7 +++++-- tools/cmake/RealmConfig.cmake.in | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17ec3d15ad3..0d4ca39162f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -332,8 +332,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) diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index 7bb37cebb01..24485ad31bc 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -39,8 +39,11 @@ endif() # 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) From 821f83c883929c01ec8b1e528731dad984a5091c Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Tue, 30 Jan 2024 17:53:38 +0000 Subject: [PATCH 3/8] cleanup cmake files --- tools/cmake/RealmConfig.cmake.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index 24485ad31bc..e540b979f59 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -11,8 +11,9 @@ if(@REALM_HAVE_OPENSSL@) include(${OPENSSL_CMAKE_INCLUDE_FILE}) endif() - - set(OPENSSL_USE_STATIC_LIBS ON) + if(NOT DEFINED OPENSSL_USE_STATIC_LIBS) + set(OPENSSL_USE_STATIC_LIBS ON) + endif() find_dependency(OpenSSL @OPENSSL_VERSION@) endif() From 65e1dc9d75e0e46e8bb9fdcc67fe4d25f692b5c1 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Fri, 2 Feb 2024 18:35:55 +0000 Subject: [PATCH 4/8] Remove usage of OPENSSL_USE_STATIC_LIBS --- CMakeLists.txt | 3 --- tools/cmake/RealmConfig.cmake.in | 3 --- 2 files changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d4ca39162f..929edb364cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -315,9 +315,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}") diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index e540b979f59..eaa3378d395 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -11,9 +11,6 @@ if(@REALM_HAVE_OPENSSL@) include(${OPENSSL_CMAKE_INCLUDE_FILE}) endif() - if(NOT DEFINED OPENSSL_USE_STATIC_LIBS) - set(OPENSSL_USE_STATIC_LIBS ON) - endif() find_dependency(OpenSSL @OPENSSL_VERSION@) endif() From 50929ab7c375dd2b36951a60a66359e33d97df29 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Wed, 7 Feb 2024 16:18:30 +0000 Subject: [PATCH 5/8] Dont rely on cmake cache for openssl config --- tools/cmake/RealmConfig.cmake.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index eaa3378d395..0146479d905 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -5,7 +5,10 @@ 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")) +message(STATUS REALM_USE_SYSTEM_OPENSSL:${REALM_USE_SYSTEM_OPENSSL}) +message(STATUS CMAKE_SYSTEM_NAME:${CMAKE_SYSTEM_NAME}) + + 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) From 03f40b10e1ab6e6b05652d84754ad7cd0a294db0 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Sat, 10 Feb 2024 10:53:03 +0000 Subject: [PATCH 6/8] remove cmake debugging --- tools/cmake/RealmConfig.cmake.in | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index 0146479d905..5a0a97c6511 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -5,9 +5,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/AcquireRealmDependency.cmake") include(CMakeFindDependencyMacro) if(@REALM_HAVE_OPENSSL@) -message(STATUS REALM_USE_SYSTEM_OPENSSL:${REALM_USE_SYSTEM_OPENSSL}) -message(STATUS CMAKE_SYSTEM_NAME:${CMAKE_SYSTEM_NAME}) - 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) From 534fb2bbcfe8e1524009981ff47e97030a56d7a1 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Fri, 16 Feb 2024 17:31:06 +0000 Subject: [PATCH 7/8] Remove mention of backtrace --- src/realm/CMakeLists.txt | 3 ++- tools/cmake/RealmConfig.cmake.in | 14 -------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/realm/CMakeLists.txt b/src/realm/CMakeLists.txt index c9a51456b2e..da7523ea3ab 100644 --- a/src/realm/CMakeLists.txt +++ b/src/realm/CMakeLists.txt @@ -368,7 +368,8 @@ endif() target_link_libraries(Storage INTERFACE Threads::Threads) if(TARGET Backtrace::Backtrace) - target_link_libraries(Storage PUBLIC Backtrace::Backtrace) + target_include_directories(Storage INTERFACE ${Backtrace_INCLUDE_DIRS}) + target_link_libraries(Storage INTERFACE ${Backtrace_LIBRARIES}) endif() if(REALM_ENABLE_ENCRYPTION AND UNIX AND NOT APPLE AND REALM_HAVE_OPENSSL) diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index 5a0a97c6511..e418c869c99 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -17,20 +17,6 @@ endif() set(THREADS_PREFER_PTHREAD_FLAG ON) find_dependency(Threads) -if(@REALM_HAVE_BACKTRACE@) - find_dependency(Backtrace) - add_library(Backtrace::Backtrace INTERFACE IMPORTED) - if(Backtrace_LIBRARIES) - # 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() -endif() - # Use Zlib for Sync, but allow integrators to override it # Don't use find_library(ZLIB) on Apple platforms - it hardcodes the path per platform, # so for an iOS build it'll use the path from the Device plaform, which is an error on Simulator. From fbbf3d6f584d67c32a234c3892c0cf14baca2943 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Mon, 19 Feb 2024 15:33:53 +0100 Subject: [PATCH 8/8] Change backtrace definition --- CMakeLists.txt | 14 +------------- src/realm/CMakeLists.txt | 11 ++++++++--- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 929edb364cd..f1ee484c77b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,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) diff --git a/src/realm/CMakeLists.txt b/src/realm/CMakeLists.txt index da7523ea3ab..49274a5fe90 100644 --- a/src/realm/CMakeLists.txt +++ b/src/realm/CMakeLists.txt @@ -367,9 +367,14 @@ endif() target_link_libraries(Storage INTERFACE Threads::Threads) -if(TARGET Backtrace::Backtrace) - target_include_directories(Storage INTERFACE ${Backtrace_INCLUDE_DIRS}) - target_link_libraries(Storage INTERFACE ${Backtrace_LIBRARIES}) +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)