Add support for building engine target as shared library on all platforms

This commit is contained in:
Wojtek Figat
2023-11-15 22:56:23 +01:00
parent 80a30f504a
commit ee6a311406
7 changed files with 42 additions and 15 deletions

View File

@@ -25,8 +25,6 @@ extern "C" {
__declspec(dllexport) int32 AmdPowerXpressRequestHighPerformance = 1;
}
extern LONG CALLBACK SehExceptionHandler(EXCEPTION_POINTERS* ep);
#if FLAX_TESTS
int main(int argc, char* argv[])
#else
@@ -54,7 +52,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd
{
return Engine::Main(lpCmdLine);
}
__except (SehExceptionHandler(GetExceptionInformation()))
__except (Platform::SehExceptionHandler(GetExceptionInformation()))
{
return -1;
}

View File

@@ -88,10 +88,6 @@ bool Win32Thread::Start(uint32 stackSize)
return false;
}
#if PLATFORM_WINDOWS
extern LONG CALLBACK SehExceptionHandler(EXCEPTION_POINTERS* ep);
#endif
unsigned long Win32Thread::ThreadProc(void* pThis)
{
auto thread = (Win32Thread*)pThis;
@@ -103,7 +99,7 @@ unsigned long Win32Thread::ThreadProc(void* pThis)
return static_cast<unsigned long>(exitCode);
}
#if PLATFORM_WINDOWS
__except (SehExceptionHandler(GetExceptionInformation()))
__except (Platform::SehExceptionHandler(GetExceptionInformation()))
{
return -1;
}

View File

@@ -273,7 +273,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LONG CALLBACK SehExceptionHandler(EXCEPTION_POINTERS* ep)
long __stdcall WindowsPlatform::SehExceptionHandler(EXCEPTION_POINTERS* ep)
{
if (ep->ExceptionRecord->ExceptionCode == CLR_EXCEPTION)
{

View File

@@ -23,6 +23,9 @@ public:
/// </summary>
static void* Instance;
// Native exceptions handling function.
static long __stdcall SehExceptionHandler(struct _EXCEPTION_POINTERS* ep);
public:
/// <summary>

View File

@@ -281,6 +281,10 @@ bool MCore::LoadEngine()
flaxLibraryPath = ::String(StringUtils::GetDirectoryName(Platform::GetExecutableFilePath())) / StringUtils::GetFileName(flaxLibraryPath);
}
#endif
if (!FileSystem::FileExists(flaxLibraryPath))
{
LOG(Error, "Flax Engine native library file is missing ({0})", flaxLibraryPath);
}
RegisterNativeLibrary("FlaxEngine", flaxLibraryPath.Get());
MRootDomain = New<MDomain>("Root");

View File

@@ -43,7 +43,7 @@ public class Scripting : EngineModule
if (options.Target is EngineTarget engineTarget && engineTarget.UseSeparateMainExecutable(options))
{
// Build target doesn't support linking again main executable (eg. Linux) thus additional shared library is used for the engine (eg. libFlaxEditor.so)
var fileName = options.Platform.GetLinkOutputFileName(engineTarget.OutputName, LinkerOutput.SharedLibrary);
var fileName = options.Platform.GetLinkOutputFileName(EngineTarget.LibraryName, LinkerOutput.SharedLibrary);
options.CompileEnv.PreprocessorDefinitions.Add("MCORE_MAIN_MODULE_NAME=" + fileName);
}
}