|
3 | 3 | */
|
4 | 4 |
|
5 | 5 | apply plugin: 'kotlin-multiplatform'
|
6 |
| -apply from: rootProject.file("gradle/targets.gradle") |
7 | 6 | apply from: rootProject.file("gradle/compile-jvm-multiplatform.gradle")
|
8 | 7 | apply from: rootProject.file("gradle/compile-common.gradle")
|
9 | 8 | apply from: rootProject.file("gradle/compile-js-multiplatform.gradle")
|
10 | 9 | apply from: rootProject.file("gradle/compile-native-multiplatform.gradle")
|
11 | 10 | apply from: rootProject.file('gradle/publish-npm-js.gradle')
|
12 | 11 |
|
| 12 | +project.ext.ideaActive = System.getProperty('idea.active') == 'true' |
| 13 | +project.ext.sourceSetSuffixes = ["Main", "Test"] |
| 14 | + |
13 | 15 | void defineSourceSet(newName, dependsOn, includedInPred) {
|
14 |
| - for (suffix in ["Main", "Test"]) { |
| 16 | + for (suffix in project.ext.sourceSetSuffixes) { |
15 | 17 | def newSS = kotlin.sourceSets.maybeCreate(newName + suffix)
|
16 | 18 | for (dep in dependsOn) {
|
17 | 19 | newSS.dependsOn(kotlin.sourceSets[dep + suffix])
|
@@ -48,13 +50,6 @@ defineSourceSet("concurrent", ["common"]) { it in ["jvm", "native"] }
|
48 | 50 | defineSourceSet("nativeDarwin", ["native"]) { isNativeDarwin(it) }
|
49 | 51 | defineSourceSet("nativeOther", ["native"]) { isNativeOther(it) }
|
50 | 52 |
|
51 |
| -// todo: This is IDEA kludge, without "fromPresent" the code does not resolve properly |
52 |
| -if (project.ext.ideaActive && isNativeDarwin(project.ext.ideaPreset.name)) { |
53 |
| - kotlin.targets { |
54 |
| - fromPreset(project.ext.ideaPreset, 'nativeDarwin') |
55 |
| - } |
56 |
| -} |
57 |
| - |
58 | 53 | /*
|
59 | 54 | * All platform plugins and configuration magic happens here instead of build.gradle
|
60 | 55 | * because JMV-only projects depend on core, thus core should always be initialized before configuration.
|
@@ -118,6 +113,36 @@ configurations {
|
118 | 113 | configureKotlinJvmPlatform(kotlinCompilerPluginClasspath)
|
119 | 114 | }
|
120 | 115 |
|
| 116 | +def configureNativeSourceSetPreset(name, preset) { |
| 117 | + def hostMainCompilation = project.kotlin.targetFromPreset(preset).compilations.main |
| 118 | + def compileConfiguration = configurations[hostMainCompilation.compileDependencyConfigurationName] |
| 119 | + def hostNativePlatformLibs = files(provider { |
| 120 | + compileConfiguration.findAll { |
| 121 | + it.path.endsWith(".klib") || it.absolutePath.contains("klib${File.separator}platform") |
| 122 | + } |
| 123 | + }) |
| 124 | + for (suffix in project.ext.sourceSetSuffixes) { |
| 125 | + configure(kotlin.sourceSets[name + suffix]) { |
| 126 | + dependencies.add(implementationMetadataConfigurationName, hostNativePlatformLibs) |
| 127 | + } |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +// Configure platform libraries for native source sets when working in IDEA |
| 132 | +if (project.ext.ideaActive) { |
| 133 | + def manager = project.ext.hostManager |
| 134 | + def linuxPreset = kotlin.presets.linuxX64 |
| 135 | + def macosPreset = kotlin.presets.macosX64 |
| 136 | + // linux should be always available (cross-compilation capable) -- use it as default |
| 137 | + assert manager.isEnabled(linuxPreset.konanTarget) |
| 138 | + // use macOS libs for nativeDarwin if available |
| 139 | + def macosAvailable = manager.isEnabled(macosPreset.konanTarget) |
| 140 | + // configure source sets |
| 141 | + configureNativeSourceSetPreset("native", linuxPreset) |
| 142 | + configureNativeSourceSetPreset("nativeOther", linuxPreset) |
| 143 | + configureNativeSourceSetPreset("nativeDarwin", macosAvailable ? macosPreset : linuxPreset) |
| 144 | +} |
| 145 | + |
121 | 146 | kotlin.sourceSets {
|
122 | 147 | jvmTest.dependencies {
|
123 | 148 | api "com.devexperts.lincheck:lincheck:$lincheck_version"
|
|
0 commit comments