-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
57 lines (47 loc) · 1.81 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
plugins {
kotlin("multiplatform") version "1.8.22"
}
group = "com.russellbanks"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
jcenter()
}
val os = org.gradle.internal.os.OperatingSystem.current()!!
kotlin {
when {
os.isWindows -> mingwX64("libui")
os.isMacOsX -> macosX64("libui")
os.isLinux -> linuxX64("libui")
else -> throw Error("Unknown host")
}.binaries.executable {
if (os.isWindows) {
windowsResources("hello.rc")
linkerOpts("-mwindows")
}
}
val libuiMain by sourceSets.getting {
dependencies {
// Kotlin LibUI - https://github.com/msink/kotlin-libui
implementation(libs.libui)
// Kotlinx DateTime - https://github.com/Kotlin/kotlinx-datetime
implementation(libs.kotlinx.datetime)
}
}
}
fun org.jetbrains.kotlin.gradle.plugin.mpp.Executable.windowsResources(rcFileName: String) {
val taskName = linkTaskName.replaceFirst("link", "windres")
val inFile = compilation.defaultSourceSet.resources.sourceDirectories.singleFile.resolve(rcFileName)
val outFile = buildDir.resolve("processedResources/$taskName.res")
val windresTask = tasks.create<Exec>(taskName) {
val konanUserDir = System.getenv("KONAN_DATA_DIR") ?: "${System.getProperty("user.home")}/.konan"
val konanLlvmDir = "$konanUserDir/dependencies/msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin"
inputs.file(inFile)
outputs.file(outFile)
commandLine("$konanLlvmDir/windres", inFile, "-D_${buildType.name}", "-O", "coff", "-o", outFile)
environment("PATH", "$konanLlvmDir;${System.getenv("PATH")}")
dependsOn(compilation.compileKotlinTask)
}
linkTask.dependsOn(windresTask)
linkerOpts(outFile.toString())
}