-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.gradle
More file actions
193 lines (166 loc) · 5.2 KB
/
Copy pathbuild.gradle
File metadata and controls
193 lines (166 loc) · 5.2 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
plugins {
id 'java-library'
id 'maven-publish'
id 'com.gradleup.shadow' version "${shadow_version}"
id 'net.linguica.maven-settings' version "${maven_settings_version}"
id "de.undercouch.download" version "${gradle_download_task_version}"
}
group = 'de.maxhenkel.speex4j'
base {
archivesName = 'speex4j'
}
version = library_version
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
withJavadocJar()
}
tasks.named('sourcesJar', Jar) {
exclude 'natives/**'
}
def generatedResourcesDir = layout.buildDirectory.dir("generated-resources")
sourceSets {
main {
resources {
srcDir generatedResourcesDir
}
}
}
repositories {
mavenCentral()
maven { url = 'https://maven.maxhenkel.de/repository/public' }
}
dependencies {
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
implementation "de.maxhenkel.native-utils:native-utils:${nativeutils_version}"
testImplementation platform("org.junit:junit-bom:${junit_version}")
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.platform:junit-platform-launcher'
}
test {
useJUnitPlatform()
}
shadowJar {
archiveClassifier = ''
relocate("de.maxhenkel.nativeutils", "de.maxhenkel.speex4j")
}
tasks.assemble.dependsOn tasks.shadowJar
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'Speex4J'
description = 'Speex Wrapper for Java'
url = 'https://maxhenkel.de'
}
}
}
repositories {
maven {
name = 'henkelmax.public'
url = uri('https://maven.maxhenkel.de/repository/public')
}
}
}
def platforms = [
[
name : 'windows-x64',
file : 'zig-x86_64-windows-gnu.cmake',
res : 'windows-x64',
libExt: 'dll'
],
[
name : 'windows-arm64',
file : 'zig-aarch64-windows-gnu.cmake',
res : 'windows-aarch64',
libExt: 'dll'
],
[
name : 'linux-x64',
file : 'zig-x86_64-linux-gnu.cmake',
res : 'linux-x64',
libExt: 'so'
],
[
name : 'linux-arm64',
file : 'zig-aarch64-linux-gnu.cmake',
res : 'linux-aarch64',
libExt: 'so'
],
[
name : 'macos-x64',
file : 'zig-x86_64-macos.cmake',
res : 'mac-x64',
libExt: 'dylib'
],
[
name : 'macos-arm64',
file : 'zig-aarch64-macos.cmake',
res : 'mac-aarch64',
libExt: 'dylib'
],
]
platforms.each { target ->
def safeName = target.name.capitalize().replace('-', '')
def configureTask = "configureNatives${safeName}"
def buildTask = "buildNatives${safeName}"
def copyTask = "copyNatives${safeName}"
def cmakeListsPath = "../../CMakeLists.txt"
def cmakePlatformPath = "../../cmake/${target.file}"
def buildDir = layout.projectDirectory.dir("native/build/${target.res}")
def resourceDir = generatedResourcesDir.get().dir("natives/${target.res}")
def cSourcesDir = layout.projectDirectory.dir('native/src')
def outputName = "libspeex4j.${target.libExt}"
tasks.register(configureTask, Exec) {
group = 'natives'
description = "CMake configure for ${target.name}"
workingDir = buildDir
inputs.file(buildDir.file(cmakeListsPath))
inputs.file(buildDir.file(cmakePlatformPath))
inputs.dir(cSourcesDir)
outputs.dir(buildDir)
doFirst {
def dir = buildDir.asFile
if (dir.exists()) {
logger.lifecycle("Cleaning ${dir}")
project.delete(fileTree(dir: dir))
}
dir.mkdirs()
}
commandLine 'cmake',
"-DCMAKE_TOOLCHAIN_FILE=${cmakePlatformPath}",
'-DCMAKE_BUILD_TYPE=Release',
'-G', 'Ninja',
'../..'
}
tasks.register(buildTask, Exec) {
group = 'natives'
description = "Build natives for ${target.name}"
workingDir = buildDir
dependsOn configureTask
inputs.dir(buildDir)
outputs.dir(buildDir)
commandLine 'cmake', '--build', '.', '--config', 'Release'
}
tasks.register(copyTask, Copy) {
group = 'natives'
description = "Copy ${target.name} natives into resources"
dependsOn buildTask
from buildDir.file(outputName)
into resourceDir
}
}
tasks.register('buildAndCopyAllNatives') {
group = 'natives'
description = 'Build & copy all native libraries for every platform/arch'
dependsOn platforms.collect { "copyNatives${it.name.capitalize().replace('-', '')}" }
}
tasks.named('processResources') {
dependsOn 'buildAndCopyAllNatives'
}
tasks.named("clean", Delete).configure {
delete("native/build")
}