diff --git a/samples/csvparser/build.gradle.kts b/samples/csvparser/build.gradle.kts index 0be263ea749..2b60facd6c8 100644 --- a/samples/csvparser/build.gradle.kts +++ b/samples/csvparser/build.gradle.kts @@ -1,23 +1,20 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset - plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - kotlin { - targetFromPreset(hostPreset, "csvParser") { + // Determine host preset. + val hostOs = System.getProperty("os.name") + + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("csvParser") + hostOs == "Linux" -> linuxX64("csvParser") + hostOs.startsWith("Windows") -> mingwX64("csvParser") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + hostTarget.apply { binaries { executable { entryPoint = "sample.csvparser.main" @@ -25,4 +22,4 @@ kotlin { } } } -} \ No newline at end of file +} diff --git a/samples/curl/build.gradle.kts b/samples/curl/build.gradle.kts index d8a1391ba3c..7b080269538 100644 --- a/samples/curl/build.gradle.kts +++ b/samples/curl/build.gradle.kts @@ -1,6 +1,3 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset -import org.jetbrains.kotlin.konan.target.KonanTarget.* - plugins { kotlin("multiplatform") } @@ -11,26 +8,26 @@ repositories { maven("file://$localRepo") } -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64") kotlin { - targetFromPreset(hostPreset, "curl") { + // Determine host preset. + val hostOs = System.getProperty("os.name") + val isMingwX64 = hostOs.startsWith("Windows") + + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("curl") + hostOs == "Linux" -> linuxX64("curl") + isMingwX64 -> mingwX64("curl") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + hostTarget.apply { binaries { executable { entryPoint = "sample.curl.main" - if (hostPreset.konanTarget == MINGW_X64) { + if (isMingwX64) { // Add lib path to `libcurl` and its dependencies: linkerOpts(mingwPath.resolve("lib").toString()) runTask?.environment("PATH" to mingwPath.resolve("bin")) diff --git a/samples/echoServer/build.gradle.kts b/samples/echoServer/build.gradle.kts index 6c7bb70230c..da4ac5c56ae 100644 --- a/samples/echoServer/build.gradle.kts +++ b/samples/echoServer/build.gradle.kts @@ -4,25 +4,31 @@ plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - // Add two additional presets for Raspberry Pi. val raspberryPiPresets: List = listOf("linuxArm32Hfp", "linuxArm64").map { kotlin.presets[it] as KotlinNativeTargetPreset } kotlin { - targetFromPreset(hostPreset, "echoServer") { + // Determine host preset. + val hostOs = System.getProperty("os.name") + + // Create a target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("echoServer") + hostOs == "Linux" -> linuxX64("echoServer") + hostOs.startsWith("Windows") -> mingwX64("echoServer") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + // Create cross-targets. + val raspberryPiTargets = raspberryPiPresets.map { preset -> + val targetName = "echoServer${preset.name.capitalize()}" + targetFromPreset(preset, targetName) {} + } + + // Configure executables for all targets. + configure(raspberryPiTargets + listOf(hostTarget)) { binaries { executable { entryPoint = "sample.echoserver.main" @@ -31,18 +37,6 @@ kotlin { } } - raspberryPiPresets.forEach { preset -> - val targetName = "echoServer${preset.name.capitalize()}" - targetFromPreset(preset, targetName) { - binaries { - executable { - entryPoint = "sample.echoserver.main" - runTask?.args(3000) - } - } - } - } - sourceSets { val echoServerMain by getting raspberryPiPresets.forEach { preset -> diff --git a/samples/gitchurn/build.gradle.kts b/samples/gitchurn/build.gradle.kts index 1c6a1d2577c..ae82dcb7f97 100644 --- a/samples/gitchurn/build.gradle.kts +++ b/samples/gitchurn/build.gradle.kts @@ -1,30 +1,27 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset -import org.jetbrains.kotlin.konan.target.KonanTarget.* - plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64") kotlin { - targetFromPreset(hostPreset, "gitChurn") { + // Determine host preset. + val hostOs = System.getProperty("os.name") + val isMingwX64 = hostOs.startsWith("Windows") + + // Create a target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("gitChurn") + hostOs == "Linux" -> linuxX64("gitChurn") + isMingwX64 -> mingwX64("gitChurn") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + hostTarget.apply { binaries { executable { entryPoint = "sample.gitchurn.main" - if (hostPreset.konanTarget == MINGW_X64) { + if (isMingwX64) { linkerOpts(mingwPath.resolve("lib").toString()) runTask?.environment("PATH" to mingwPath.resolve("bin")) } @@ -33,10 +30,10 @@ kotlin { } compilations["main"].cinterops { val libgit2 by creating { - when (hostPreset.konanTarget) { - MACOS_X64 -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include") - LINUX_X64 -> includeDirs.headerFilterOnly("/usr/include") - MINGW_X64 -> includeDirs.headerFilterOnly(mingwPath.resolve("include")) + when (preset) { + presets["macosX64"] -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include") + presets["linuxX64"] -> includeDirs.headerFilterOnly("/usr/include") + presets["mingwX64"] -> includeDirs.headerFilterOnly(mingwPath.resolve("include")) } } } diff --git a/samples/globalState/build.gradle.kts b/samples/globalState/build.gradle.kts index e7cc821fd2a..6cb4b781a53 100644 --- a/samples/globalState/build.gradle.kts +++ b/samples/globalState/build.gradle.kts @@ -1,23 +1,20 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset - plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") +kotlin { + // Determine host preset. + val hostOs = System.getProperty("os.name") -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("globalState") + hostOs == "Linux" -> linuxX64("globalState") + hostOs.startsWith("Windows") -> mingwX64("globalState") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } -kotlin { - targetFromPreset(hostPreset, "globalState") { + hostTarget.apply { binaries { executable { entryPoint = "sample.globalstate.main" diff --git a/samples/gtk/build.gradle.kts b/samples/gtk/build.gradle.kts index de104bfcec8..dc70e18b128 100644 --- a/samples/gtk/build.gradle.kts +++ b/samples/gtk/build.gradle.kts @@ -1,30 +1,27 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset -import org.jetbrains.kotlin.konan.target.KonanTarget.* - plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64") kotlin { - targetFromPreset(hostPreset, "gtk") { + // Determine host preset. + val hostOs = System.getProperty("os.name") + val isMingwX64 = hostOs.startsWith("Windows") + + // Create a target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("gtk") + hostOs == "Linux" -> linuxX64("gtk") + isMingwX64 -> mingwX64("gtk") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + hostTarget.apply { binaries { executable { entryPoint = "sample.gtk.main" - if (hostPreset.konanTarget == MINGW_X64) { + if (isMingwX64) { linkerOpts(mingwPath.resolve("lib").toString()) runTask?.environment("PATH" to mingwPath.resolve("bin")) } @@ -32,8 +29,8 @@ kotlin { } compilations["main"].cinterops { val gtk3 by creating { - when (hostPreset.konanTarget) { - MACOS_X64, LINUX_X64 -> { + when (preset) { + presets["macosX64"], presets["linuxX64"] -> { listOf("/opt/local/include", "/usr/include", "/usr/local/include").forEach { includeDirs( "$it/atk-1.0", @@ -51,7 +48,7 @@ kotlin { "/usr/local/lib/glib-2.0/include" ) } - MINGW_X64 -> { + presets["mingwX64"] -> { listOf( "/include/atk-1.0", "/include/gdk-pixbuf-2.0", diff --git a/samples/libcurl/build.gradle.kts b/samples/libcurl/build.gradle.kts index 7618113d0fc..bf1456005f8 100644 --- a/samples/libcurl/build.gradle.kts +++ b/samples/libcurl/build.gradle.kts @@ -1,6 +1,3 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset -import org.jetbrains.kotlin.konan.target.KonanTarget.* - plugins { kotlin("multiplatform") `maven-publish` @@ -21,28 +18,28 @@ val cleanLocalRepo by tasks.creating(Delete::class) { delete(localRepo) } -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64") kotlin { - targetFromPreset(hostPreset, "libcurl") { + + // Determine host preset. + val hostOs = System.getProperty("os.name") + + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("libcurl") + hostOs == "Linux" -> linuxX64("libcurl") + hostOs.startsWith("Windows") -> mingwX64("libcurl") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + hostTarget.apply { compilations["main"].cinterops { val libcurl by creating { - when (hostPreset.konanTarget) { - MACOS_X64 -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include") - LINUX_X64 -> includeDirs.headerFilterOnly("/usr/include", "/usr/include/x86_64-linux-gnu") - MINGW_X64 -> includeDirs.headerFilterOnly(mingwPath.resolve("/include")) + when (preset) { + presets["macosX64"] -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include") + presets["linuxX64"] -> includeDirs.headerFilterOnly("/usr/include", "/usr/include/x86_64-linux-gnu") + presets["mingwX64"] -> includeDirs.headerFilterOnly(mingwPath.resolve("/include")) } } } diff --git a/samples/nonBlockingEchoServer/build.gradle.kts b/samples/nonBlockingEchoServer/build.gradle.kts index 60e4c06a994..46449d22811 100644 --- a/samples/nonBlockingEchoServer/build.gradle.kts +++ b/samples/nonBlockingEchoServer/build.gradle.kts @@ -1,23 +1,20 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset - plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") +kotlin { + // Determine host preset. + val hostOs = System.getProperty("os.name") -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - // Windows is not supported - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("nonBlockingEchoServer") + hostOs == "Linux" -> linuxX64("nonBlockingEchoServer") + hostOs.startsWith("Windows") -> mingwX64("nonBlockingEchoServer") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } -kotlin { - targetFromPreset(hostPreset, "nonBlockingEchoServer") { + hostTarget.apply { binaries { executable { entryPoint = "sample.nbechoserver.main" diff --git a/samples/tensorflow/build.gradle.kts b/samples/tensorflow/build.gradle.kts index ef818470daf..e2c18948375 100644 --- a/samples/tensorflow/build.gradle.kts +++ b/samples/tensorflow/build.gradle.kts @@ -1,29 +1,27 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - // Windows is not supported - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - val kotlinNativeDataPath = System.getenv("KONAN_DATA_DIR")?.let { File(it) } ?: File(System.getProperty("user.home")).resolve(".konan") val tensorflowHome = kotlinNativeDataPath.resolve("third-party/tensorflow") kotlin { - targetFromPreset(hostPreset, "tensorflow") { + // Determine host preset. + val hostOs = System.getProperty("os.name") + + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("tensorflow") + hostOs == "Linux" -> linuxX64("tensorflow") + // Windows is not supported + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + hostTarget.apply { binaries { executable { entryPoint = "sample.tensorflow.main" diff --git a/samples/tetris/build.gradle.kts b/samples/tetris/build.gradle.kts index 51c7c39ce1c..704b142be12 100644 --- a/samples/tetris/build.gradle.kts +++ b/samples/tetris/build.gradle.kts @@ -1,7 +1,5 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType -import org.jetbrains.kotlin.konan.target.KonanTarget.* plugins { kotlin("multiplatform") @@ -19,8 +17,6 @@ val isRaspberryPiBuild = val isMingwX86Build = isWindows && project.findProperty("tetris.mingwX86.build")?.toString()?.toBoolean() == true -val hostPreset = determinePreset() - val winCompiledResourceFile = buildDir.resolve("compiledWindowsResources/Tetris.res") val kotlinNativeDataPath = System.getenv("KONAN_DATA_DIR")?.let { File(it) } @@ -32,14 +28,14 @@ else File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64") kotlin { - targetFromPreset(hostPreset, "tetris") { + createRequestedTarget("tetris").apply { binaries { executable { entryPoint = "sample.tetris.main" - when (hostPreset.konanTarget) { - MACOS_X64 -> linkerOpts("-L/opt/local/lib", "-L/usr/local/lib", "-lSDL2") - LINUX_X64 -> linkerOpts("-L/usr/lib64", "-L/usr/lib/x86_64-linux-gnu", "-lSDL2") - MINGW_X64, MINGW_X86 -> linkerOpts( + when (preset) { + presets["macosX64"] -> linkerOpts("-L/opt/local/lib", "-L/usr/local/lib", "-lSDL2") + presets["linuxX64"] -> linkerOpts("-L/usr/lib64", "-L/usr/lib/x86_64-linux-gnu", "-lSDL2") + presets["mingwX64"], presets["mingwX86"] -> linkerOpts( winCompiledResourceFile.toString(), mingwPath.resolve("lib").toString(), "-Wl,-Bstatic", @@ -54,7 +50,7 @@ kotlin { "-lsetupapi", "-mwindows" ) - LINUX_ARM32_HFP -> linkerOpts("-lSDL2") + presets["linuxArm32Hfp"] -> linkerOpts("-lSDL2") } runTask?.workingDir(project.provider { val tetris: KotlinNativeTarget by kotlin.targets @@ -65,18 +61,18 @@ kotlin { compilations["main"].cinterops { val sdl by creating { - when (hostPreset.konanTarget) { - MACOS_X64 -> includeDirs("/opt/local/include/SDL2", "/usr/local/include/SDL2") - LINUX_X64 -> includeDirs("/usr/include/SDL2") - MINGW_X64, MINGW_X86 -> includeDirs(mingwPath.resolve("/include/SDL2")) - LINUX_ARM32_HFP -> includeDirs(kotlinNativeDataPath.resolve("dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2")) + when (preset) { + presets["macosX64"] -> includeDirs("/opt/local/include/SDL2", "/usr/local/include/SDL2") + presets["linuxX64"] -> includeDirs("/usr/include/SDL2") + presets["mingwX64"], presets["mingwX86"] -> includeDirs(mingwPath.resolve("/include/SDL2")) + presets["linuxArm32Hfp"] -> includeDirs(kotlinNativeDataPath.resolve("dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2")) } } } } } -val compileWindowsResources: Exec? = if (hostPreset.konanTarget == MINGW_X64 || hostPreset.konanTarget == MINGW_X86) { +val compileWindowsResources: Exec? = if (isWindows) { val compileWindowsResources: Exec by tasks.creating(Exec::class) { val windresDir = if (isMingwX86Build) kotlinNativeDataPath.resolve("dependencies/msys2-mingw-w64-i686-gcc-7.4.0-clang-llvm-6.0.1/bin") @@ -117,19 +113,17 @@ afterEvaluate { } } -fun determinePreset(): KotlinNativeTargetPreset { - val preset = when { - isRaspberryPiBuild -> kotlin.presets["linuxArm32Hfp"] as KotlinNativeTargetPreset // aka RaspberryPi - isMingwX86Build -> kotlin.presets["mingwX86"] as KotlinNativeTargetPreset - else -> return when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" +fun createRequestedTarget(name: String): KotlinNativeTarget = with(kotlin) { + return when { + isRaspberryPiBuild -> linuxArm32Hfp(name) // aka RaspberryPi + isMingwX86Build -> mingwX86(name) + else -> when { + hostOs == "Mac OS X" -> macosX64(name) + hostOs == "Linux" -> linuxX64(name) + hostOs.startsWith("Windows") -> mingwX64(name) else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") - }.let { - kotlin.presets[it] as KotlinNativeTargetPreset } + }.also { + println("$project has been configured for ${it.preset?.name} platform.") } - println("$project has been configured for ${preset.name} platform.") - return preset } diff --git a/samples/torch/build.gradle.kts b/samples/torch/build.gradle.kts index 754478eda0c..80c4815e07a 100644 --- a/samples/torch/build.gradle.kts +++ b/samples/torch/build.gradle.kts @@ -1,5 +1,4 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType plugins { @@ -11,20 +10,19 @@ val kotlinNativeDataPath = System.getenv("KONAN_DATA_DIR")?.let { File(it) } val torchHome = kotlinNativeDataPath.resolve("third-party/torch") -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - // Windows is not supported - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - kotlin { - targetFromPreset(hostPreset, "torch") { + // Determine host preset. + val hostOs = System.getProperty("os.name") + + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("torch") + hostOs == "Linux" -> linuxX64("torch") + // Windows is not supported + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + hostTarget.apply { binaries { executable { entryPoint = "sample.torch.main" diff --git a/samples/videoplayer/build.gradle.kts b/samples/videoplayer/build.gradle.kts index 95e9329b3b8..e6405844589 100644 --- a/samples/videoplayer/build.gradle.kts +++ b/samples/videoplayer/build.gradle.kts @@ -1,51 +1,47 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset -import org.jetbrains.kotlin.konan.target.KonanTarget.* - plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") - -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} - val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64") kotlin { - targetFromPreset(hostPreset, "videoPlayer") { + // Determine host preset. + val hostOs = System.getProperty("os.name") + + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("videoPlayer") + hostOs == "Linux" -> linuxX64("videoPlayer") + hostOs.startsWith("Windows") -> mingwX64("videoPlayer") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } + + hostTarget.apply { binaries { executable { entryPoint = "sample.videoplayer.main" - when (hostPreset.konanTarget) { - MACOS_X64 -> linkerOpts("-L/opt/local/lib", "-L/usr/local/lib") - LINUX_X64 -> linkerOpts("-L/usr/lib/x86_64-linux-gnu", "-L/usr/lib64") - MINGW_X64 -> linkerOpts(mingwPath.resolve("lib").toString()) + when (preset) { + presets["macosX64"] -> linkerOpts("-L/opt/local/lib", "-L/usr/local/lib") + presets["linuxX64"] -> linkerOpts("-L/usr/lib/x86_64-linux-gnu", "-L/usr/lib64") + presets["mingwX64"] -> linkerOpts(mingwPath.resolve("lib").toString()) } } } compilations["main"].cinterops { val ffmpeg by creating { - when (hostPreset.konanTarget) { - MACOS_X64 -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include") - LINUX_X64 -> includeDirs.headerFilterOnly("/usr/include", "/usr/include/x86_64-linux-gnu", "/usr/include/ffmpeg") - MINGW_X64 -> includeDirs(mingwPath.resolve("/include")) + when (preset) { + presets["macosX64"] -> includeDirs.headerFilterOnly("/opt/local/include", "/usr/local/include") + presets["linuxX64"] -> includeDirs.headerFilterOnly("/usr/include", "/usr/include/x86_64-linux-gnu", "/usr/include/ffmpeg") + presets["mingwX64"] -> includeDirs(mingwPath.resolve("/include")) } } val sdl by creating { - when (hostPreset.konanTarget) { - MACOS_X64 -> includeDirs("/opt/local/include/SDL2", "/usr/local/include/SDL2") - LINUX_X64 -> includeDirs("/usr/include/SDL2") - MINGW_X64 -> includeDirs(mingwPath.resolve("/include/SDL2")) + when (preset) { + presets["macosX64"] -> includeDirs("/opt/local/include/SDL2", "/usr/local/include/SDL2") + presets["linuxX64"] -> includeDirs("/usr/include/SDL2") + presets["mingwX64"] -> includeDirs(mingwPath.resolve("/include/SDL2")) } } } diff --git a/samples/workers/build.gradle.kts b/samples/workers/build.gradle.kts index f9ec6224f7f..0f18ad4c2fd 100644 --- a/samples/workers/build.gradle.kts +++ b/samples/workers/build.gradle.kts @@ -1,23 +1,20 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset - plugins { kotlin("multiplatform") } -// Determine host preset. -val hostOs = System.getProperty("os.name") +kotlin { + // Determine host preset. + val hostOs = System.getProperty("os.name") -val hostPreset: KotlinNativeTargetPreset = when { - hostOs == "Mac OS X" -> "macosX64" - hostOs == "Linux" -> "linuxX64" - hostOs.startsWith("Windows") -> "mingwX64" - else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") -}.let { - kotlin.presets[it] as KotlinNativeTargetPreset -} + // Create target for the host platform. + val hostTarget = when { + hostOs == "Mac OS X" -> macosX64("workers") + hostOs == "Linux" -> linuxX64("workers") + hostOs.startsWith("Windows") -> mingwX64("workers") + else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.") + } -kotlin { - targetFromPreset(hostPreset, "workers") { + hostTarget.apply { binaries { executable { entryPoint = "sample.workers.main"