From 2c32ce22f6cb5822c70c423c34bca04210f47929 Mon Sep 17 00:00:00 2001 From: huruitao Date: Thu, 26 Jun 2025 16:30:24 +0800 Subject: [PATCH] Add the ohos macro to the cmakelist,cpp and h files for OpenHarmony cross compilation Signed-off-by: huruitao --- CMakeLists.txt | 4 ++-- src/realm/util/features.h | 6 +++++- src/realm/util/thread.cpp | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a693f1c8542..dbb47987c4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,13 +289,13 @@ 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) - if(CMAKE_SYSTEM_NAME MATCHES "^Windows|Linux|Android") + if(CMAKE_SYSTEM_NAME MATCHES "^Windows|Linux|Android|OHOS") set(REALM_NEEDS_OPENSSL TRUE) endif() if(REALM_NEEDS_OPENSSL OR REALM_FORCE_OPENSSL) option(REALM_INCLUDE_CERTS "Include a list of trust certificates in the build for OpenSSL certificate verification" ON) endif() -elseif(REALM_ENABLE_ENCRYPTION AND CMAKE_SYSTEM_NAME MATCHES "Linux|Android") + elseif(REALM_ENABLE_ENCRYPTION AND CMAKE_SYSTEM_NAME MATCHES "Linux|Android|OHOS") set(REALM_NEEDS_OPENSSL TRUE) endif() diff --git a/src/realm/util/features.h b/src/realm/util/features.h index 831ae320aaf..64c1cec6fbc 100644 --- a/src/realm/util/features.h +++ b/src/realm/util/features.h @@ -212,6 +212,10 @@ #if defined ANDROID || defined __ANDROID_API__ #define REALM_ANDROID 1 #define REALM_LINUX 0 +#elif defined __OHOS__ +#define REALM_ANDROID 0 +#define REALM_LINUX 0 +#define REALM_OHOS 1 #elif defined(__linux__) #define REALM_ANDROID 0 #define REALM_LINUX 1 @@ -275,7 +279,7 @@ #define REALM_APPLE_DEVICE 0 #endif -#if REALM_ANDROID || REALM_IOS || REALM_WATCHOS || REALM_TVOS || REALM_UWP +#if REALM_ANDROID || REALM_IOS || REALM_WATCHOS || REALM_TVOS || REALM_UWP || REALM_OHOS #define REALM_MOBILE 1 #else #define REALM_MOBILE 0 diff --git a/src/realm/util/thread.cpp b/src/realm/util/thread.cpp index 15fa7bd6791..157f6ec701f 100644 --- a/src/realm/util/thread.cpp +++ b/src/realm/util/thread.cpp @@ -45,14 +45,18 @@ #if _POSIX_THREADS >= 200809L #ifdef __GNU_LIBRARY__ #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 12 && !REALM_ANDROID +#ifndef REALM_OHOS #define REALM_HAVE_ROBUST_PTHREAD_MUTEX #endif +#endif #elif !REALM_ANDROID +#ifndef REALM_OHOS #define REALM_HAVE_ROBUST_PTHREAD_MUTEX #endif #endif #endif #endif +#endif using namespace realm;