Skip to content

Commit 8bebb68

Browse files
committed
Building and packaging Win32 and Win64 builds of UModel
- SDL2.dll is no longer copied next to umodel.exe, it is picked up from libs during development, using delay-loading tech - package_win32.sh script builds Win32 and Win64 targets and packages executables alongside with SDL2 dlls - Separated SDL2 logic from common.project to SDL2.project - Replaced appMilliseconds implementation from SDL_GetTicks to GetTickCount, so running in command line mode will no longer require SDL2.dll
1 parent 912d691 commit 8bebb68

File tree

9 files changed

+105
-39
lines changed

9 files changed

+105
-39
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ umodel.cfg
3333
# Executable files and pdb
3434
umodel[-_]*.exe
3535
umodel*.pdb
36-
SDL2.dll
3736
Tools/**/*.exe
3837
Tools/**/*.pdb
3938
*todo.md

Core/Core.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -637,21 +637,17 @@ extern bool GUseDebugger;
637637
#endif
638638

639639

640-
#if RENDERING
641-
# define appMilliseconds() SDL_GetTicks()
642-
#else
643-
# ifdef _WIN32
644-
# if !defined(WINAPI) // detect <windows.h>
645-
extern "C" {
646-
__declspec(dllimport) unsigned long __stdcall GetTickCount();
647-
}
648-
# endif
649-
# else
650-
// Local implementation of GetTickCount() for non-Windows platforms
651-
unsigned long GetTickCount();
640+
#ifdef _WIN32
641+
# if !defined(WINAPI) // detect <windows.h>
642+
extern "C" {
643+
__declspec(dllimport) unsigned long __stdcall GetTickCount();
644+
}
652645
# endif
653-
# define appMilliseconds() GetTickCount()
654-
#endif // RENDERING
646+
#else
647+
// Local implementation of GetTickCount() for non-Windows platforms
648+
unsigned long GetTickCount();
649+
#endif
650+
#define appMilliseconds() GetTickCount()
655651

656652
// Allow operation of enum class as with regular integer
657653
#define BITFIELD_ENUM(Enum) \

build.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,8 @@ GenerateMakefile
251251
# Perform a build
252252
# if $target is empty, whole project will be built, otherwise a single file
253253
case "$PLATFORM" in
254-
"vc-win32")
254+
"vc-win32"|"vc-win64")
255255
Make $makefile $target || exit 1
256-
[ $render -eq 1 ] && cp $root/libs/SDL2/x86/SDL2.dll .
257-
;;
258-
"vc-win64")
259-
Make $makefile $target || exit 1
260-
[ $render -eq 1 ] && cp $root/libs/SDL2/x64/SDL2.dll .
261256
;;
262257
"mingw32"|"cygwin")
263258
PATH=/bin:/usr/bin:$PATH # configure paths for Cygwin

