Skip to content

Commit

Permalink
Also detect debug build, clarified instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmilke committed Nov 13, 2023
1 parent 3ee7876 commit 86ced4a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
26 changes: 25 additions & 1 deletion Source/ThirdParty/VtkLibrary/VtkLibrary.Build.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Fill out your copyright notice in the Description page of Project Settings.

using System;
using System.Diagnostics;
using System.IO;
using UnrealBuildTool;

Expand All @@ -12,6 +13,12 @@ public VtkLibrary(ReadOnlyTargetRules Target) : base(Target)

// If you want to load a debug build, specify here the Debug directory
var BuildDir = "Release";

if (!Directory.Exists(Path.Combine(ModuleDirectory, "Release")) && Directory.Exists(Path.Combine(ModuleDirectory, "Debug")))
{
Console.WriteLine("[VtkPlugin] Searched for Release folder but only found Debug, so chose Debug.");
BuildDir = "Debug";
}

// Load includes
PublicSystemIncludePaths.Add("$(ModuleDir)/Public");
Expand All @@ -23,7 +30,7 @@ public VtkLibrary(ReadOnlyTargetRules Target) : base(Target)
var dllSearchPath = Path.Combine(ModuleDirectory, BuildDir, "bin");

if (!Directory.Exists(libSearchPath) || !Directory.Exists(dllSearchPath))
Console.WriteLine("Did not find lib- or dll-path for VtkLibrary!");
Console.WriteLine("[VtkPlugin] Did not find lib- or dll-path for VtkLibrary!");

// Libs
foreach (var libPath in Directory.EnumerateFiles(libSearchPath, "*.lib" , SearchOption.AllDirectories))
Expand All @@ -47,7 +54,24 @@ public VtkLibrary(ReadOnlyTargetRules Target) : base(Target)

// This adds a runtime dependency & copies the dll from source path to destination path on build
RuntimeDependencies.Add(destPath, srcPath);
}

// DLLs
foreach (var filePath in Directory.EnumerateFiles(dllSearchPath, "*.pdb" , SearchOption.AllDirectories))
{
var dllName = Path.GetFileName(filePath);
var srcPath = Path.Combine("$(ModuleDir)", BuildDir, "bin", dllName);
var destPath = Path.Combine("$(BinaryOutputDir)", dllName);

// TODO: Investigate why we can't delayload VTK like this on Windows, uncomment if fix is found
// This prevents the dlls to be auto-loaded when the plugin is read
// and allows us to load them later in VtkPlugin.cpp during StartupModule.
// That allows us to load dlls from specific paths, which is not (easily) possible otherwise on Windows.
//PublicDelayLoadDLLs.Add(dllName);
//RuntimeDependencies.Add(srcPath);

// This adds a runtime dependency & copies the dll from source path to destination path on build
RuntimeDependencies.Add(destPath, srcPath);
}
}
else if (Target.Platform == UnrealTargetPlatform.Mac)
Expand Down
29 changes: 10 additions & 19 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## VTK Plugin for Unreal Engine 5+

**This branch is fully cross-compatible between Windows and Unix (Linux/Mac).** See "How" in the [Remarks on Linux/Mac](#remarks-on-linuxmac) section.

A plugin that links the [VTK Library](https://github.com/Kitware/VTK) to [Unreal Engine 5.3](https://docs.unrealengine.com/5.3/en-US/).

Currently, this plugin does the following:
Expand All @@ -14,21 +12,17 @@ Currently, this plugin does the following:
This plugin is quite verbose as it aims to be a foundation for implementing & testing VTK functionality in UE.
Check the Unreal Log for `[VtkPlugin]` to see what's happening (also valid for the blueprint functions).

### ✔️ Remarks on Windows

Delay-loading (which would be better practice) is currently disabled for Windows and all VTK dlls are instantly loaded.
This prevents module reloading.
### ⚠️ Remarks on Windows

### ✔️ Remarks on Linux/Mac
- Delay-loading (which would be better practice) is currently disabled and all VTK dlls are instantly loaded.
- This prevents module reloading.

Delay-loading is enabled on Unix-based systems and thus also module reloading (theoretically).
### ⚠️ Remarks on Linux/Mac

To achieve cross-compatibility of all VTK methods, the `VtkWrapper` module with [RTTI](https://en.wikipedia.org/wiki/Run-time_type_information) enabled was implemented to wrap all VTK-native code.
Each VTK functionality needs to be wrapped explicitly before it is exposed (e.g., to `VtkPlugin` which implements the blueprints).
This is needed, as contrary to Windows Unreal Engine on Unix is by default compiled without RTTI support (thoroughly discussed [here](https://forums.unrealengine.com/t/rtti-failed-compiling-when-enabled-for-4-23-linux/455083/22)).
Globally enabling RTTI on Unix is not (easily) done, so this approach orients the way the `OpenExrWrapper` is implemented as suggested [here](https://forums.unrealengine.com/t/rtti-failed-compiling-when-enabled-for-4-23-linux/455083/13).

⚠️ The provided `VtkWrapper` implementation is just an example and better solutions exist.
- Cross-compatibility only through an [RTTI](https://en.wikipedia.org/wiki/Run-time_type_information) enabled Wrapper module (`VtkWrapper`)
- Using PImpl pattern
- UE on Unix is per default compiled without RTTI and will clash with RTTI-functionality used in some VTK includes ([also discussed here](https://forums.unrealengine.com/t/rtti-failed-compiling-when-enabled-for-4-23-linux/455083/22))
- Wrapper modules also employed by Unreal, e.g., in the `OpenExrWrapper` ([see here](https://forums.unrealengine.com/t/rtti-failed-compiling-when-enabled-for-4-23-linux/455083/13))

## Installation

Expand All @@ -37,13 +31,13 @@ Globally enabling RTTI on Unix is not (easily) done, so this approach orients th
You can use the `[*.bat|*.sh|*.command]` installation scripts to download and build VTK for UE automatically.

By default it will do a `Release` build, but you can tell it to do a `Debug` build by starting it with `Debug` as a parameter.
**If you do a Debug build,** be aware to change the respective paths in your `VtkLibrary.Build.cs` and `VtkPlugin.cpp` to `Debug` as well.
**If you do a Debug build,** don't delete your build folder (`./Temporary`) at the end of the script. The `*.dll` files store the path to its debug symbols which remain there.

```powershell
# Release build
.\install_vtk_windows.bat
# Debug build
# Debug build (do not delete build folder at the end)
.\install_vtk_windows.bat debug
```

Expand All @@ -67,9 +61,6 @@ Alternatively, download & build the VTK library yourself and copy the files to t

For test data have a look at the VTKData repository (files here are referenced in the [official VTK examples](https://examples.vtk.org/site/Cxx)): https://github.com/open-cv/VTKData

If you are using Linux or Mac the scripts or configuration may not be fully functional.
Please consider a pull request if this is the case and you fix it. :-)

If there are linking errors with the VTK library, have a look in the `Source/ThirdParty/VtkLibrary` folder:
- Check if your VTK binaries are in the correct folder
- Check if your VTK includes are present
Expand Down

0 comments on commit 86ced4a

Please sign in to comment.