Skip to content

Commit 48dac32

Browse files
authored
[src] Update plugin config files to be able to link and load Release or Debug version of SOFA. Add scripts to copy libs (#26)
* Add script to sync libraries * Update script to allow release or debug option * Update plugin config files to allow full debug build linking with debug version of SOFA
1 parent edcfb3c commit 48dac32

3 files changed

Lines changed: 128 additions & 8 deletions

File tree

Content/Scripts/copySOFALibs.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
import shutil
3+
import sys
4+
5+
# List of subpaths to sync (relative to sofa_path/sofaUE_path)
6+
SUBPATHS = [
7+
"thirdparty/lib",
8+
"bin/Release",
9+
]
10+
11+
def sync_folder(src, dst):
12+
"""
13+
Copy contents of src into dst.
14+
Overwrites files in dst if they already exist.
15+
Creates directories as needed.
16+
"""
17+
for dirpath, _, filenames in os.walk(src):
18+
rel_path = os.path.relpath(dirpath, src)
19+
target_dir = os.path.join(dst, rel_path)
20+
21+
os.makedirs(target_dir, exist_ok=True)
22+
23+
for filename in filenames:
24+
src_file = os.path.join(dirpath, filename)
25+
dst_file = os.path.join(target_dir, filename)
26+
shutil.copy2(src_file, dst_file)
27+
print(f"Copied {src_file} -> {dst_file}")
28+
29+
30+
if __name__ == "__main__":
31+
if len(sys.argv) < 3:
32+
print("Usage: python copySOFALibs.py SOFA_BUILD_PATH SOFAUE5_PLUGIN_PATH Debug_Mode(optional)")
33+
sys.exit(1)
34+
35+
sofa_path, sofaUE_path = sys.argv[1], sys.argv[2]
36+
37+
debugMode = False
38+
if len(sys.argv) == 4:
39+
debugMode = sys.argv[3]
40+
41+
#sofa_path = "C:\projects\sofa-build\"
42+
#sofaUE_path = "C:\projects\UE5\SofaIntegration\Plugins\SofaUE5\"
43+
44+
if not os.path.isdir(sofa_path):
45+
print(f"Error: {sofa_path} is not a valid directory")
46+
sys.exit(1)
47+
48+
#os.makedirs(sofaUE_path, exist_ok=True)
49+
50+
# first copy dll
51+
if (debugMode):
52+
srcPath = os.path.join(sofa_path, "bin/Debug/")
53+
dstPath = os.path.join(sofaUE_path, "Binaries/ThirdParty/SofaUE5Library/Win64/Debug/")
54+
else:
55+
srcPath = os.path.join(sofa_path, "bin/Release/")
56+
dstPath = os.path.join(sofaUE_path, "Binaries/ThirdParty/SofaUE5Library/Win64/Release/")
57+
58+
print(f"Syncing {srcPath} -> {dstPath}")
59+
60+
if not os.path.exists(srcPath):
61+
print(f"Warning: {srcPath} does not exist, skipping")
62+
63+
sync_folder(srcPath, dstPath)
64+
65+
66+
# copy lib
67+
if (debugMode):
68+
srcPath = os.path.join(sofa_path, "lib/Debug/")
69+
dstPath = os.path.join(sofaUE_path, "Source/ThirdParty/SofaUE5Library/x64/Debug/")
70+
else:
71+
srcPath = os.path.join(sofa_path, "lib/Release/")
72+
dstPath = os.path.join(sofaUE_path, "Source/ThirdParty/SofaUE5Library/x64/Release/")
73+
74+
print(f"Syncing {srcPath} -> {dstPath}")
75+
76+
if not os.path.exists(srcPath):
77+
print(f"Warning: {srcPath} does not exist, skipping")
78+
79+
sync_folder(srcPath, dstPath)
80+
81+
82+
print("All selected folders synced ✅")

Source/SofaUE5/Private/SofaUE5.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,22 @@ void FSofaUE5Module::StartupModule()
4242
// Get the base directory of this plugin
4343
FString BaseDir = IPluginManager::Get().FindPlugin("SofaUE5")->GetBaseDir();
4444

45+
bool debugMode = false;
46+
47+
#if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT) && !UE_BUILD_SHIPPING
48+
debugMode = true;
49+
#endif
50+
4551
// Add on the relative location of the third party dll and load it
4652
FString LibraryPath;
53+
4754
#if PLATFORM_WINDOWS
48-
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SofaUE5Library/Win64/SofaVerseAPI.dll"));
55+
//LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SofaUE5Library/Win64/SofaVerseAPI.dll"));
56+
if (debugMode)
57+
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SofaUE5Library/Win64/Debug/SofaVerseAPI_d.dll"));
58+
else
59+
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SofaUE5Library/Win64/Release/SofaVerseAPI.dll"));
60+
4961
#elif PLATFORM_MAC
5062
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/SofaUE5Library/Mac/Release/libSofaVerseAPI.dylib"));
5163
#elif PLATFORM_LINUX
@@ -66,7 +78,11 @@ void FSofaUE5Module::StartupModule()
6678
return;
6779
}
6880

