@@ -8,12 +8,21 @@ import org.gradle.api.tasks.TaskAction
8
8
9
9
@CompileStatic
10
10
class GenerateLibs extends DefaultTask {
11
- String description = ' Generates native libraries using classes under ":imgui-binding" and Dear-ImGui itself from "imgui" submodule.'
11
+ String description = ' Generates native libraries using classes under ":imgui-binding" and Dear ImGui itself from "imgui" submodule.'
12
+
13
+ private final String [] buildEnvs = System . getProperty(' envs' )?. split(' ,' )
14
+ private final boolean forWin32 = buildEnvs?. contains(' win32' )
15
+ private final boolean forWin64 = buildEnvs?. contains(' win64' )
16
+ private final boolean forLinux32 = buildEnvs?. contains(' linux32' )
17
+ private final boolean forLinux64 = buildEnvs?. contains(' linux64' )
18
+ private final boolean forMac64 = buildEnvs?. contains(' mac64' )
19
+
20
+ private final boolean isLocal = System . properties. containsKey(" local" )
12
21
13
22
private final String sourceDir = project. file(' src/main/java' )
14
23
private final String classpath = project. file(' build/classes/java/main' )
15
- private final String jniDir = project. buildDir. path + ' /jni'
16
- private final String tmpFolder = project. buildDir. path + ' /tmp'
24
+ private final String jniDir = (isLocal ? project. buildDir. path : ' /tmp/imgui ' ) + ' /jni'
25
+ private final String tmpFolder = (isLocal ? project. buildDir. path : ' /tmp/imgui ' ) + ' /tmp'
17
26
private final String libsFolder = ' libsNative'
18
27
19
28
@TaskAction
@@ -31,41 +40,60 @@ class GenerateLibs extends DefaultTask {
31
40
32
41
// Generate platform dependant ant configs and header files
33
42
def buildConfig = new BuildConfig (' imgui-java' , tmpFolder, libsFolder, jniDir)
43
+ def buildTargets = [] as BuildTarget []
34
44
35
- def win32 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.Windows , false )
36
- def win64 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.Windows , true )
37
-
38
- def linux32 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.Linux , false )
39
- def linux64 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.Linux , true )
45
+ if (forWin32) {
46
+ def win32 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.Windows , false )
47
+ win32. cppFlags + = ' -fstack-protector -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include'
48
+ win32. libraries + = ' -lfreetype -lbz2 -lssp'
49
+ buildTargets + = win32
50
+ }
51
+ if (forWin64) {
52
+ def win64 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.Windows , true )
53
+ win64. cppFlags + = ' -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include'
54
+ win64. libraries + = ' -lfreetype -lbz2 -lssp'
55
+ buildTargets + = win64
56
+ }
40
57
41
- def mac64 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.MacOsX , true )
42
- mac64. cppFlags + = " -stdlib=libc++"
43
- mac64. cppFlags = mac64. cppFlags. replaceAll(" 10.5" , " 10.9" )
44
- mac64. linkerFlags = mac64. linkerFlags. replaceAll(" 10.5" , " 10.9" )
58
+ if (forLinux32) {
59
+ def linux32 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.Linux , false )
60
+ linux32. cppFlags + = ' -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include'
61
+ linux32. linkerFlags + = ' -lfreetype'
62
+ buildTargets + = linux32
63
+ }
64
+ if (forLinux64) {
65
+ def linux64 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.Linux , true )
66
+ linux64. cppFlags + = ' -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include'
67
+ linux64. linkerFlags + = ' -lfreetype'
68
+ buildTargets + = linux64
69
+ }
45
70
46
- // Freetype Deps Config
47
- win32. cppFlags + = " -fstack-protector -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
48
- win32. libraries + = " -lfreetype -lbz2 -lssp"
49
- win64. cppFlags + = " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
50
- win64. libraries + = " -lfreetype -lbz2 -lssp"
51
- linux32. cppFlags + = " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
52
- linux32. linkerFlags + = " -lfreetype"
53
- linux64. cppFlags + = " -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include"
54
- linux64. linkerFlags + = " -lfreetype"
55
- mac64. cppFlags + = " -I/usr/local/include/freetype2 -I/usr/local/include/libpng16 -I/usr/local/include/harfbuzz -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include"
56
- mac64. linkerFlags + = " -lfreetype"
57
- // End
71
+ if (forMac64) {
72
+ def mac64 = BuildTarget . newDefaultTarget(BuildTarget.TargetOs.MacOsX , true )
73
+ mac64. cppFlags + = ' -stdlib=libc++'
74
+ mac64. cppFlags = mac64. cppFlags. replaceAll(' 10.5' , ' 10.9' )
75
+ mac64. linkerFlags = mac64. linkerFlags. replaceAll(' 10.5' , ' 10.9' )
76
+ mac64. cppFlags + = ' -I/usr/local/include/freetype2 -I/usr/local/include/libpng16 -I/usr/local/include/harfbuzz -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include'
77
+ mac64. linkerFlags + = ' -lfreetype'
78
+ buildTargets + = mac64
79
+ }
58
80
59
- new AntScriptGenerator (). generate(buildConfig, win32, win64, linux32, linux64, mac64 )
81
+ new AntScriptGenerator (). generate(buildConfig, buildTargets )
60
82
61
83
// Generate native libraries
62
84
// Comment/uncomment lines with OS you need.
63
85
64
- BuildExecutor . executeAnt(jniDir + ' /build-windows32.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
65
- BuildExecutor . executeAnt(jniDir + ' /build-windows64.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
66
- BuildExecutor . executeAnt(jniDir + ' /build-linux32.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
67
- BuildExecutor . executeAnt(jniDir + ' /build-linux64.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
68
- BuildExecutor . executeAnt(jniDir + ' /build-macosx64.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
86
+ if (forWin32)
87
+ BuildExecutor . executeAnt(jniDir + ' /build-windows32.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
88
+ if (forWin64)
89
+ BuildExecutor . executeAnt(jniDir + ' /build-windows64.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
90
+ if (forLinux32)
91
+ BuildExecutor . executeAnt(jniDir + ' /build-linux32.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
92
+ if (forLinux64)
93
+ BuildExecutor . executeAnt(jniDir + ' /build-linux64.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
94
+ if (forMac64)
95
+ BuildExecutor . executeAnt(jniDir + ' /build-macosx64.xml' , ' -v' , ' -Dhas-compiler=true' , ' -Drelease=true' , ' clean' , ' postcompile' )
96
+
69
97
BuildExecutor . executeAnt(jniDir + ' /build.xml' , ' -v' , ' pack-natives' )
70
98
}
71
99
}
0 commit comments