-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
172 lines (153 loc) · 5.48 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
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
plugins {
kotlin("multiplatform")
}
group = "dev.thibault"
version = "1.0.0-alpha01"
val mainFun = "dev.tclement.imgrecolor.main"
val mainClass = "dev.tclement.imgrecolor.MainKt"
repositories {
mavenCentral()
}
kotlin {
val nativeTargets = setOf(
//macosX64(),
linuxX64(),
//mingwX64(),
)
jvm {
compilations.getByName("main") {
kotlinOptions.jvmTarget = "11"
}
}
nativeTargets.forEach {
it.compilations.getByName("main") {
cinterops {
val stbi by creating
val lodepng by creating
val curl by creating
}
}
it.binaries {
executable {
entryPoint = mainFun
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(KotlinX.coroutines.core)
implementation("com.github.ajalt.clikt:clikt:_")
implementation("com.soywiz.korlibs.klock:klock:_")
implementation("dev.kdrag0n:colorkt:_")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val nativeMain by creating {
dependsOn(commonMain)
}
val nativeTest by creating {
dependsOn(commonTest)
}
if (nativeTargets.find { it.name == "linuxX64" } != null) {
val linuxX64Main by getting {
dependsOn(nativeMain)
}
val linuxX64Test by getting {
dependsOn(nativeTest)
}
}
if (nativeTargets.find { it.name == "mingwX64" } != null) {
val mingwX64Main by getting {
dependsOn(nativeMain)
}
val mingwX64Test by getting {
dependsOn(nativeTest)
}
}
if (nativeTargets.find { it.name == "macosX64" } != null) {
val macosX64Main by getting {
dependsOn(nativeMain)
}
val macosX64Test by getting {
dependsOn(nativeTest)
}
}
}
}
tasks {
val clean by getting {
doLast {
remove("src/nativeInterop/cinterop/lodepng/build")
}
}
val jvmJar by getting(Jar::class) {
doFirst {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
val main by kotlin.jvm().compilations.getting
manifest {
attributes(
"Main-Class" to mainClass,
)
}
from({
main.runtimeDependencyFiles.files.map { if (it.isDirectory) it else zipTree(it) }
})
}
}
val copyLodepngFiles by creating(Copy::class) {
inputs.files("src/nativeInterop/cinterop/lodepng/upstream")
outputs.files("src/nativeInterop/cinterop/lodepng/lodepng.c", "src/nativeInterop/cinterop/lodepng/lodepng.h")
rename {
it.replace(".cpp", ".c")
}
from("src/nativeInterop/cinterop/lodepng/upstream")
into("src/nativeInterop/cinterop/lodepng")
include("lodepng.cpp", "lodepng.h")
}
val createLodepngDefFile by creating(Task::class) {
inputs.files("\"src/nativeInterop/cinterop/lodepng/upstream")
outputs.files("src/nativeInterop/cinterop/lodepng.def")
file("src/nativeInterop/cinterop/lodepng.def").writeText("""
package = lvandeve.lodepng
headers = $rootDir/src/nativeInterop/cinterop/lodepng/lodepng.h
staticLibraries = lodepng.a
libraryPaths = $rootDir/src/nativeInterop/cinterop/lodepng/build/out/
compilerOpts = -DLODEPNG_NO_COMPILE_DECODER
""".trimIndent())
}
val buildLodepngStaticObject by creating(Exec::class) {
dependsOn(copyLodepngFiles)
inputs.dir("src/nativeInterop/cinterop/lodepng/upstream")
outputs.dir("src/nativeInterop/cinterop/lodepng/build/obj")
delete("src/nativeInterop/cinterop/lodepng/build/obj")
mkdir("src/nativeInterop/cinterop/lodepng/build/obj/")
commandLine("gcc", "-Wall", "-Werror", "-Wextra", "-c", "src/nativeInterop/cinterop/lodepng/lodepng.c", "-o", "src/nativeInterop/cinterop/lodepng/build/obj/lodepng.o")
}
val buildLodepngStaticLib by creating(Exec::class) {
dependsOn(buildLodepngStaticObject)
inputs.dir("src/nativeInterop/cinterop/lodepng/upstream")
outputs.dir("src/nativeInterop/cinterop/lodepng/build/out")
delete("src/nativeInterop/cinterop/lodepng/build/out")
mkdir("src/nativeInterop/cinterop/lodepng/build/out/")
commandLine("ar", "rcs", "src/nativeInterop/cinterop/lodepng/build/out/lodepng.a", "src/nativeInterop/cinterop/lodepng/build/obj/lodepng.o")
}
val createStbiDefFile by creating(Task::class) {
file("src/nativeInterop/cinterop/stbi.def").writeText("""
package = nothings.stbi
headers = $rootDir/src/nativeInterop/cinterop/stb/stb_image.h
compilerOpts = -DSTB_IMAGE_IMPLEMENTATION -DSTB_IMAGE_STATIC
""".trimIndent())
}
withType(CInteropProcess::class) {
when {
name.contains("lodepng", ignoreCase = true) -> dependsOn(buildLodepngStaticLib, createLodepngDefFile)
name.contains("stbi", ignoreCase = true) -> dependsOn(createStbiDefFile)
}
}
}