diff options
author | nea <nea@nea.moe> | 2023-06-08 03:47:38 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-06-08 03:47:38 +0200 |
commit | d423203d960e6e2340798f00f907d2b1271c3d89 (patch) | |
tree | 007846bff6390c7f3648f8a5b3ce5e071c024250 /nosession_libc/build.gradle.kts | |
parent | f6b449e65d050b321abf0e54826ec48c0d993b2a (diff) | |
download | NoSession-d423203d960e6e2340798f00f907d2b1271c3d89.tar.gz NoSession-d423203d960e6e2340798f00f907d2b1271c3d89.tar.bz2 NoSession-d423203d960e6e2340798f00f907d2b1271c3d89.zip |
Use kotlin buildscript
Diffstat (limited to 'nosession_libc/build.gradle.kts')
-rw-r--r-- | nosession_libc/build.gradle.kts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/nosession_libc/build.gradle.kts b/nosession_libc/build.gradle.kts new file mode 100644 index 0000000..0f64343 --- /dev/null +++ b/nosession_libc/build.gradle.kts @@ -0,0 +1,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) +} |