|
| 1 | +/* |
| 2 | + * GenerateConanToolchainFileTask.kt |
| 3 | + * |
| 4 | + * ConanAndroidGradlePlugin (https://github.com/opendocument-app/ConanAndroidGradlePlugin) |
| 5 | + * |
| 6 | + * Copyright (c) 2024 ViliusSutkus89.com OpenDocument.app |
| 7 | + * |
| 8 | + * ConanAndroidGradlePlugin is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License version 3 as |
| 10 | + * published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * ConanAndroidGradlePlugin is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +package app.opendocument |
| 22 | + |
| 23 | +import org.gradle.api.DefaultTask |
| 24 | +import org.gradle.api.file.RegularFileProperty |
| 25 | +import org.gradle.api.tasks.OutputFile |
| 26 | +import org.gradle.api.tasks.TaskAction |
| 27 | + |
| 28 | + |
| 29 | +abstract class GenerateConanToolchainFileTask : DefaultTask() { |
| 30 | + @get:OutputFile |
| 31 | + abstract val conanToolchainFile: RegularFileProperty |
| 32 | + init { |
| 33 | + conanToolchainFile.convention(project.layout.buildDirectory.get().dir("conan").file("android_toolchain.cmake")) |
| 34 | + } |
| 35 | + |
| 36 | + @TaskAction |
| 37 | + fun writeToolchain() { |
| 38 | + val ANDROID_ABI = "\${ANDROID_ABI}" |
| 39 | + val CMAKE_CURRENT_LIST_DIR = "\${CMAKE_CURRENT_LIST_DIR}" |
| 40 | + val CMAKE_BUILD_TYPE = "\${CMAKE_BUILD_TYPE}" |
| 41 | + conanToolchainFile.get().asFile.writeText(""" |
| 42 | +# During multiple stages of CMake configuration, the toolchain file is processed and command-line |
| 43 | +# variables may not be always available. The script exits prematurely if essential variables are absent. |
| 44 | +
|
| 45 | +if ( NOT ANDROID_ABI OR NOT CMAKE_BUILD_TYPE ) |
| 46 | + return() |
| 47 | +endif() |
| 48 | +if(${ANDROID_ABI} STREQUAL "x86_64") |
| 49 | + include("${CMAKE_CURRENT_LIST_DIR}/x86_64/build/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") |
| 50 | +elseif(${ANDROID_ABI} STREQUAL "x86") |
| 51 | + include("${CMAKE_CURRENT_LIST_DIR}/x86/build/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") |
| 52 | +elseif(${ANDROID_ABI} STREQUAL "arm64-v8a") |
| 53 | + include("${CMAKE_CURRENT_LIST_DIR}/armv8/build/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") |
| 54 | +elseif(${ANDROID_ABI} STREQUAL "armeabi-v7a") |
| 55 | + include("${CMAKE_CURRENT_LIST_DIR}/armv7/build/${CMAKE_BUILD_TYPE}/generators/conan_toolchain.cmake") |
| 56 | +else() |
| 57 | + message(FATAL "Not supported configuration") |
| 58 | +endif() |
| 59 | + """.trimIndent()) |
| 60 | + } |
| 61 | +} |
0 commit comments