-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle
322 lines (259 loc) · 10.7 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
id "de.undercouch.download" version "3.4.3"
id 'com.github.hierynomus.license' version '0.15.0'
id 'maven-publish'
id 'net.nemerosa.versioning' version '2.7.1'
id 'com.jfrog.bintray' version '1.8.4'
id 'com.github.ben-manes.versions' version '0.13.0'
}
apply from: 'gradle/publishing.gradle'
repositories {
jcenter()
mavenCentral()
}
boolean runsOn(String osName) {
return System.properties['os.name'].toLowerCase().contains(osName.toLowerCase())
}
ext.isWindows = runsOn('windows')
ext.isLinux = runsOn('linux')
ext.isMacOS = runsOn('mac')
wrapper {
gradleVersion = '6.0'
}
sourceCompatibility = '11'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
compileJava {
options.warnings = true
options.deprecation = true
options.compilerArgs += ["-Xdoclint:none", "-Xlint:none", "-h", file("$projectDir/src/main/native/src/main/headers/")]
}
dependencies {
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
javafx {
version = "13"
modules = [ 'javafx.controls']
//sdk = "$projectDir/deps/javafx-sdk/sdk/javafx-sdk-13/"
}
mainClassName = 'eu.mihosoft.nativefx.NativeFXApp'
task downloadBoostHeaders(type: Download) {
src 'http://deps.mihosoft.eu/boost/1.71.0/headers/boost.zip'
dest "$projectDir/src/main/native/ext/headers/boost.zip"
onlyIfNewer true
}
task downloadAndUnzipBoostHeaders(dependsOn: downloadBoostHeaders, type: Copy) {
from zipTree(downloadBoostHeaders.dest)
into "$projectDir/src/main/native/ext/headers/"
}
task cmakeNative(dependsOn: [downloadAndUnzipBoostHeaders], type:Exec) {
doFirst {
String version;
def cmdAndArgs = [];
if(isWindows) {
cmdAndArgs = ["cmd", "/c", "cmake.exe", "--version"]
} else {
cmdAndArgs = ["cmake", "--version"]
}
def stdout = new ByteArrayOutputStream()
def result = exec {
commandLine = cmdAndArgs
standardOutput = stdout
}
if(result.exitValue != 0) {
throw new RuntimeException("Cannot run 'cmake' executable!"+
" Make sure it's installed and added to the executable PATH."
)
}
version = stdout.toString()
def lines = version.split('\n')
if(lines.size() < 1) {
throw new RuntimeException("Cannot determin cmake version: $version")
}
version = lines[0]
def words = version.split(' ');
if(words.size() < 3) {
throw new RuntimeException("Cannot determin cmake version: $version")
}
try {
version = words[2]
def numbers = version.split('\\.')
if(numbers.size() < 2) {
throw new RuntimeException("Cannot determin cmake version: $version")
}
if((numbers[0] as Integer) < 3) {
throw new RuntimeException("Cmake version '$version' is too old!")
}
if((numbers[0] as Integer) == 3 && (numbers[1] as Integer) < 9) {
throw new RuntimeException("Cmake version '$version' is too old!")
}
} catch (NumberFormatException ex) {
throw new RuntimeException("Cannot determin cmake version: $version")
}
mkdir "$projectDir/build/native/"
}
workingDir "$projectDir/build/native/"
if(isWindows) {
commandLine 'cmd', '/c', 'cmake.exe', "$projectDir/src/main/native/", "-DCMAKE_GENERATOR_PLATFORM=x64"
} else {
commandLine 'cmake', "$projectDir/src/main/native/"
}
}
task compileNative(dependsOn: cmakeNative, type:Exec) {
workingDir "$projectDir/build/native/"
// if we didn't find msbuild in default locations
// then this will work if it's on the path
String msbuildCmd = "MSBuild.exe"
String[] paths = [
// search msbuild in default locations for visual studio 2019
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\MSBuild.exe",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\bin\\MSBuild.exe",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\bin\\MSBuild.exe",
// search msbuild in default locations for visual studio 2017
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\MSBuild\\15.0\\Bin\\MSBuild.exe",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\bin\\MSBuild.exe",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\bin\\MSBuild.exe",
// search msbuild in default locations for visual studio 2015
"C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe"
]
// this is stupid. but it looks like we really have to do this.
// PLEASE let me know if i'm wrong.
// (why can't msbuild.exe just be on the path like make?)
// (we don't want to force devs to use the developer command line or do
// other crazy magic like running vcvarsall.but etc.)
for(String p : paths) {
if(new File(p).isFile()) {
msbuildCmd = p;
break;
}
}
if(isWindows) {
commandLine 'cmd', '/c', msbuildCmd, 'nativefx.sln', '/property:Configuration=Release', '/property:Platform=x64'
} else {
commandLine 'make'
}
}
task cleanNativeResources() {
doFirst{
if(isWindows) {
def dest = java.nio.file.Paths.get("$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/windows/x64/")
def destFile = java.nio.file.Paths.get(dest.toString()+"/nativefx.dll")
java.nio.file.Files.deleteIfExists(destFile);
} else if(isLinux) {
def dest = java.nio.file.Paths.get("$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/linux/x64/")
def destFile = java.nio.file.Paths.get(dest.toString()+"/libnativefx.so")
java.nio.file.Files.deleteIfExists(destFile);
} else if(isMacOS) {
def dest = java.nio.file.Paths.get("$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/macos/x64/")
def destFile = java.nio.file.Paths.get(dest.toString()+"/libnativefx.dylib")
java.nio.file.Files.deleteIfExists(destFile);
}
}
}
// task copyNativeToResources(dependsOn: compileNative) {
// doFirst {
// if(isWindows) {
// def src = java.nio.file.Paths.get("$projectDir/build/native/Release/nativefx.dll")
// def dest = java.nio.file.Paths.get("$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/windows/x64/")
// def destFile = java.nio.file.Paths.get(dest.toString()+"/nativefx.dll")
// if(!dest.toFile().exists()) java.nio.file.Files.createDirectories(dest);
// java.nio.file.Files.copy(src, destFile, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
// } else if(isLinux) {
// def src = java.nio.file.Paths.get("$projectDir/build/native/libnativefx.so")
// def dest = java.nio.file.Paths.get("$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/linux/x64/")
// def destFile = java.nio.file.Paths.get(dest.toString()+"/libnativefx.so")
// if(!dest.toFile().exists()) java.nio.file.Files.createDirectories(dest);
// java.nio.file.Files.copy(src, destFile, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
// } else if(isMacOS) {
// def src = java.nio.file.Paths.get("$projectDir/build/native/libnativefx.dylib")
// def dest = java.nio.file.Paths.get("$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/macos/x64/")
// def destFile = java.nio.file.Paths.get(dest.toString()+"/libnativefx.dylib")
// if(!dest.toFile().exists()) java.nio.file.Files.createDirectories(dest);
// java.nio.file.Files.copy(src, destFile, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
// }
// }
// }
task copyNativeToResources(dependsOn: compileNative) {
if(isWindows) {
copy {
from "$projectDir/build/native/Release/"
into "$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/windows/x64/"
}
// TODO check whether we need to ship redist libraries on windows
// copy {
// from "$projectDir/resources/native/windows/x64/"
// into "$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/windows/x64/"
// }
} else if(isLinux) {
copy {
from "$projectDir/build/native/libnativefx.so"
into "$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/linux/x64/"
}
} else if(isMacOS) {
copy {
from "$projectDir/build/native/libnativefx.dylib"
into "$projectDir/src/main/resources/eu/mihosoft/nativefx/nativelibs/macos/x64/"
}
}
}
jar {
// include '**/*.dylib'
// include '**/*.so'
// include '**/*.dll'
manifest {
// attributes(
// 'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
// 'Main-Class': mainClassName
// )
attributes('Automatic-Module-Name': 'eu.mihosoft.nativefx.core')
}
}
clean.dependsOn += "cleanNativeResources"
compileNative.dependsOn += "compileJava"
assemble.dependsOn += "copyNativeToResources"
license {
header = rootProject.file('config/HEADER')
strictCheck = true
ignoreFailures = true
mapping {
java = 'SLASHSTAR_STYLE'
groovy = 'SLASHSTAR_STYLE'
fxml = 'XML_STYLE'
}
ext.yearCurrent = new java.text.SimpleDateFormat("yyyy").format(new Date())
ext.yearSince1 = '2019'
ext.author1 = 'Michael Hoffer <info@michaelhoffer.de>'
exclude '**/*.svg'
exclude '**/*.dll'
exclude '**/*.exp'
exclude '**/*.lib'
exclude '**/*.so'
exclude '**/*.dylib'
include '**/*.h'
include '**/*.hpp'
include '**/*.cpp'
include 'src/main/native/**/*'
}
test {
forkEvery = 1
testLogging {
// Make sure output from
// standard out or error is shown
// in Gradle output.
showStandardStreams = true
// Or we use events method:
// events 'standard_out', 'standard_error'
// Or set property events:
// events = ['standard_out', 'standard_error']
// Instead of string values we can
// use enum values:
// events org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT,
// org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR,
}
}
run {
jvmArgs "-Dfile.encoding=UTF-8"
}