Skip to content

Commit

Permalink
Modify CMakeLists for vcpkg portfile (#7603)
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire authored Apr 19, 2024
1 parent 5046288 commit 12d53fc
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "external/catch"]
path = external/catch
url = https://github.com/catchorg/Catch2.git
[submodule "src/external/sha-1"]
path = src/external/sha-1
url = https://github.com/clibs/sha1.git
[submodule "src/external/sha-2"]
path = src/external/sha-2
url = https://github.com/kalven/sha-2.git
[submodule "test/external/catch"]
path = test/external/catch
url = https://github.com/catchorg/Catch2.git
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
* The ownership relationship between App and User has changed. User now strongly retains App and App has a weak cache of Users. This means that creating a SyncConfig or opening a Realm will keep the parent App alive, rather than things being in a broken state if the App is deallocated. ([PR #7300](https://github.com/realm/realm-core/pull/7300).
* A new CMake define `REALM_APP_SERVICES` can be used to compile out core's default implmentation of the application services. ([#7268](https://github.com/realm/realm-core/issues/7268))
* Fix a race condition in Promise which could result in an assertion failure if it was destroyed immediately after a `get()` on the Future returned. The problematic scenario only occurred in test code and not in library code ([PR #7602](https://github.com/realm/realm-core/pull/7602)).
* Catch2 is no longer required as a submodule if the `REALM_NO_TESTS` flag is set.
* Sha-2 is no longer required as a submodule on Windows if linking with OpenSSL.
* The Catch2 submodule has moved to `test/external/catch`.

----------------------------------------------

Expand Down
23 changes: 5 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -400,27 +400,14 @@ install(FILES tools/cmake/AcquireRealmDependency.cmake
COMPONENT devel
)

if(CMAKE_SYSTEM_NAME MATCHES "^Windows")
# Increase the Catch2 virtual console width because our test names can be very long and they break test reports
set(CATCH_CONFIG_CONSOLE_WIDTH 300)
elseif(APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CATCH_CONFIG_NO_POSIX_SIGNALS ON CACHE BOOL "Disable Catch support for POSIX signals on Apple platforms other than macOS")
if(REALM_BUILD_LIB_ONLY)
set(REALM_EXCLUDE_TESTS EXCLUDE_FROM_ALL)
endif()
set(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS ON CACHE BOOL "Enable Catch2's optional standard library stringmakers")

add_subdirectory(external EXCLUDE_FROM_ALL)

# Cmake does not let us easily set the deployment target per-target, but Catch2
# can use modern features because we only run tests on recent OS versions.
target_compile_definitions(Catch2 PRIVATE _LIBCPP_DISABLE_AVAILABILITY)

# Enable CTest and include unit tests
enable_testing()

if(REALM_BUILD_LIB_ONLY OR REALM_NO_TESTS)
set(REALM_EXCLUDE_TESTS EXCLUDE_FROM_ALL)
if (NOT REALM_NO_TESTS)
enable_testing()
add_subdirectory(test)
endif()
add_subdirectory(test ${REALM_EXCLUDE_TESTS})

if (REALM_BUILD_TEST_CLIENT)
add_subdirectory(test/client)
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,15 @@ let package = Package(
cxxSettings: (cxxSettings) as [CXXSetting]),
.target(
name: "Catch2Generated",
path: "external/generated",
path: "test/external/generated",
// this file was manually generated with catch v3.0.1
// and should be regenerated when catch is upgraded
resources: [.copy("catch2/catch_user_config.hpp")],
publicHeadersPath: "."),
.target(
name: "Catch2",
dependencies: ["Catch2Generated"],
path: "external/catch/src",
path: "test/external/catch/src",
exclude: [
"CMakeLists.txt",
"catch2/catch_user_config.hpp.in",
Expand Down
1 change: 1 addition & 0 deletions evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ tasks:
--ignore='build/external/**' \
--ignore='external/**' \
--ignore='src/external/**' \
--ignore='test/external/**' \
--ignore='src/realm/parser/generated/**' \
--ignore='test/large_tests/**' \
--excl-line='LCOV_EXCL_LINE|REALM_TERMINATE|REALM_UNREACHABLE' \
Expand Down
1 change: 0 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.15)

add_cxx_flag_if_supported(-Wno-unused-but-set-variable)
add_subdirectory(catch)
4 changes: 2 additions & 2 deletions src/realm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ endif()
# On systems without a built-in SHA-2 implementation (or one provided by a dependency)
# we need to bundle the public domain implementation.
# Note: This is also used on Windows because Windows lacks a native SHA224 hash needed for realm encryption
if(NOT APPLE AND NOT REALM_HAVE_OPENSSL OR WIN32)
if(NOT APPLE AND NOT REALM_HAVE_OPENSSL)
add_library(sha2 OBJECT ../external/sha-2/sha224.cpp ../external/sha-2/sha256.cpp)
target_include_directories(Storage PRIVATE ../external/sha-2)
target_sources(Storage PRIVATE $<TARGET_OBJECTS:sha2>)
Expand Down Expand Up @@ -387,7 +387,7 @@ if(REALM_HAVE_BACKTRACE AND NOT CMAKE_GENERATOR STREQUAL Xcode)
target_link_libraries(Storage PUBLIC ${Backtrace_LIBRARIES})
endif()

if(REALM_ENABLE_ENCRYPTION AND UNIX AND NOT APPLE AND REALM_HAVE_OPENSSL)
if(REALM_ENABLE_ENCRYPTION AND REALM_HAVE_OPENSSL AND (UNIX OR WIN32))
target_link_libraries(Storage PUBLIC OpenSSL::Crypto)
endif()

Expand Down
18 changes: 14 additions & 4 deletions src/realm/util/sha_crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@
#include <bcrypt.h>
#pragma comment(lib, "bcrypt.lib")
#define REALM_USE_BUNDLED_SHA2 1
#elif REALM_HAVE_OPENSSL
#elif !REALM_HAVE_OPENSSL
#include <sha1.h>
#define REALM_USE_BUNDLED_SHA2 1
#endif

/*
* OpenSSL can be used with Windows. If this is the case:
* The Sha-1 & Sha-2 submodules are no longer needed, so the
* REALM_USE_BUNDLED_SHA2 macro should be undefined.
* This is particularly relevant when integrating realm-core
* via vcpkg.
*/
#if REALM_HAVE_OPENSSL
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#else
#include <sha1.h>
#define REALM_USE_BUNDLED_SHA2 1
#undef REALM_USE_BUNDLED_SHA2
#endif

#ifdef REALM_USE_BUNDLED_SHA2
Expand Down
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ add_subdirectory(util)
add_custom_target(benchmarks)
add_subdirectory(object-store)

if(CMAKE_SYSTEM_NAME MATCHES "^Windows")
# Increase the Catch2 virtual console width because our test names can be very long and they break test reports
set(CATCH_CONFIG_CONSOLE_WIDTH 300)
elseif(APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CATCH_CONFIG_NO_POSIX_SIGNALS ON CACHE BOOL "Disable Catch support for POSIX signals on Apple platforms other than macOS")
endif()
set(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS ON CACHE BOOL "Enable Catch2's optional standard library stringmakers")
add_subdirectory(external/catch)

# Cmake does not let us easily set the deployment target per-target, but Catch2
# can use modern features because we only run tests on recent OS versions.
target_compile_definitions(Catch2 PRIVATE _LIBCPP_DISABLE_AVAILABILITY)

# AFL and LIBFUZZER not yet supported by Windows
if(NOT CMAKE_SYSTEM_NAME MATCHES "^Windows" AND NOT EMSCRIPTEN AND NOT ANDROID)
add_subdirectory(fuzzy)
Expand Down

0 comments on commit 12d53fc

Please sign in to comment.