Skip to content

Commit a3c7d2c

Browse files
committed
Added back SDL2 backend because SDL3 was broken
1 parent 508fdc2 commit a3c7d2c

27 files changed

+6481
-1639
lines changed

backends/backend-sdl/build.gradle

Lines changed: 126 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,133 @@
11
sourceSets.main.java.srcDirs = ["src"]
2+
sourceSets.main.resources.srcDirs = ["libs/linux64", "libs/macosx64","libs/windows32", "libs/windows64"]
23

3-
configurations{
4-
natives
4+
dependencies{
5+
testImplementation libraries.jnigen
6+
testImplementation aproj(":arc-core")
57
}
68

7-
jar{
8-
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
9-
from{
10-
configurations.natives.collect{ it.isDirectory() ? it : zipTree(it) }
9+
apply plugin: "com.badlogicgames.gdx.gdx-jnigen"
10+
11+
file("jni").mkdir()
12+
13+
task preJni{
14+
//this absolutely needs to run during configuration so jnigen can run downloaded sdl-config scripts for configuration of library flags
15+
try{
16+
if(!file("jni/glew.zip").exists()){
17+
println "Fetching GLEW source..."
18+
"curl -o $rootDir/backends/backend-sdl/jni/glew.zip -L https://github.com/nigels-com/glew/releases/download/glew-2.2.0/glew-2.2.0.zip".execute().waitFor()
19+
"unzip -qq -d $rootDir/backends/backend-sdl/jni $rootDir/backends/backend-sdl/jni/glew.zip".execute().waitFor()
20+
}
21+
22+
if(!file("jni/sdlmingw.tar.gz").exists()){
23+
println "Fetching SDL-mingw builds..."
24+
"curl -o $rootDir/backends/backend-sdl/jni/sdlmingw.tar.gz -L https://www.libsdl.org/release/SDL2-devel-2.32.8-mingw.tar.gz".execute().waitFor()
25+
"tar -xvzf $rootDir/backends/backend-sdl/jni/sdlmingw.tar.gz -C $rootDir/backends/backend-sdl/jni".execute().waitFor()
26+
}
27+
}catch(Exception youAreProbablyOnWindowsOrDontHaveUnzip){}
28+
29+
doFirst{
30+
copy{
31+
from "$rootDir/arc-core/build/classes/java/main"
32+
into "$rootDir/backends/backend-sdl/build/classes/java/main"
33+
include "**"
34+
}
1135
}
1236
}
1337

14-
dependencies{
15-
natives libraries.lwjgl
16-
api libraries.lwjgl
17-
}
38+
/*
39+
40+
PACKAGES: Linux (Ubuntu)
41+
42+
- libdrm-dev
43+
- libsdl2-dev
44+
- libgbm-dev
45+
- ant
46+
47+
PACKAGES: Linux -> Windows Cross-Compilation
48+
49+
- mingw32
50+
- ant
51+
52+
PACKAGES: Mac
53+
54+
- sdl2
55+
- glew
56+
- ant
57+
58+
*/
59+
60+
jnigen{
61+
def execCmd = { cmd ->
62+
try{
63+
Scanner s = new Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A")
64+
return s.hasNext() ? s.next().trim() : ""
65+
}catch(Exception ignored){
66+
//fail silently, because this is run during standard arc builds and it shouldn't fail
67+
//TODO don't do anything at all in certain situations?
68+
}
69+
}
70+
71+
sharedLibName = "sdl-arc"
72+
temporaryDir = file("build/target/native").absolutePath
73+
libsDir = file("libs").absolutePath
74+
75+
def sdlVersion = "2.32.8"
76+
77+
all{
78+
cppIncludes = ["*.cpp"]
79+
cIncludes = ["*.c", "glew-2.2.0/src/glew.c"]
80+
headerDirs += ["glew-2.2.0/include"]
81+
}
82+
add(Linux, x64){
83+
cppFlags += " " + execCmd("sdl2-config --cflags")
84+
cFlags = cppFlags
85+
//NOTE: for this to statically link properly, you need to add -L/path/to/folder/with/custom/libSDL2.a
86+
//where this folder contains a custom build of SDL2 with the -fPIC flag (added to the makefile in the cflags section after configure)
87+
//--static-libs and ?.replace("-lSDL2", "-l:libSDL2.a")
88+
libraries = execCmd("sdl2-config --libs") + " -Wl,-Bdynamic -lGL "
89+
linkerFlags = "-shared -m64"
90+
}
91+
add(Windows, x64){
92+
def path = "SDL2-$sdlVersion/x86_64-w64-mingw32"
93+
def root = "$rootDir/backends/backend-sdl/jni"
94+
headerDirs += (String[])["$path/include/SDL2"]
95+
cppFlags += " " + execCmd("sh $root/$path/bin/sdl2-config --cflags")
96+
cFlags = cppFlags
97+
libraries = execCmd("sh $root/$path/bin/sdl2-config --static-libs") + " -lopengl32"
98+
linkerFlags += " -L $root/$path/lib"
99+
}
100+
add(Windows, x32){
101+
def path = "SDL2-$sdlVersion/i686-w64-mingw32"
102+
def root = "$rootDir/backends/backend-sdl/jni"
103+
headerDirs += (String[])["$path/include/SDL2"]
104+
cppFlags += " " + execCmd("sh $root/$path/bin/sdl2-config --cflags")
105+
cFlags = cppFlags
106+
libraries = execCmd("sh $root/$path/bin/sdl2-config --static-libs") + " -lopengl32"
107+
linkerFlags += " -L $root/$path/lib"
108+
}
109+
110+
if(System.getProperty("os.arch") != "aarch64"){
111+
add(MacOsX, x64){
112+
cppFlags = cFlags= execCmd("sdl2-config --cflags") + " -c -Wall -O2 -arch x86_64 -DFIXED_POINT -fmessage-length=0 -fPIC -mmacosx-version-min=10.9 -stdlib=libc++"
113+
linkerFlags = "-shared -arch x86_64 -mmacosx-version-min=10.9 -stdlib=libc++"
114+
libraries = "/usr/local/lib/libSDL2.a -lm -liconv -Wl,-framework,CoreAudio -Wl,-framework,CoreHaptics -Wl,-weak_framework,GameController -Wl,-framework,OpenGL,-weak_framework,AudioToolbox -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-weak_framework,QuartzCore -Wl,-weak_framework,Metal /usr/local/lib/libGLEW.a"
115+
}
116+
}else{
117+
118+
//doesn't work on CI, have to use native M1
119+
add(MacOsX, x64, ARM){
120+
cppFlags = cFlags = execCmd("sdl2-config --cflags") + " -c -Wall -O2 -arch arm64 -DFIXED_POINT -fmessage-length=0 -fPIC -mmacosx-version-min=10.9 -stdlib=libc++"
121+
linkerFlags = "-shared -arch arm64 -mmacosx-version-min=10.9 -stdlib=libc++"
122+
//execCmd("sdl2-config --static-libs") + " -Wl,-framework,OpenGL"
123+
libraries = "/usr/local/lib/libSDL2.a -lm -liconv -Wl,-framework,CoreAudio -Wl,-weak_framework,GameController -Wl,-framework,OpenGL,-weak_framework,AudioToolbox -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-weak_framework,QuartzCore -Wl,-weak_framework,Metal /usr/local/lib/libGLEW.a"
124+
}
125+
}
126+
127+
}
128+
129+
getTasksByName("jnigen", true).each{
130+
it.dependsOn preJni
131+
it.dependsOn classes
132+
it.dependsOn aproj(":arc-core").getTasksByName("compileJava", true)
133+
}
1.47 MB
Binary file not shown.
763 KB
Binary file not shown.
2 MB
Binary file not shown.
2.07 MB
Binary file not shown.
2.14 MB
Binary file not shown.
1.99 MB
Binary file not shown.

0 commit comments

Comments
 (0)