69-
FPlatformProcess::AddDllDirectory(*FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SofaUE5Library/Win64/")));
81+
if (debugMode)
82+
FPlatformProcess::AddDllDirectory(*FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SofaUE5Library/Win64/Debug/")));
83+
else
84+
FPlatformProcess::AddDllDirectory(*FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SofaUE5Library/Win64/Release/")));
85+
7086
ExampleLibraryHandle = FPlatformProcess::GetDllHandle(*LibraryPath);
7187

7288
if (ExampleLibraryHandle)

Source/ThirdParty/SofaUE5Library/SofaUE5Library.Build.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,38 @@ public SofaUE5Library(ReadOnlyTargetRules Target) : base(Target)
1212
if (Target.Platform == UnrealTargetPlatform.Win64)
1313
{
1414
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));
15+
PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private"));
16+
17+
string SofaLibPath;
18+
string SofaBinName;
19+
string SofaBinPath;
20+
21+
// Debug mode
22+
if (Target.Configuration == UnrealTargetConfiguration.Debug || Target.Configuration == UnrealTargetConfiguration.DebugGame)
23+
{
24+
SofaLibPath = Path.Combine(ModuleDirectory, "x64", "Debug", "SofaVerseAPI_d.lib");
25+
SofaBinName = "SofaVerseAPI_d.dll";
26+
SofaBinPath = Path.Combine("$(PluginDir)/Binaries/ThirdParty/SofaUE5Library/Win64/", "Debug", SofaBinName);
27+
28+
PublicDefinitions.Add("WITH_SOFA_DEBUG=1");
29+
}
30+
else
31+
{
32+
SofaLibPath = Path.Combine(ModuleDirectory, "x64", "Release", "SofaVerseAPI.lib");
33+
SofaBinName = "SofaVerseAPI.dll";
34+
SofaBinPath = Path.Combine("$(PluginDir)/Binaries/ThirdParty/SofaUE5Library/Win64/", "Release", SofaBinName);
35+
}
1536

1637
// Add the import library
17-
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "x64", "Release", "SofaVerseAPI.lib"));
38+
PublicAdditionalLibraries.Add(SofaLibPath);
1839

19-
// Delay-load the DLL, so we can load it from the right place first
20-
PublicDelayLoadDLLs.Add("SofaVerseAPI.dll");
40+
// Delay-load the DLL, so we can load it from the right place first
41+
PublicDelayLoadDLLs.Add(SofaBinName);
2142

22-
// Ensure that the DLL is staged along with the executable
23-
RuntimeDependencies.Add("$(PluginDir)/Binaries/ThirdParty/SofaUE5Library/Win64/SofaVerseAPI.dll");
24-
}
43+
// Ensure that the DLL is staged along with the executable
44+
RuntimeDependencies.Add(SofaBinPath);
45+
//RuntimeDependencies.Add("$(PluginDir)/Binaries/ThirdParty/SofaUE5Library/Win64/SofaPhysicsAPI.dll");
46+
}
2547
else if (Target.Platform == UnrealTargetPlatform.Mac)
2648
{
2749
//PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "Mac", "Release", "libExampleLibrary.dylib"));

0 commit comments

Comments
 (0)