Skip to content

Commit 6ee558f

Browse files
committed
Configure mpp examples for other platforms
1 parent 7a02802 commit 6ee558f

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

examples/kotlin-multiplatform/build.gradle

+42-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.konan.target.HostManager
2+
13
plugins {
24
id 'org.jetbrains.kotlin.multiplatform'
35
id 'org.jetbrains.kotlin.plugin.allopen' version "1.3.20"
@@ -24,6 +26,9 @@ repositories.all {
2426
}
2527
}
2628

29+
project.ext.hostManager = new HostManager()
30+
apply from: rootProject.file("gradle/utility.gradle")
31+
2732
// how to apply plugin to a specific source set?
2833
allOpen {
2934
annotation("org.openjdk.jmh.annotations.State")
@@ -53,11 +58,24 @@ kotlin {
5358
}
5459
}
5560
}
56-
57-
// For ARM, preset should be changed to presets.iosArm32 or presets.iosArm64
58-
// For Linux, preset should be changed to e.g. presets.linuxX64
59-
// For MacOS, preset should be changed to e.g. presets.macosX64
60-
macosX64('native')
61+
62+
if (project.ext.ideaActive) {
63+
targets {
64+
project.ext.nativeTarget = fromPreset(project.ext.ideaPreset, 'native')
65+
}
66+
} else {
67+
macosX64('macosX64')
68+
linuxX64('linuxX64')
69+
mingwX64('windowsX64')
70+
}
71+
72+
sourceSets.all {
73+
languageSettings {
74+
progressiveMode = true
75+
useExperimentalAnnotation("kotlin.Experimental")
76+
useExperimentalAnnotation('kotlin.ExperimentalUnsignedTypes')
77+
}
78+
}
6179

6280
sourceSets {
6381
commonMain {
@@ -93,14 +111,27 @@ kotlin {
93111
implementation 'org.jetbrains.kotlin:kotlin-test-js'
94112
}
95113
}
96-
nativeMain {
97-
}
98-
nativeTest {
114+
115+
if (ideaActive) {
116+
nativeMain {
117+
kotlin.srcDir("src/${project.ext.nativeTarget.preset.name}Main")
118+
}
119+
} else {
120+
nativeMain {}
121+
nativeTest {}
122+
123+
configure([linuxX64Main, macosX64Main, windowsX64Main]) {
124+
dependsOn nativeMain
125+
}
126+
127+
configure([linuxX64Test, macosX64Test, windowsX64Test]) {
128+
dependsOn nativeTest
129+
}
99130
}
100-
}
101131

102-
sourceSets.all {
103-
languageSettings.progressiveMode = true
132+
nativeMain.dependencies {
133+
134+
}
104135
}
105136
}
106137

runtime/build.gradle

-6
Original file line numberDiff line numberDiff line change
@@ -61,40 +61,34 @@ kotlin {
6161

6262
sourceSets {
6363
commonMain {
64-
kotlin.srcDirs = ["$it.name/src"]
6564
dependencies {
6665
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
6766
}
6867
}
6968
commonTest {
70-
kotlin.srcDirs = ["$it.name/src"]
7169
dependencies {
7270
implementation 'org.jetbrains.kotlin:kotlin-test-common'
7371
implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
7472
}
7573
}
7674
jvmMain {
77-
kotlin.srcDirs = ["$it.name/src"]
7875
dependencies {
7976
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
8077
compileOnly "org.openjdk.jmh:jmh-core:$jmhVersion"
8178
}
8279
}
8380
jvmTest {
84-
kotlin.srcDirs = ["$it.name/src"]
8581
dependencies {
8682
implementation 'org.jetbrains.kotlin:kotlin-test'
8783
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
8884
}
8985
}
9086
jsMain {
91-
kotlin.srcDirs = ["$it.name/src"]
9287
dependencies {
9388
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
9489
}
9590
}
9691
jsTest {
97-
kotlin.srcDirs = ["$it.name/src"]
9892
dependencies {
9993
implementation 'org.jetbrains.kotlin:kotlin-test-js'
10094
}

0 commit comments

Comments
 (0)