Skip to content

Commit a392a42

Browse files
committed
Build scripts
1 parent 19de616 commit a392a42

File tree

7 files changed

+101
-33
lines changed

7 files changed

+101
-33
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,13 @@ Dear ImGui by default uses a stb_strutype library to render a fonts atlas. It's
244244
* Read [javadoc](https://javadoc.io/doc/io.imgui.java/binding) and sources comments to get more info.
245245

246246
## How to Build
247-
To build native libraries you should install `mingw-w64` and `ant`. Modify [GenerateLibs](https://github.com/SpaiR/imgui-java/blob/master/buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy)
248-
to build specific binaries you need. After you've configured everything, run `gradlew :imgui-binding:generateLibs`.
249-
That will build native libraries and place them in `imgui-binding/build/libsNative` folder.
247+
To build native libraries you need:
248+
- Unix-like system (MacOS to build natives for Mac)
249+
- Installed dependencies: `mingw-w64`, `ant`, `freetype2`
250+
251+
After you've configured everything, run `gradlew :imgui-binding:generateLibs -Denvs=${envShortcut} -Dlocal`.<br>
252+
`envShortcut` could be `win32`, `win64`, `linux32`, `linux64` or `mac64`.<br>
253+
`-Dlocal` is optional and means that natives will be built under the `./imgui-binding/build/` folder. Otherwise `/tmp/imgui` folder will be used.
250254

251255
## Credits
252256
Binding partly based on the work of [xpenatan](https://github.com/xpenatan) and his version [jDear-imgui](https://github.com/xpenatan/jDear-imgui).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
BASEDIR=$(dirname "$0")
4+
cd $BASEDIR/../../imgui-binding || exit
5+
6+
../gradlew clean generateLibs -Denvs=linux64 -Dlocal
7+
rm -frd libsNative
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
BASEDIR=$(dirname "$0")
4+
cd $BASEDIR/../../imgui-binding || exit
5+
6+
rm -frd /tmp/imgui
7+
../gradlew clean generateLibs -Denvs=mac64
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
BASEDIR=$(dirname "$0")
4+
cd $BASEDIR/../../imgui-binding || exit
5+
6+
rm -frd /tmp/imgui
7+
../gradlew clean generateLibs -Denvs=win32,win64,linux32,linux64
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
BASEDIR=$(dirname "$0")
4+
cd $BASEDIR/../.. || exit
5+
6+
cp /tmp/imgui/libsNative/macosx64/libimgui-java64.dylib ./bin
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
BASEDIR=$(dirname "$0")
4+
cd $BASEDIR/../.. || exit
5+
6+
cp /tmp/imgui/libsNative/windows32/imgui-java.dll ./bin
7+
cp /tmp/imgui/libsNative/windows64/imgui-java64.dll ./bin
8+
cp /tmp/imgui/libsNative/linux32/libimgui-java.so ./bin
9+
cp /tmp/imgui/libsNative/linux64/libimgui-java64.so ./bin

buildSrc/src/main/groovy/imgui/generate/GenerateLibs.groovy

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ import org.gradle.api.tasks.TaskAction
88

99
@CompileStatic
1010
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")
1221

1322
private final String sourceDir = project.file('src/main/java')
1423
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'
1726
private final String libsFolder = 'libsNative'
1827

1928
@TaskAction
@@ -31,41 +40,60 @@ class GenerateLibs extends DefaultTask {
3140

3241
// Generate platform dependant ant configs and header files
3342
def buildConfig = new BuildConfig('imgui-java', tmpFolder, libsFolder, jniDir)
43+
def buildTargets = [] as BuildTarget[]
3444

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+
}
4057

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+
}
4570

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+
}
5880

59-
new AntScriptGenerator().generate(buildConfig, win32, win64, linux32, linux64, mac64)
81+
new AntScriptGenerator().generate(buildConfig, buildTargets)
6082

6183
// Generate native libraries
6284
// Comment/uncomment lines with OS you need.
6385

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+
6997
BuildExecutor.executeAnt(jniDir + '/build.xml', '-v', 'pack-natives')
7098
}
7199
}

0 commit comments

Comments
 (0)