blob: 0f64343c0405aa5464ccfd22e5e56e07a9164a66 (
plain)
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
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName
plugins {
`cpp-library`
`java-base`
}
val lib by configurations.creating
library {
linkage.set(listOf(Linkage.SHARED))
}
project.afterEvaluate {
tasks.withType(CppCompile::class) {
val javaHome = rootProject.the<JavaToolchainService>()
.compilerFor(rootProject.the<JavaPluginExtension>().toolchain)
.map { it.metadata.installationPath.asFile }
val includeDir = javaHome.map { it.resolve("include") }
val os = targetPlatform.get().operatingSystem
compilerArgs.add("-I")
compilerArgs.add(includeDir.map { it.absolutePath })
compilerArgs.add("-I")
compilerArgs.add(includeDir.map {
it.resolve(
when {
os.isMacOsX -> "darwin"
os.isLinux -> "linux"
os.isWindows -> "win32"
os.isFreeBSD -> "freebsd"
else -> TODO("Unsupported operating system")
}
).absolutePath
})
if (os.isLinux) {
compilerArgs.add("-D_FILE_OFFSET_BITS=64")
}
if (os.isMacOsX) {
compilerArgs.add("-mmacosx-version-min=10.4")
}
}
tasks.withType(AbstractLinkTask::class) {
if (targetPlatform.get().operatingSystem.isMacOsX)
linkerArgs.add("-mmacosx-version-min=10.4")
}
val linkRelease: AbstractLinkTask by tasks
val archive by tasks.creating(Zip::class) {
archivesName.set("archive.jar")
destinationDirectory.set(layout.buildDirectory.dir("libs"))
from(linkRelease.linkedFile) {
val targetPlatform = linkRelease.targetPlatform.get()
into("native/" + when(val arch = targetPlatform.architecture.name) {
"x86-64" -> "amd64"
else -> arch
} + "/" +targetPlatform.operatingSystem.name)
}
}
artifacts.add(lib.name, archive)
}
|