1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * This file was created using the `create_project.py` script located in the
19 * `<AndroidX root>/development/project-creator` directory.
20 *
21 * Please use that script when creating a new project, rather than copying an existing project and
22 * modifying its settings.
23 */
24
25
26import androidx.build.PlatformIdentifier
27import androidx.build.SoftwareType
28import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
29import org.jetbrains.kotlin.konan.target.Family
30
31plugins {
32    id("AndroidXPlugin")
33    id("com.android.library")
34}
35
36
37configurations {
38    // Configuration for resolving shared archive file of androidx's SQLite compilation
39    sqliteSharedArchive {
40        canBeConsumed = false
41        canBeResolved = true
42        attributes {
43            attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.NATIVE_LINK))
44        }
45    }
46    // Configuration for resolving SQLite sources from sqlite-bundled.
47    sqliteSources {
48        canBeConsumed = false
49        canBeResolved = true
50        attributes {
51            attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, "sqlite-amalgamation"))
52        }
53    }
54}
55
56androidXMultiplatform {
57    androidTarget()
58    ios() {
59        // Link to sqlite3 available in iOS
60        binaries.configureEach {
61            linkerOpts += ["-lsqlite3"]
62        }
63    }
64    linux()
65    mac()
66
67    defaultPlatform(PlatformIdentifier.ANDROID)
68
69    sourceSets {
70        commonMain {
71            dependencies {
72                implementation(libs.kotlinStdlib)
73                api("androidx.annotation:annotation:1.8.1")
74                api(project(":sqlite:sqlite"))
75            }
76        }
77        commonTest {
78            dependencies {
79                implementation(libs.kotlinTest)
80                implementation(project(":kruth:kruth"))
81            }
82        }
83        androidMain {
84            dependsOn(commonMain)
85        }
86        androidInstrumentedTest {
87            dependsOn(commonTest)
88            dependencies {
89                implementation(libs.kotlinTestJunit)
90                implementation(libs.testRunner)
91                implementation(libs.testCore)
92            }
93        }
94        nativeMain {
95            dependsOn(commonMain)
96            // For usage of C interop APIs
97            // See: https://kotlinlang.org/docs/whatsnew19.html#explicit-c-interoperability-stability-guarantees
98            languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi")
99        }
100        nativeTest {
101            dependsOn(commonTest)
102        }
103        targets.configureEach { target ->
104            if (target.platformType == KotlinPlatformType.native) {
105                def main = target.compilations["main"]
106                main.defaultSourceSet {
107                    dependsOn(nativeMain)
108                    // Aligns dependants of nativeMain to have same language settings.
109                    languageSettings.optIn("kotlinx.cinterop.ExperimentalForeignApi")
110                }
111                main.cinterops {
112                    sqlite3 { cInteropSettings ->
113                        includeDirs(configurations.sqliteSources.incoming.files)
114                        // TODO KT-62795 We shouldn't need this dependency once that issue is fixed.
115                        tasks.named(cInteropSettings.interopProcessingTaskName).configure {
116                            it.dependsOn(configurations.sqliteSources)
117                        }
118                    }
119                }
120
121                def test = target.compilations["test"]
122                test.defaultSourceSet {
123                    dependsOn(nativeTest)
124                }
125                if (target.konanTarget.family == Family.LINUX) {
126                    // For tests in Linux host, statically include androidx's compiled SQLite
127                    // via a generated C interop definition
128                    createCinteropFromArchiveConfiguration(test, configurations["sqliteSharedArchive"])
129                } else if (target.konanTarget.family == Family.OSX) {
130                    // For tests in Mac host, link to shared SQLite library included in MacOS
131                    test.kotlinOptions.freeCompilerArgs += [
132                        "-linker-options", "-lsqlite3"
133                    ]
134                }
135            }
136        }
137    }
138}
139
140dependencies {
141    sqliteSharedArchive(project(":sqlite:sqlite-bundled"))
142    sqliteSources(project(":sqlite:sqlite-bundled"))
143}
144
145androidx {
146    name = "SQLite Framework Integration"
147    type = SoftwareType.PUBLISHED_LIBRARY
148    inceptionYear = "2017"
149    description = "The implementation of SQLite library using the framework code."
150}
151
152android {
153    namespace = "androidx.sqlite.db.framework"
154}
155