-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
768 lines (673 loc) · 28.3 KB
/
build.gradle.kts
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
@file:Suppress("LocalVariableName")
import java.io.FileInputStream
import java.util.Properties
buildscript {
val roboVMVersion = "2.3.20"
dependencies {
classpath("com.mobidevelop.robovm:robovm-gradle-plugin:$roboVMVersion")
}
}
plugins {
kotlin("jvm")
id("maven-publish")
}
val gdxVersion: String by project
dependencies {
implementation("com.badlogicgames.gdx:gdx:$gdxVersion")
}
//region Java Wrapping of Effekseer C++ using Swig
/**
* The directory all the Swig generated Java wrapper classes of Effekseer will be placed.
*/
val javaWrappedEffekseerDir = File("${projectDir}/src/main/java/io/github/niraj_rayalla/gdxseer/effekseer")
/**
* Task used to create the directory pointed by [javaWrappedEffekseerDir].
*/
val createJavaWrappedEffekseerDir by tasks.creating {
doLast {
delete(javaWrappedEffekseerDir)
javaWrappedEffekseerDir.mkdirs()
}
}
/**
* The directory all the Swig generated Java classes of the Effekseer adapter logic will be placed.
*/
val javaAdapterEffekseerDir = File("${projectDir}/src/main/java/io/github/niraj_rayalla/gdxseer/adapter_effekseer")
/**
* Task used to create the directory pointed by [javaAdapterEffekseerDir].
*/
val createJavaAdapterEffekseerDir by tasks.creating {
doLast {
delete(javaAdapterEffekseerDir)
javaAdapterEffekseerDir.mkdirs()
}
}
/**
* The directory all the Swig generated Java classes of the Effekseer GL logic will be placed.
*/
val javaEffekseerGLDir = File("${projectDir}/GL/src/main/java/io/github/niraj_rayalla/gdxseer/effekseer_gl")
/**
* Task used to create the directory pointed by [javaEffekseerGLDir].
*/
val createJavaEffekseerGLDir by tasks.creating {
doLast {
delete(javaEffekseerGLDir)
javaEffekseerGLDir.mkdirs()
}
}
/**
* The directory all the Swig generated Java classes of the Effekseer Metal logic will be placed.
*/
val javaEffekseerMetalDir = File("${projectDir}/Metal/src/main/java/io/github/niraj_rayalla/gdxseer/effekseer_metal")
/**
* Task used to create the directory pointed by [javaEffekseerMetalDir].
*/
val createJavaEffekseerMetalDir by tasks.creating {
doLast {
delete(javaEffekseerMetalDir)
javaEffekseerMetalDir.mkdirs()
}
}
/**
* The directory all the copied and transformed Effekseer source code is located. This is the actual files used by
* Swig to generate the Java wrappers.
*/
val copiedAndTransformedEffekseerDir = File("${projectDir}/cpp/Effekseer/Dev/Cpp/")
/**
* Task used to create the directory pointed by [copiedAndTransformedEffekseerDir].
*/
val createCopiedAndTransformedEffekseerDir by tasks.creating {
doLast {
copiedAndTransformedEffekseerDir.mkdirs()
}
}
/**
* Task used to copy the Effekseer source and do any transformations before getting Swigged.
*/
val copyAndTransformEffekseerSourceForSwig: Task by tasks.creating {
val deleteTask by tasks.creating {
// Delete existing copy
delete(copiedAndTransformedEffekseerDir)
}
dependsOn(deleteTask)
dependsOn(createCopiedAndTransformedEffekseerDir)
createCopiedAndTransformedEffekseerDir.shouldRunAfter(deleteTask)
val sourceCppDir = File("${projectDir}/Effekseer/Dev/Cpp/")
val copyTask by tasks.creating(Copy::class.java) {
// Get a new copy of Effekseer source
copy {
from(sourceCppDir)
.into(copiedAndTransformedEffekseerDir)
.exclude("3rdParty")
.exclude("EditorCommon")
.exclude("EffekseerMaterial*")
.exclude("EffekseerRendererDX*")
.exclude("TakeScreenshots*")
.exclude("Test*")
.exclude("Viewer")
}
}
dependsOn(copyTask)
copyTask.shouldRunAfter(createCopiedAndTransformedEffekseerDir)
val transformTask by tasks.creating(Copy::class.java) {
// Transform sources
var wasTransformed = false
val EffectNodeRelativeFilePath = "Effekseer/Effekseer/Effekseer.EffectNode.h"
val transformSearch = "struct alignas(2) TriggerValues"
val transformReplace = "struct TriggerValues"
val copiedEffectNodeIncludePath = File(copiedAndTransformedEffekseerDir, EffectNodeRelativeFilePath)
delete(copiedEffectNodeIncludePath)
copy {
from(File(sourceCppDir, EffectNodeRelativeFilePath))
.into(copiedEffectNodeIncludePath.parentFile)
.filter { line ->
if (line.contains(transformSearch)) {
wasTransformed = true
line.replace(transformSearch, transformReplace)
}
else line
}
}
if (!wasTransformed) {
throw GradleException("Failed to find \"$transformSearch\" in $copiedEffectNodeIncludePath so that it can be replaced with \"$transformReplace\" for SWIG generation. This is needed to avoid this error: \"Swig: Syntax error in input\".")
}
}
dependsOn(transformTask)
transformTask.shouldRunAfter(copyTask)
}
/**
* Task used to generate the Java logic that wraps the C++ Effekseer logic using Swig.
*/
val generateWrapperEffekseer by tasks.creating {
dependsOn(copyAndTransformEffekseerSourceForSwig)
dependsOn(createJavaWrappedEffekseerDir)
createJavaWrappedEffekseerDir.shouldRunAfter(copyAndTransformEffekseerSourceForSwig)
// The effekseer logic
val effekseerGenerateTask by tasks.creating(Exec::class.java) {
commandLine(
"swig", "-c++", "-java",
"-package", "io.github.niraj_rayalla.gdxseer.effekseer",
"-outdir", javaWrappedEffekseerDir.absolutePath,
"-o", "${projectDir}/cpp/Effekseer_Swig.cpp",
"${projectDir}/swig_interface/effekseer.i"
)
}
dependsOn(effekseerGenerateTask)
effekseerGenerateTask.shouldRunAfter(createJavaWrappedEffekseerDir)
// The effekseer adapter logic
val adapterEffekseerGenerateTask by tasks.creating(Exec::class.java) {
dependsOn(createJavaAdapterEffekseerDir)
commandLine(
"swig", "-c++", "-java",
"-package", "io.github.niraj_rayalla.gdxseer.adapter_effekseer",
"-outdir", javaAdapterEffekseerDir.absolutePath,
"-o", "${projectDir}/cpp/Adapter_Effekseer_Swig.cpp",
"${projectDir}/swig_interface/adapter_effekseer.i"
)
}
dependsOn(adapterEffekseerGenerateTask)
adapterEffekseerGenerateTask.shouldRunAfter(effekseerGenerateTask)
// The effekseer GL logic
val effekseerGLGenerateTask by tasks.creating(Exec::class.java) {
dependsOn(createJavaEffekseerGLDir)
commandLine(
"swig", "-c++", "-java",
"-package", "io.github.niraj_rayalla.gdxseer.effekseer_gl",
"-outdir", javaEffekseerGLDir.absolutePath,
"-o", "${projectDir}/cpp/Effekseer_GL_Swig.cpp",
"${projectDir}/swig_interface/effekseer_GL.i"
)
}
dependsOn(effekseerGLGenerateTask)
effekseerGLGenerateTask.shouldRunAfter(adapterEffekseerGenerateTask)
// The effekseer Metal logic
val effekseerMetalGenerateTask by tasks.creating(Exec::class.java) {
dependsOn(createJavaEffekseerMetalDir)
commandLine(
"swig", "-c++", "-java",
"-package", "io.github.niraj_rayalla.gdxseer.effekseer_metal",
"-outdir", javaEffekseerMetalDir.absolutePath,
"-o", "${projectDir}/cpp/Effekseer_Metal_Swig.mm",
"${projectDir}/swig_interface/effekseer_Metal.i"
)
}
dependsOn(effekseerMetalGenerateTask)
effekseerMetalGenerateTask.shouldRunAfter(effekseerGLGenerateTask)
// Delete the copied code
val deleteCopiedEffekseerSource by tasks.creating {
doLast {
delete(File("${projectDir}/cpp/Effekseer/"))
}
}
dependsOn(deleteCopiedEffekseerSource)
deleteCopiedEffekseerSource.shouldRunAfter(effekseerMetalGenerateTask)
}
//endregion
//region CMAKE configuration
//region Desktop
/**
* The directory to use for Cmake building on the current OS.
*/
val desktopCmakeBuildDir = when {
org.gradle.internal.os.OperatingSystem.current().isMacOsX -> {
File("${projectDir}/cmake-macos")
}
org.gradle.internal.os.OperatingSystem.current().isLinux -> {
File("${projectDir}/cmake-linux")
}
else -> {
File("${projectDir}/cmake-windows")
}
}
/**
* Used to create [desktopCmakeBuildDir]. This doesn't delete the directory if it already exists.
*/
val createDesktopCmakeBuildDir by tasks.creating {
doLast {
desktopCmakeBuildDir.mkdirs()
}
}
/**
* Calls cmake to configure for cmake building of the desktop library on the current OS.
*/
val configureDesktopBuilding by tasks.creating(Exec::class.java) {
dependsOn(generateWrapperEffekseer)
dependsOn(createDesktopCmakeBuildDir)
createDesktopCmakeBuildDir.shouldRunAfter(generateWrapperEffekseer)
val commandLineArgs = ArrayList<String>().apply {
add("cmake")
if (org.gradle.internal.os.OperatingSystem.current().isMacOsX) {
add("-D")
add("CMAKE_OSX_ARCHITECTURES=x86_64;arm64")
}
add("-D")
add("GDXSEER_RENDERER=GL")
add("-B")
add(desktopCmakeBuildDir.absolutePath)
}
commandLine(commandLineArgs)
}
//endregion
//region iOS
/**
* @return The directory the iOS library for the given properties should be built in.
*/
fun getIOSCmakeBuildDir(isForSimulator: Boolean, isUsingMetal: Boolean): File {
val sim = if (isForSimulator) "simulator" else "device"
val renderer = if (isUsingMetal) "metal" else "gl"
return File("${projectDir}/cmake-ios-$sim-$renderer")
}
/**
* Used to create the directory the iOS library for the given properties should be built in. This doesn't delete the directory if it already exists.
*/
fun createIOSCmakeBuildDir(isForSimulator: Boolean, isUsingMetal: Boolean): Task {
val sim = if (isForSimulator) "simulator" else "device"
val renderer = if (isUsingMetal) "metal" else "gl"
return tasks.create("createIOS_${sim}_${renderer}") {
doLast {
getIOSCmakeBuildDir(isForSimulator, isUsingMetal).mkdirs()
}
}
}
/**
* @return A task for configuring the Cmake for building the IOS library with option [isForSimulator].
*/
fun getConfigureIOSBuildTask(isForSimulator: Boolean, isUsingMetal: Boolean): Task {
return tasks.create("configureIOS${if (isForSimulator) "Simulator" else "Device"}${if (isUsingMetal) "Metal" else "GL"}Building", Exec::class.java) {
dependsOn(generateWrapperEffekseer)
val createDirTask = createIOSCmakeBuildDir(isForSimulator, isUsingMetal)
dependsOn(createDirTask)
createDirTask.shouldRunAfter(generateWrapperEffekseer)
fun getIosJavaHomeFromLocalProperties(): String? {
return try {
val localProperties = Properties()
localProperties.load(FileInputStream(rootProject.file("local.properties")))
localProperties.getProperty("iOS_JAVA_HOME")
}
catch (e: Exception) {
logger.warn("Failed to find iOS_JAVA_HOME in local.properties. Defaulting to JAVA_HOME.")
null
}
}
val commandLineArgs = ArrayList<String>().apply {
add("cmake")
if (isForSimulator) {
add("-G")
add("Xcode")
}
add("-D")
add("iOS_JAVA_HOME=${getIosJavaHomeFromLocalProperties() ?: System.getenv("JAVA_HOME")}")
add("-D")
add("CMAKE_SYSTEM_NAME=iOS")
add("-D")
add("CMAKE_OSX_ARCHITECTURES=x86_64;arm64")
add("-D")
add("GDXSEER_RENDERER=${if (isUsingMetal) "Metal" else "GL"}")
add("-D")
add("USE_OPENGLES3=ON")
add("-B")
add(getIOSCmakeBuildDir(isForSimulator, isUsingMetal).absolutePath)
}
commandLine(commandLineArgs)
}
}
/**
* Calls cmake to configure for cmake building of the iOS library on device using GLES.
*/
val configureIOSDeviceGLBuilding = getConfigureIOSBuildTask(isForSimulator = false, isUsingMetal = false)
/**
* Calls cmake to configure for cmake building of the iOS library on simulator using GLES.
*/
val configureIOSSimulatorGLBuilding = getConfigureIOSBuildTask(isForSimulator = true, isUsingMetal = false)
/**
* Calls cmake to configure for cmake building of the iOS library on device using Metal.
*/
val configureIOSDeviceMetalBuilding = getConfigureIOSBuildTask(isForSimulator = false, isUsingMetal = true)
/**
* Calls cmake to configure for cmake building of the iOS library on simulator using Metal.
*/
val configureIOSSimulatorMetalBuilding = getConfigureIOSBuildTask(isForSimulator = true, isUsingMetal = true)
//endregion
//endregion
//region CMAKE Builds
/**
* Builds the desktop GDXseer C++ library.
*/
val buildDesktopNativeLibrary: Task by tasks.creating {
dependsOn(configureDesktopBuilding)
// Build the core jar
dependsOn(tasks.jar)
tasks.jar.get().shouldRunAfter(configureDesktopBuilding)
// Windows process source code
val windowsIncludeAlgorithmLine = "#include <algorithm>"
var hasProcessedWindowsNativeSourceCode = false
val windowsProcessFile = File("Effekseer/Dev/Cpp/Effekseer/Effekseer/Network/Effekseer.Session.cpp")
val windowsProcessNativeSourceCode: Task by tasks.creating {
doLast {
/*
if (org.gradle.internal.os.OperatingSystem.current().isWindows) {
val lines = windowsProcessFile.readLines()
val hasIncludeAlgorithmLine = lines.indexOf(windowsIncludeAlgorithmLine)
if (hasIncludeAlgorithmLine < 0) {
val stringBuilder = StringBuilder()
var hasFoundIncludeLine = false
var hasFoundEndOfIncludeLines = false
for (line in lines) {
var shouldIncludeAlgorithmLine = false
if (line.startsWith("#include")) {
hasFoundIncludeLine = true
}
else if (hasFoundIncludeLine && !hasFoundEndOfIncludeLines) {
hasFoundEndOfIncludeLines = true
shouldIncludeAlgorithmLine = true
}
if (shouldIncludeAlgorithmLine) {
stringBuilder.appendLine(windowsIncludeAlgorithmLine)
}
stringBuilder.appendLine(line)
}
windowsProcessFile.writeText(stringBuilder.toString())
hasProcessedWindowsNativeSourceCode = true
}
}
*/
}
}
dependsOn(windowsProcessNativeSourceCode)
windowsProcessNativeSourceCode.shouldRunAfter(tasks.jar)
// Build the GL C++ library
val cmakeDesktopNativeLibrary by tasks.creating(Exec::class.java) {
commandLine(
"cmake",
"--build", desktopCmakeBuildDir.absolutePath,
"--config", "Release"
)
}
dependsOn(cmakeDesktopNativeLibrary)
cmakeDesktopNativeLibrary.shouldRunAfter(windowsProcessNativeSourceCode)
// Window undo process source code
val windowsUndoProcessNativeSourceCode: Task by tasks.creating {
doLast {
if (hasProcessedWindowsNativeSourceCode) {
val lines = windowsProcessFile.readLines()
val stringBuilder = StringBuilder()
for (line in lines) {
if (line != windowsIncludeAlgorithmLine) {
stringBuilder.appendLine(line)
}
}
windowsProcessFile.writeText(stringBuilder.toString())
}
}
}
dependsOn(windowsUndoProcessNativeSourceCode)
windowsUndoProcessNativeSourceCode.shouldRunAfter(cmakeDesktopNativeLibrary)
// Copy the built native library into the native release directory
val copyDesktopNativeLibraryToNativeRelease by tasks.creating(Copy::class.java) {
when {
org.gradle.internal.os.OperatingSystem.current().isMacOsX -> {
from("$rootDir/cmake-macos/cpp/libGDXseer_Effekseer.dylib")
}
org.gradle.internal.os.OperatingSystem.current().isLinux -> {
from("$rootDir/cmake-linux/cpp/libGDXseer_Effekseer.so")
}
else -> {
from("$rootDir/cmake-windows/cpp/Release/GDXseer_Effekseer.dll")
}
}
into("$rootDir/release_native_libs/desktop")
}
dependsOn(copyDesktopNativeLibraryToNativeRelease)
copyDesktopNativeLibraryToNativeRelease.shouldRunAfter(windowsUndoProcessNativeSourceCode)
}
val ndkBuildCommand = if (org.gradle.internal.os.OperatingSystem.current().isWindows) "ndk-build.cmd" else "ndk-build"
/**
* Builds the Android GDXseer C++ library.
*/
val buildAndroidNativeLibrary by tasks.creating {
dependsOn(generateWrapperEffekseer)
// Build the core jar
dependsOn(tasks.jar)
tasks.jar.get().shouldRunAfter(generateWrapperEffekseer)
// Get the build project path
val androidBuildProjectPath = projectDir.absolutePath
val androidBuildScriptPath = File(projectDir, "cpp/Android_mk/Android.mk").absolutePath
val androidNativeLibOutPath = File(projectDir, "android-build").absolutePath
// Returns a new task for building the GDXseer Android native library for the given CPU architecture
fun buildForArch(arch: String): Task {
return tasks.create("buildAndroidNativeLibrary_$arch") {
val clean = tasks.create("buildAndroidNativeLibrary_${arch}_clean", Exec::class.java) {
// Clean
commandLine(
ndkBuildCommand, "clean",
"APP_BUILD_SCRIPT=$androidBuildScriptPath",
"NDK_PROJECT_PATH=$androidBuildProjectPath",
"NDK_APPLICATION_MK=cpp/Android_mk/${arch}.mk"
)
}
dependsOn(clean)
val build = tasks.create("buildAndroidNativeLibrary_${arch}_build", Exec::class.java) {
// Build the GL C++ library
commandLine(
ndkBuildCommand, "-j4",
"APP_BUILD_SCRIPT=$androidBuildScriptPath",
"NDK_PROJECT_PATH=$androidBuildProjectPath",
"NDK_APPLICATION_MK=cpp/Android_mk/${arch}.mk",
"NDK_OUT=$androidNativeLibOutPath",
"NDK_LIBS_OUT=$androidNativeLibOutPath/libs/"
)
}
dependsOn(build)
build.shouldRunAfter(clean)
}
}
val build_x86 = buildForArch("x86")
dependsOn(build_x86)
build_x86.shouldRunAfter(tasks.jar.get())
val build_x86_64 = buildForArch("x86_64")
dependsOn(build_x86_64)
build_x86_64.shouldRunAfter(build_x86)
val build_armeabi_v7a = buildForArch("armeabi-v7a")
dependsOn(build_armeabi_v7a)
build_armeabi_v7a.shouldRunAfter(build_x86_64)
val build_arm64_v8a = buildForArch("arm64-v8a")
dependsOn(build_arm64_v8a)
build_arm64_v8a.shouldRunAfter(build_armeabi_v7a)
// Copy the built native library into the native release directory
val copyAndroidNativeLibraryToNativeRelease by tasks.creating(Copy::class.java) {
from("$rootDir/android-build/libs")
into("$rootDir/release_native_libs/android")
}
dependsOn(copyAndroidNativeLibraryToNativeRelease)
copyAndroidNativeLibraryToNativeRelease.shouldRunAfter(build_arm64_v8a)
}
/**
* @return A task for building the IOS library with options [isForSimulator] and [isUsingMetal].
*/
fun getBuildNativeIOSTask(isForSimulator: Boolean, isUsingMetal: Boolean): Task {
val taskNamePostfix = "IOS${if (isForSimulator) "Simulator" else "Device"}${if (isUsingMetal) "Metal" else "GL"}NativeLibrary"
return tasks.create("build$taskNamePostfix", Exec::class.java) {
val configureIOSBuildingTask = if (isForSimulator) {
if (isUsingMetal) configureIOSSimulatorMetalBuilding else configureIOSSimulatorGLBuilding
}
else {
if (isUsingMetal) configureIOSDeviceMetalBuilding else configureIOSDeviceGLBuilding
}
dependsOn(configureIOSBuildingTask)
// Build the core jar
dependsOn(tasks.jar)
tasks.jar.get().shouldRunAfter(configureIOSBuildingTask)
// Build the C++ library
val cmakeArgs = listOf(
"cmake",
"--build", getIOSCmakeBuildDir(isForSimulator, isUsingMetal).absolutePath,
"--config", "Release"
) + (if (isForSimulator) listOf("--", "-sdk", "iphonesimulator") else emptyList())
commandLine(cmakeArgs)
}
}
/**
* Builds the iOS GL GDXseer C++ library for use on a iOS device. Also signs the library.
*/
val buildIOSDeviceGLNativeLibrary = getBuildNativeIOSTask(isForSimulator = false, isUsingMetal = false)
/**
* Builds the iOS GL GDXseer C++ library for use on a iOS simulator.
*/
val buildIOSSimulatorGLNativeLibrary = getBuildNativeIOSTask(isForSimulator = true, isUsingMetal = false)
/**
* @return A task for building the IOS library frameworks with option [isUsingMetal].
*/
fun getBuildNativeIOSFrameworks(isUsingMetal: Boolean, deviceBuildSharedLibraryTask: Task, simulatorBuildSharedLibraryTask: Task): Task {
val renderer = if (isUsingMetal) "Metal" else "GL"
return tasks.create("buildIOS${renderer}Frameworks") {
dependsOn(deviceBuildSharedLibraryTask)
dependsOn(simulatorBuildSharedLibraryTask)
val cleanIOSFrameworks = tasks.create("cleanIOS${renderer}Frameworks") {
doLast {
delete("./GDXseer-ios-$renderer/build")
delete("./GDXseer-ios-$renderer/build_device")
delete("./GDXseer-ios-$renderer/build_simulator")
}
}
dependsOn(cleanIOSFrameworks)
cleanIOSFrameworks.mustRunAfter(deviceBuildSharedLibraryTask).mustRunAfter(simulatorBuildSharedLibraryTask)
// Device framework
val buildIOSDeviceFramework = tasks.create("buildIOS${renderer}DeviceFramework", Exec::class.java) {
commandLine(
"xcodebuild",
"-project", "./GDXseer-ios-$renderer/GDXseer_device.xcodeproj",
"-scheme", "GDXseer",
"-configuration", "Release",
"-destination=\"generic/platform=iOS\"",
"-derivedDataPath", "./GDXseer-ios-$renderer/build_device",
"-archivePath", "./GDXseer-ios-$renderer/build_device",
"ONLY_ACTIVE_ARCH=NO",
"SKIP_INTSALL=NO",
"BUILD_LIBRARY_FOR_DISTRBUTION=YES",
"-sdk", "iphoneos"
)
}
dependsOn(buildIOSDeviceFramework)
buildIOSDeviceFramework.mustRunAfter(cleanIOSFrameworks)
// Simulator framework
val buildIOSSimulatorFramework = tasks.create("buildIOS${renderer}SimulatorFramework", Exec::class.java) {
commandLine(
"xcodebuild",
"-project", "./GDXseer-ios-$renderer/GDXseer_simulator.xcodeproj",
"-scheme", "GDXseer",
"-configuration", "Release",
"-destination=\"generic/platform=iOS Simulator\"",
"-derivedDataPath", "./GDXseer-ios-$renderer/build_simulator",
"-archivePath", "./GDXseer-ios-$renderer/build_simulator",
"ONLY_ACTIVE_ARCH=NO",
"SKIP_INTSALL=NO",
"BUILD_LIBRARY_FOR_DISTRBUTION=YES",
"-sdk", "iphonesimulator"
)
}
dependsOn(buildIOSSimulatorFramework)
buildIOSSimulatorFramework.mustRunAfter(cleanIOSFrameworks)
// XCFramework of both the device and simulator frameworks
val buildIOSXCFramework = tasks.create("buildIOS${renderer}XCFramework", Exec::class.java) {
commandLine(
"xcodebuild", "-create-xcframework",
"-framework", "./GDXseer-ios-$renderer/build_device/Build/Products/Release-iphoneos/GDXseer.framework",
"-framework", "./GDXseer-ios-$renderer/build_simulator/Build/Products/Release-iphonesimulator/GDXseer.framework",
"-output", "./GDXseer-ios-$renderer/build/GDXseer.xcframework"
)
}
dependsOn(buildIOSXCFramework)
buildIOSXCFramework.mustRunAfter(buildIOSDeviceFramework).mustRunAfter(buildIOSSimulatorFramework)
// Get the code sign identity
fun getCodeSignIdentityFromLocalProperties(): String? {
return try {
val localProperties = Properties()
localProperties.load(FileInputStream(rootProject.file("local.properties")))
localProperties.getProperty("iOS_CODE_SIGN_IDENTITY")
}
catch (e: Exception) {
logger.warn("Failed to find iOS_CODE_SIGN_IDENTITY in local.properties. Defaulting to Adhoc signing.")
null
}
}
val codeSignIdentity = getCodeSignIdentityFromLocalProperties() ?: "-"
// Sign the built XCFramework
val signIOSXCFramework = tasks.create("signIOS${renderer}XCFramework", Exec::class.java) {
commandLine(
"codesign", "-s", codeSignIdentity, "./GDXseer-ios-$renderer/build/GDXseer.xcframework"
)
}
dependsOn(signIOSXCFramework)
signIOSXCFramework.mustRunAfter(buildIOSXCFramework)
// Sign the built XCFramework
val signIOSSharedLib = tasks.create("signIOS${renderer}SharedLib", Exec::class.java) {
commandLine(
"codesign", "-s", codeSignIdentity, "./GDXseer-ios-$renderer/build/GDXseer.xcframework/ios-arm64/GDXseer.framework/Frameworks/libGDXseer_Effekseer.dylib"
)
}
dependsOn(signIOSSharedLib)
signIOSSharedLib.mustRunAfter(signIOSXCFramework)
// Copy the built framework into the native release directory
val copyIOSXCFrameworkToNativeRelease = tasks.create("copyIOS${renderer}XCFrameworkToNativeRelease", Copy::class.java) {
from("$rootDir/GDXseer-ios-$renderer/build/GDXseer.xcframework")
into("$rootDir/release_native_libs/ios/$renderer/GDXseer.xcframework")
}
dependsOn(copyIOSXCFrameworkToNativeRelease)
copyIOSXCFrameworkToNativeRelease.shouldRunAfter(signIOSSharedLib)
}
}
/**
* Builds the device and simulator GL library for iOS, and then their corresponding unsigned frameworks, and finally from that the signed xcframework.
*/
val buildIOSGLFrameworks: Task = getBuildNativeIOSFrameworks(false, buildIOSDeviceGLNativeLibrary, buildIOSSimulatorGLNativeLibrary)
/**
* Builds the iOS Metal GDXseer C++ library for use on a iOS device. Also signs the library.
*/
val buildIOSDeviceMetalNativeLibrary = getBuildNativeIOSTask(isForSimulator = false, isUsingMetal = true)
/**
* Builds the iOS Metal GDXseer C++ library for use on a iOS simulator.
*/
val buildIOSSimulatorMetalNativeLibrary = getBuildNativeIOSTask(isForSimulator = true, isUsingMetal = true)
/**
* Builds the device and simulator Metal library for iOS, and then their corresponding unsigned frameworks, and finally from that the signed xcframework.
*/
val buildIOSMetalFrameworks: Task = getBuildNativeIOSFrameworks(true, buildIOSDeviceMetalNativeLibrary, buildIOSSimulatorMetalNativeLibrary)
//endregion
//region Final Builds
/**
* Builds the C++ and Jar for the desktop library.
*/
val buildDesktopLibrary by tasks.creating {
dependsOn(":GDXseer-desktop:jar")
}
/**
* Builds the C++ and Jar for the Android library.
*/
val buildAndroidLibrary by tasks.creating {
dependsOn(":GDXseer-android:jar")
}
/**
* Builds the C++ and Jar for the iOS GL library.
*/
val buildIOSGLLibrary by tasks.creating {
dependsOn(":GDXseer-ios-GL:jar")
}
/**
* Builds the C++ and Jar for the iOS Metal library.
*/
val buildIOSMetalLibrary by tasks.creating {
dependsOn(":GDXseer-ios-Metal:jar")
}
//endregion
//region Maven Publishing
apply(from = "gdxseer_publishing.build.gradle.kts")
publishing {
publications {
getByName(project.name, MavenPublication::class) {
pom {
description.set("The base GDXseer library which allows for Effekseer to be used in libGDX projects. This is used by all specific implementations for each platform/renderer.")
}
}
}
}
//endregion