Skip to content

Commit 12d53fc

Browse files
authored
Modify CMakeLists for vcpkg portfile (#7603)
1 parent 5046288 commit 12d53fc

File tree

11 files changed

+43
-30
lines changed

11 files changed

+43
-30
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
[submodule "external/catch"]
2-
path = external/catch
3-
url = https://github.com/catchorg/Catch2.git
41
[submodule "src/external/sha-1"]
52
path = src/external/sha-1
63
url = https://github.com/clibs/sha1.git
74
[submodule "src/external/sha-2"]
85
path = src/external/sha-2
96
url = https://github.com/kalven/sha-2.git
7+
[submodule "test/external/catch"]
8+
path = test/external/catch
9+
url = https://github.com/catchorg/Catch2.git

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
* 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).
5050
* 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))
5151
* 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)).
52+
* Catch2 is no longer required as a submodule if the `REALM_NO_TESTS` flag is set.
53+
* Sha-2 is no longer required as a submodule on Windows if linking with OpenSSL.
54+
* The Catch2 submodule has moved to `test/external/catch`.
5255

5356
----------------------------------------------
5457

CMakeLists.txt

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -400,27 +400,14 @@ install(FILES tools/cmake/AcquireRealmDependency.cmake
400400
COMPONENT devel
401401
)
402402

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

413-
# Cmake does not let us easily set the deployment target per-target, but Catch2
414-
# can use modern features because we only run tests on recent OS versions.
415-
target_compile_definitions(Catch2 PRIVATE _LIBCPP_DISABLE_AVAILABILITY)
416-
417-
# Enable CTest and include unit tests
418-
enable_testing()
419-
420-
if(REALM_BUILD_LIB_ONLY OR REALM_NO_TESTS)
421-
set(REALM_EXCLUDE_TESTS EXCLUDE_FROM_ALL)
407+
if (NOT REALM_NO_TESTS)
408+
enable_testing()
409+
add_subdirectory(test)
422410
endif()
423-
add_subdirectory(test ${REALM_EXCLUDE_TESTS})
424411

425412
if (REALM_BUILD_TEST_CLIENT)
426413
add_subdirectory(test/client)

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,15 @@ let package = Package(
498498
cxxSettings: (cxxSettings) as [CXXSetting]),
499499
.target(
500500
name: "Catch2Generated",
501-
path: "external/generated",
501+
path: "test/external/generated",
502502
// this file was manually generated with catch v3.0.1
503503
// and should be regenerated when catch is upgraded
504504
resources: [.copy("catch2/catch_user_config.hpp")],
505505
publicHeadersPath: "."),
506506
.target(
507507
name: "Catch2",
508508
dependencies: ["Catch2Generated"],
509-
path: "external/catch/src",
509+
path: "test/external/catch/src",
510510
exclude: [
511511
"CMakeLists.txt",
512512
"catch2/catch_user_config.hpp.in",

evergreen/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@ tasks:
10961096
--ignore='build/external/**' \
10971097
--ignore='external/**' \
10981098
--ignore='src/external/**' \
1099+
--ignore='test/external/**' \
10991100
--ignore='src/realm/parser/generated/**' \
11001101
--ignore='test/large_tests/**' \
11011102
--excl-line='LCOV_EXCL_LINE|REALM_TERMINATE|REALM_UNREACHABLE' \

external/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
cmake_minimum_required(VERSION 3.15)
22

33
add_cxx_flag_if_supported(-Wno-unused-but-set-variable)
4-
add_subdirectory(catch)

src/realm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ endif()
352352
# On systems without a built-in SHA-2 implementation (or one provided by a dependency)
353353
# we need to bundle the public domain implementation.
354354
# Note: This is also used on Windows because Windows lacks a native SHA224 hash needed for realm encryption
355-
if(NOT APPLE AND NOT REALM_HAVE_OPENSSL OR WIN32)
355+
if(NOT APPLE AND NOT REALM_HAVE_OPENSSL)
356356
add_library(sha2 OBJECT ../external/sha-2/sha224.cpp ../external/sha-2/sha256.cpp)
357357
target_include_directories(Storage PRIVATE ../external/sha-2)
358358
target_sources(Storage PRIVATE $<TARGET_OBJECTS:sha2>)
@@ -387,7 +387,7 @@ if(REALM_HAVE_BACKTRACE AND NOT CMAKE_GENERATOR STREQUAL Xcode)
387387
target_link_libraries(Storage PUBLIC ${Backtrace_LIBRARIES})
388388
endif()
389389

390-
if(REALM_ENABLE_ENCRYPTION AND UNIX AND NOT APPLE AND REALM_HAVE_OPENSSL)
390+
if(REALM_ENABLE_ENCRYPTION AND REALM_HAVE_OPENSSL AND (UNIX OR WIN32))
391391
target_link_libraries(Storage PUBLIC OpenSSL::Crypto)
392392
endif()
393393

src/realm/util/sha_crypto.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@
2828
#include <bcrypt.h>
2929
#pragma comment(lib, "bcrypt.lib")
3030
#define REALM_USE_BUNDLED_SHA2 1
31-
#elif REALM_HAVE_OPENSSL
31+
#elif !REALM_HAVE_OPENSSL
32+
#include <sha1.h>
33+
#define REALM_USE_BUNDLED_SHA2 1
34+
#endif
35+
36+
/*
37+
* OpenSSL can be used with Windows. If this is the case:
38+
* The Sha-1 & Sha-2 submodules are no longer needed, so the
39+
* REALM_USE_BUNDLED_SHA2 macro should be undefined.
40+
* This is particularly relevant when integrating realm-core
41+
* via vcpkg.
42+
*/
43+
#if REALM_HAVE_OPENSSL
3244
#include <openssl/sha.h>
3345
#include <openssl/evp.h>
3446
#include <openssl/hmac.h>
35-
#else
36-
#include <sha1.h>
37-
#define REALM_USE_BUNDLED_SHA2 1
47+
#undef REALM_USE_BUNDLED_SHA2
3848
#endif
3949

4050
#ifdef REALM_USE_BUNDLED_SHA2

test/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ add_subdirectory(util)
22
add_custom_target(benchmarks)
33
add_subdirectory(object-store)
44

5+
if(CMAKE_SYSTEM_NAME MATCHES "^Windows")
6+
# Increase the Catch2 virtual console width because our test names can be very long and they break test reports
7+
set(CATCH_CONFIG_CONSOLE_WIDTH 300)
8+
elseif(APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
9+
set(CATCH_CONFIG_NO_POSIX_SIGNALS ON CACHE BOOL "Disable Catch support for POSIX signals on Apple platforms other than macOS")
10+
endif()
11+
set(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS ON CACHE BOOL "Enable Catch2's optional standard library stringmakers")
12+
add_subdirectory(external/catch)
13+
14+
# Cmake does not let us easily set the deployment target per-target, but Catch2
15+
# can use modern features because we only run tests on recent OS versions.
16+
target_compile_definitions(Catch2 PRIVATE _LIBCPP_DISABLE_AVAILABILITY)
17+
518
# AFL and LIBFUZZER not yet supported by Windows
619
if(NOT CMAKE_SYSTEM_NAME MATCHES "^Windows" AND NOT EMSCRIPTEN AND NOT ANDROID)
720
add_subdirectory(fuzzy)

0 commit comments

Comments
 (0)