-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
122 lines (97 loc) · 2.97 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import org.gradle.internal.logging.text.StyledTextOutput;
import org.gradle.internal.logging.text.StyledTextOutputFactory;
import static org.gradle.internal.logging.text.StyledTextOutput.Style;
defaultTasks 'clean'
def getAndroidNDKPath() {
return System.getenv("ANDROID_NDK")
}
def getAndroidSDKPath() {
return System.getenv("ANDROID_HOME")
}
ext.tempFolder = '/var/tmp/.temp'
ext.buildFolder = 'build'
ext.androidNDK = getAndroidNDKPath()
ext.androidNDKVersion = "26"
ext.androidSDK = getAndroidSDKPath()
if (ext.androidSDK == null) {
throw new GradleException('Must set ANDROID_HOME')
}
if (ext.androidNDK == null) {
ext.androidNDK = ext.androidSDK + '/ndk-bundle'
if (!file(ext.androidNDK).exists())
throw new GradleException('No NDK found in SDK: must set ANDROID_NDK')
}
def findCMake() {
def cmake = System.getenv("CMAKE");
if (cmake != null) {
return cmake;
}
def cmakes = fileTree(project.property('androidSDK')).matching { include 'cmake/*/bin/cmake' }
if (cmakes.size() == 0) {
throw new GradleException('No cmake found in ' + project.property('androidSDK') + '/cmake')
}
return cmakes.last();
}
ext.cmake = findCMake()
println "Build folder: $buildFolder"
println "Android SDK folder: $androidSDK"
println "Android NDK folder: $androidNDK"
println "Using cmake from: $cmake"
def cmake(projectFolder, cmakeFolder, arch, ndkVersion) {
exec {
workingDir cmakeFolder
commandLine "$cmake",
"$projectFolder",
"-DCMAKE_BUILD_TYPE=Release ",
"-DANDROID_PLATFORM=android-" + ndkVersion,
"-DANDROID_NDK=" + project.property('androidNDK') + " ",
"-DANDROID_STL=c++_static ",
"-DANDROID_ABI=" + arch,
"-DCMAKE_CXX_FLAGS= ",
"-DCMAKE_TOOLCHAIN_FILE=" + project.property('androidNDK') + "/build/cmake/android.toolchain.cmake",
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/var/tmp/" + arch
}
}
def buildLibs(arch, ndkVersion) {
def cmakeFolder = project.property('tempFolder') + '/' + arch + '/.cmake'
def buildFolder = project.property('buildFolder') + '/libs/' + arch
mkdir cmakeFolder
mkdir buildFolder
exec {
commandLine "$cmake", '--version'
}
println "Cmake folder: $cmakeFolder"
cmake("$projectDir/src/", cmakeFolder, arch, ndkVersion)
exec {
workingDir cmakeFolder
commandLine "make"
}
copy {
from file(cmakeFolder + "/libpeuck_static.a")
into file(buildFolder + "/libpeuck_static.a")
}
copy {
from file(cmakeFolder + "/libpeuck.so")
into file(buildFolder + "/libpeuck" + arch + ".so")
}
}
task clean(type: Delete) {
delete project.property('tempFolder')
delete project.property('buildFolder')
}
task build() {
def includeFolder = project.property('buildFolder') + '/include'
doFirst {
delete includeFolder
mkdir includeFolder
}
def ndkVersion = project.property('androidNDKVersion')
buildLibs("armeabi-v7a", ndkVersion)
buildLibs("arm64-v8a", ndkVersion)
doLast {
copy {
from "$projectDir/include"
into includeFolder
}
}
}