common.project

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ sources(COMP_LIBS) = {
166166
pop(INCLUDES)
167167
pop(DEFINES)
168168

169+
# SDL2
170+
!include $R/libs/SDL2/SDL2.project
171+
169172
# oodle SDK support
170173
!include $R/libs/oodle/oodle.project
171174

@@ -192,9 +195,6 @@ sources(UE4_LIBS) = {
192195
#------------------------------------------------
193196

194197
OBJDIR = $R/obj/$PRJ-$PLATFORM
195-
!if "$PLATFORM" ne "osx"
196-
STDLIBS += SDL2 # disabled in macOS build
197-
!endif
198198
INCLUDES += . $R/Core $R/Unreal $LIBINCLUDES
199199
OPTIONS += $WARNINGS
200200

@@ -212,11 +212,3 @@ OPTIONS += $WARNINGS
212212
libs/tracy/TracyClient.cpp
213213
}
214214
!endif
215-
216-
!if "$PLATFORM" eq "win32"
217-
INCLUDES += $R/libs/includewin32
218-
LIBRARIES += $R/libs/SDL2/x86
219-
!elif "$PLATFORM" eq "win64"
220-
INCLUDES += $R/libs/includewin32
221-
LIBRARIES += $R/libs/SDL2/x64
222-
!endif

libs/SDL2/SDL2.project

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# perl highlighting
2+
3+
!if "$PLATFORM" ne "osx"
4+
STDLIBS += SDL2 # disabled in macOS build
5+
!endif
6+
7+
!if "$PLATFORM" eq "win32"
8+
INCLUDES += $R/libs/includewin32
9+
LIBRARIES += $R/libs/SDL2/x86
10+
!elif "$PLATFORM" eq "win64"
11+
INCLUDES += $R/libs/includewin32
12+
LIBRARIES += $R/libs/SDL2/x64
13+
!endif
14+
15+
!if "$COMPILER" eq "VisualC"
16+
# Delay loading of SDL2.dll
17+
LINKFLAGS += -DELAYLOAD:SDL2.dll
18+
STDLIBS += delayimp
19+
# Delay loader helper function
20+
sources(MAIN) = $R/libs/SDL2/SDL2Loader.cpp
21+
!endif

libs/SDL2/SDL2Loader.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <windows.h>
2+
#include <delayimp.h>
3+
4+
// Reference:
5+
// https://docs.microsoft.com/en-us/cpp/build/reference/understanding-the-helper-function
6+
7+
// Core external functions
8+
void appPrintf(const char*, ...);
9+
void appError(const char*, ...);
10+
11+
static const char* DllPaths[] =
12+
{
13+
#ifndef _WIN64
14+
"SDL2.dll",
15+
"libs\\SDL2\\x86\\SDL2.dll"
16+
#else
17+
"SDL2_64.dll",
18+
"libs\\SDL2\\x64\\SDL2.dll"
19+
#endif
20+
};
21+
22+
static FARPROC WINAPI delayHook(unsigned dliNotify, PDelayLoadInfo pdli)
23+
{
24+
if (dliNotify == dliNotePreLoadLibrary)
25+
{
26+
if (stricmp(pdli->szDll, "SDL2.dll") == 0)
27+
{
28+
// Find SDL2.dll in local folder, then in libs. Use a different file name for Win64 builds.
29+
for (const char* DllName : DllPaths)
30+
{
31+
HANDLE hDll = LoadLibrary(DllName);
32+
if (hDll)
33+
return (FARPROC) hDll;
34+
}
35+
appError("SDL2.dll was not found, terminating...");
36+
}
37+
else
38+
{
39+
// Actually can simply return NULL, and let CRT to find a DLL itself
40+
appError("Unknown DelayLoad: %s", pdli->szDll);
41+
}
42+
}
43+
44+
return NULL;
45+
}
46+
47+
ExternC const PfnDliHook __pfnDliNotifyHook2 = delayHook;

package_win32.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/bin/bash
22
archive="umodel_win32.zip"
3-
filelist="umodel.exe readme.txt SDL2.dll"
3+
filelist="umodel.exe umodel_64.exe readme.txt SDL2.dll SDL2_64.dll"
44

5-
for i in $filelist; do
6-
if [ ! -f $i ]; then
7-
echo "ERROR: unable to find \"$i\""
8-
exit 1
9-
fi
10-
done
5+
# Build 32 and 64 bit executables
6+
./build.sh || exit 1
7+
./build.sh --64 || exit 1
118

129
if grep -q -E "(PRIVATE BUILD)" umodel.exe; then
1310
echo "ERROR: this is a private build"
@@ -19,5 +16,21 @@ if grep -q -E "(DEBUG BUILD)" umodel.exe; then
1916
exit
2017
fi
2118

19+
# Copy SDL2.dll locally
20+
cp libs/SDL2/x86/SDL2.dll .
21+
cp libs/SDL2/x64/SDL2.dll ./SDL2_64.dll
22+
23+
# Verify for presence of all files
24+
for i in $filelist; do
25+
if [ ! -f $i ]; then
26+
echo "ERROR: unable to find \"$i\""
27+
exit 1
28+
fi
29+
done
30+
31+
# Create an archive
2232
rm -f $archive
2333
pkzipc -add $archive -level=9 $filelist
34+
35+
# Remove SDL2.dll files, these are required only for packaging
36+
rm -f SDL2.dll SDL2_64.dll

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ Oodle
216216

217217
Changes
218218
~~~~~~~
219+
05.07.2021
220+
- providing Win32 and Win64 builds of UE Viewer
221+
219222
30.05.2021
220223
- Mass Effect Legendary Edition support
221224

umodel.exe

190 KB
Binary file not shown.

0 commit comments

Comments
 (0)