From ce8d717be2c6157e2f0842a20a4a4fa39349ff5c Mon Sep 17 00:00:00 2001 From: KamilGronek Date: Wed, 14 Aug 2024 12:03:06 +0200 Subject: [PATCH] Prepare build cs for mac --- .../PubnubLibrary/Private/PubnubLibrary.cpp | 19 +++++++- Source/PubnubLibrary/Public/PubnubLibrary.h | 1 + .../sdk/PubNubModule/PubNubModule.Build.cs | 46 ++++++++----------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Source/PubnubLibrary/Private/PubnubLibrary.cpp b/Source/PubnubLibrary/Private/PubnubLibrary.cpp index 35d57e2..ff4d3a1 100644 --- a/Source/PubnubLibrary/Private/PubnubLibrary.cpp +++ b/Source/PubnubLibrary/Private/PubnubLibrary.cpp @@ -2,18 +2,33 @@ #include "PubnubLibrary.h" #include "Core.h" -#include "Kismet/KismetSystemLibrary.h" +#include "Interfaces/IPluginManager.h" #define LOCTEXT_NAMESPACE "FPubnubLibraryModule" void FPubnubLibraryModule::StartupModule() { +#if PLATFORM_MAC + FString BaseDir = IPluginManager::Get().FindPlugin("PubnubChat")->GetBaseDir(); + FString LibraryPath; + LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/sdk/lib/macos/libpubnub-chat.dylib")); + + ChatSDKLibraryHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr; + + if (!ChatSDKLibraryHandle) + { + FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("ChatSDKModuleHandle", "Failed to load pubnub third party library")); + } +#endif } void FPubnubLibraryModule::ShutdownModule() { - +#if PLATFORM_MAC + FPlatformProcess::FreeDllHandle(ChatSDKLibraryHandle); + ChatSDKLibraryHandle = nullptr; +#endif } #undef LOCTEXT_NAMESPACE diff --git a/Source/PubnubLibrary/Public/PubnubLibrary.h b/Source/PubnubLibrary/Public/PubnubLibrary.h index 04c12e1..b8c13b6 100644 --- a/Source/PubnubLibrary/Public/PubnubLibrary.h +++ b/Source/PubnubLibrary/Public/PubnubLibrary.h @@ -13,4 +13,5 @@ class FPubnubLibraryModule : public IModuleInterface virtual void StartupModule() override; virtual void ShutdownModule() override; + void* PubnubLibraryHandle; }; diff --git a/Source/ThirdParty/sdk/PubNubModule/PubNubModule.Build.cs b/Source/ThirdParty/sdk/PubNubModule/PubNubModule.Build.cs index f389cfc..3c5ff95 100644 --- a/Source/ThirdParty/sdk/PubNubModule/PubNubModule.Build.cs +++ b/Source/ThirdParty/sdk/PubNubModule/PubNubModule.Build.cs @@ -13,39 +13,29 @@ public PubNubModule(ReadOnlyTargetRules Target) : base(Target) { Type = ModuleType.External; - string extention = null; - string PlatformLib = null; - string binary = null; - string buildLocation = null; - if(Target.Platform == UnrealTargetPlatform.Win64) - { - extention = StaticLink ? "lib" : "dll"; - PlatformLib = OpenSsl ? "openssl" : "windows"; - binary = $"pubnub.{extention}"; - buildLocation = "Lib/win64"; - } - else if(Target.Platform == UnrealTargetPlatform.Mac) - { - extention = StaticLink ? "a" : "dylib"; - PlatformLib = OpenSsl ? "openssl" : "posix"; - binary = $"libpubnub.{extention}"; - buildLocation = "Lib/MacOS"; - } - else - { - extention = StaticLink ? "a" : "so"; - PlatformLib = OpenSsl ? "openssl" : "posix"; - binary = $"libpubnub.{extention}"; - buildLocation = "Lib/Linux"; - } - - if (OpenSsl) { + if (OpenSsl) { PublicDependencyModuleNames.AddRange(new string[] { "OpenSSL" }); } var SDKPath = Path.Combine(new string[] { ModuleDirectory, ".." }); + + + + if (Target.Platform == UnrealTargetPlatform.Win64) + { + string BuildLocation = "Lib/win64"; + PublicAdditionalLibraries.Add(Path.Combine(SDKPath, BuildLocation, "pubnub.lib")); + + } + else if(Target.Platform == UnrealTargetPlatform.Mac) + { + PublicDelayLoadDLLs.Add(Path.Combine(SDKPath, "lib", "macos", "libpubnub.dylib")); + RuntimeDependencies.Add("$(PluginDir)/Source/ThirdParty/sdk/lib/macos/libpubnub.dylib"); + } + + string PlatformLib = "openssl"; + - PublicAdditionalLibraries.Add(Path.Combine(SDKPath, buildLocation, binary)); PublicIncludePaths.AddRange( new string[] { SDKPath,