Leonid Startsev | 9f6d3b4 | 2019-10-09 18:07:41 +0300 | [diff] [blame] | 1 | /* |
Leonid Startsev | f7abe61 | 2020-02-18 17:16:03 +0300 | [diff] [blame] | 2 | * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Leonid Startsev | 9f6d3b4 | 2019-10-09 18:07:41 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
Vsevolod Tolstopyatov | 608cbad | 2020-09-14 15:38:02 +0300 | [diff] [blame^] | 5 | project.ext.ideaActive = System.getProperty('idea.active') == 'true' |
Leonid Startsev | 9f6d3b4 | 2019-10-09 18:07:41 +0300 | [diff] [blame] | 6 | project.ext.deployMode = property('native.deploy') == 'true' |
| 7 | project.ext.singleTargetMode = project.ext.ideaActive || !project.ext.deployMode |
| 8 | |
| 9 | project.ext.nativeMainSets = [] |
| 10 | project.ext.nativeTestSets = [] |
| 11 | |
| 12 | kotlin { |
Vsevolod Tolstopyatov | 608cbad | 2020-09-14 15:38:02 +0300 | [diff] [blame^] | 13 | targets { |
| 14 | def manager = project.ext.hostManager |
| 15 | def linuxEnabled = manager.isEnabled(presets.linuxX64.konanTarget) |
| 16 | def macosEnabled = manager.isEnabled(presets.macosX64.konanTarget) |
| 17 | def winEnabled = manager.isEnabled(presets.mingwX64.konanTarget) |
| 18 | |
| 19 | project.ext.isLinuxHost = linuxEnabled |
| 20 | project.ext.isMacosHost = macosEnabled |
| 21 | project.ext.isWinHost = winEnabled |
| 22 | |
| 23 | def ideaPreset = presets.linuxX64 |
| 24 | if (macosEnabled) ideaPreset = presets.macosX64 |
| 25 | if (winEnabled) ideaPreset = presets.mingwX64 |
| 26 | project.ext.ideaPreset = ideaPreset |
| 27 | } |
| 28 | |
Leonid Startsev | 9f6d3b4 | 2019-10-09 18:07:41 +0300 | [diff] [blame] | 29 | targets.metaClass.addTarget = { preset -> |
| 30 | def target = delegate.fromPreset(preset, preset.name) |
| 31 | project.ext.nativeMainSets.add(target.compilations['main'].kotlinSourceSets.first()) |
| 32 | project.ext.nativeTestSets.add(target.compilations['test'].kotlinSourceSets.first()) |
| 33 | } |
| 34 | |
| 35 | targets { |
| 36 | if (project.ext.singleTargetMode) { |
| 37 | fromPreset(project.ext.ideaPreset, 'native') |
| 38 | } else { |
| 39 | // Linux |
| 40 | addTarget(presets.linuxX64) |
| 41 | addTarget(presets.linuxArm32Hfp) |
Ugljesa Jovanovic | dc3f467 | 2019-12-27 22:33:48 +0100 | [diff] [blame] | 42 | addTarget(presets.linuxArm64) |
Leonid Startsev | 9f6d3b4 | 2019-10-09 18:07:41 +0300 | [diff] [blame] | 43 | |
| 44 | // Mac & iOS |
| 45 | addTarget(presets.macosX64) |
| 46 | |
| 47 | addTarget(presets.iosArm64) |
| 48 | addTarget(presets.iosArm32) |
| 49 | addTarget(presets.iosX64) |
| 50 | |
Leonid Startsev | 54c9c51 | 2019-10-18 15:51:59 +0300 | [diff] [blame] | 51 | addTarget(presets.watchosX86) |
| 52 | addTarget(presets.watchosArm32) |
| 53 | addTarget(presets.watchosArm64) |
| 54 | |
| 55 | addTarget(presets.tvosArm64) |
| 56 | addTarget(presets.tvosX64) |
Leonid Startsev | 9f6d3b4 | 2019-10-09 18:07:41 +0300 | [diff] [blame] | 57 | |
| 58 | // Windows |
| 59 | addTarget(presets.mingwX64) |
| 60 | addTarget(presets.mingwX86) |
Leonid Startsev | 9f6d3b4 | 2019-10-09 18:07:41 +0300 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | sourceSets { |
| 65 | nativeMain { dependsOn commonMain } |
| 66 | // Empty source set is required in order to have native tests task |
Sergey Igushkin | c5f1af6 | 2020-05-26 15:54:39 +0300 | [diff] [blame] | 67 | nativeTest { dependsOn commonTest } |
Leonid Startsev | 9f6d3b4 | 2019-10-09 18:07:41 +0300 | [diff] [blame] | 68 | |
| 69 | if (!project.ext.singleTargetMode) { |
| 70 | configure(project.ext.nativeMainSets) { |
| 71 | dependsOn nativeMain |
| 72 | } |
| 73 | |
| 74 | configure(project.ext.nativeTestSets) { |
| 75 | dependsOn nativeTest |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |