1+ val platform: String by project
2+ val armArch: String by project
3+ val iosSigningIdentity: String by project
4+ val buildType: String? by project
5+
6+ buildscript {
7+ repositories {
8+ mavenLocal()
9+ maven(" https://dl.bintray.com/utopia-rise/kotlin-godot" )
10+ jcenter()
11+ mavenCentral()
12+ }
13+ dependencies {
14+ classpath(" org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" )
15+ classpath(" org.godotengine.kotlin:godot-gradle-plugin:0.1.0-3.2" )
16+ }
17+ }
18+
19+ repositories {
20+ mavenLocal()
21+ maven(" https://dl.bintray.com/utopia-rise/kotlin-godot" )
22+ maven(url = " https://dl.bintray.com/utopia-rise/kotlinx" )
23+
24+ // Here we exclude jetbrains coroutines and atomicfu because they do not provide the ones for android platform
25+ // so we exclude them so that those dependencies are downloaded from our bintray, where we provide android dependencies
26+ jcenter {
27+ content {
28+ excludeModule(" org.jetbrains.kotlinx" , " kotlinx-coroutines-core-native" )
29+ excludeModule(" org.jetbrains.kotlinx" , " atomicfu-native" )
30+ }
31+ }
32+ mavenCentral {
33+ content {
34+ excludeModule(" org.jetbrains.kotlinx" , " kotlinx-coroutines-core-native" )
35+ excludeModule(" org.jetbrains.kotlinx" , " atomicfu-native" )
36+ }
37+ }
38+ }
39+
40+ plugins {
41+ id(" org.jetbrains.kotlin.multiplatform" ) version (" 1.3.61" )
42+ }
43+
44+ apply (plugin = " godot-gradle-plugin" )
45+
46+ configure< org.godotengine.kotlin.gradleplugin.KotlinGodotPluginExtension > {
47+ this .releaseType = if (buildType?.toLowerCase() == " release" ) {
48+ org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType .RELEASE
49+ } else {
50+ org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType .DEBUG
51+ }
52+ this .godotProjectPath = " ${project.rootDir.absolutePath} /.."
53+ this .libraryPath = " kotlin.gdnlib"
54+ this .configureTargetAction = ::configureTargetAction
55+ }
56+
57+ kotlin {
58+ sourceSets {
59+ sourceSets.create(" macosMain" )
60+ sourceSets.create(" linuxMain" )
61+ sourceSets.create(" windowsMain" )
62+ sourceSets.create(" androidArm64Main" )
63+ sourceSets.create(" androidX64Main" )
64+ sourceSets.create(" iosArm64Main" )
65+ sourceSets.create(" iosX64Main" )
66+ configure(listOf (
67+ sourceSets[" macosMain" ],
68+ sourceSets[" linuxMain" ],
69+ sourceSets[" windowsMain" ],
70+ sourceSets[" androidArm64Main" ],
71+ sourceSets[" androidX64Main" ],
72+ sourceSets[" iosArm64Main" ],
73+ sourceSets[" iosX64Main" ]
74+ )) {
75+ this .kotlin.srcDir(" src/main/kotlin" )
76+ }
77+ }
78+
79+ if (project.hasProperty(" platform" )) {
80+ when (platform) {
81+ " windows" -> listOf (targetFromPreset(presets[" godotMingwX64" ], " windows" ))
82+ " linux" -> listOf (targetFromPreset(presets[" godotLinuxX64" ], " linux" ))
83+ " macos" -> listOf (targetFromPreset(presets[" godotMacosX64" ], " macos" ))
84+ " android" -> if (project.hasProperty(" armArch" )) {
85+ when (armArch) {
86+ " X64" -> listOf (targetFromPreset(presets[" godotAndroidNativeX64" ], " androidX64" ))
87+ " arm64" -> listOf (targetFromPreset(presets[" godotAndroidNativeArm64" ], " androidArm64" ))
88+ else -> listOf (targetFromPreset(presets[" godotAndroidNativeArm64" ], " androidArm64" ))
89+ }
90+ } else listOf (targetFromPreset(presets[" godotAndroidNativeArm64" ], " androidArm64" ))
91+ " ios" -> if (project.hasProperty(" armArch" )) {
92+ when (armArch) {
93+ " arm64" -> listOf (targetFromPreset(presets[" godotIosArm64" ], " iosArm64" ))
94+ " X64" -> listOf (targetFromPreset(presets[" godotIosX64" ], " iosX64" ))
95+ else -> listOf (targetFromPreset(presets[" godotIosArm64" ], " iosArm64" ))
96+ }
97+ } else listOf (targetFromPreset(presets[" godotIosArm64" ], " iosArm64" ))
98+ else -> listOf (targetFromPreset(presets[" godotLinuxX64" ], " linux" ))
99+ }
100+ } else {
101+ listOf (
102+ targetFromPreset(presets[" godotLinuxX64" ], " linux" ),
103+ targetFromPreset(presets[" godotMacosX64" ], " macos" ),
104+ targetFromPreset(presets[" godotMingwX64" ], " windows" ),
105+ targetFromPreset(presets[" godotAndroidNativeArm64" ], " androidArm64" ),
106+ targetFromPreset(presets[" godotAndroidNativeX64" ], " androidX64" ),
107+ targetFromPreset(presets[" godotIosArm64" ], " iosArm64" ),
108+ targetFromPreset(presets[" godotIosX64" ], " iosX64" )
109+ )
110+ }
111+ }
112+
113+ fun configureTargetAction (kotlinTarget : @ParameterName(name = " target" ) org.jetbrains.kotlin.gradle.plugin.KotlinTarget ) {
114+ kotlinTarget.compilations.getByName(" main" ) {
115+ if (this is org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation ) {
116+ println (" Configuring target ${this .target.name} " )
117+ this .target.compilations.all {
118+ dependencies {
119+ implementation(" org.godotengine.kotlin:godot-library-extension:0.1.0-3.2" )
120+ implementation(" org.godotengine.kotlin:annotations:0.1.0-3.2" )
121+ }
122+ }
123+ if (project.hasProperty(" iosSigningIdentity" ) && this .target.name == " iosArm64" ) {
124+ tasks.build {
125+ doLast {
126+ exec {
127+ commandLine = listOf (" codesign" , " -f" , " -s" , iosSigningIdentity, " build/bin/iosArm64/releaseShared/libkotlin.dylib" )
128+ }
129+ exec {
130+ commandLine = listOf (" install_name_tool" , " -id" , " @executable_path/dylibs/ios/libkotlin.dylib" , " build/bin/iosArm64/releaseShared/libkotlin.dylib" )
131+ }
132+ }
133+ }
134+ } else if (project.hasProperty(" iosSigningIdentity" ) && this .target.name == " iosX64" ) {
135+ tasks.build {
136+ doLast {
137+ exec {
138+ commandLine = listOf (" codesign" , " -f" , " -s" , iosSigningIdentity, " build/bin/iosX64/releaseShared/libkotlin.dylib" )
139+ }
140+ exec {
141+ commandLine = listOf (" install_name_tool" , " -id" , " @executable_path/dylibs/ios/libkotlin.dylib" , " build/bin/iosX64/releaseShared/libkotlin.dylib" )
142+ }
143+ }
144+ }
145+ }
146+ } else {
147+ System .err.println (" Not a native target! TargetName: ${kotlinTarget.name} " )
148+ }
149+ }
150+ }
0 commit comments