build.gradle.kts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import io.github.isning.gradle.plugins.cmake.params.CustomCMakeParams
  2. import io.github.isning.gradle.plugins.cmake.params.entries.CustomCMakeCacheEntries
  3. import io.github.isning.gradle.plugins.cmake.params.entries.asCMakeParams
  4. import io.github.isning.gradle.plugins.cmake.params.entries.platform.ModifiablePlatformEntriesImpl
  5. import io.github.isning.gradle.plugins.cmake.params.entries.plus
  6. import io.github.isning.gradle.plugins.cmake.params.plus
  7. import io.github.isning.gradle.plugins.kn.krossCompile.invoke
  8. import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
  9. import java.util.*
  10. plugins {
  11. alias(libs.plugins.kotlinMultiplatform)
  12. alias(libs.plugins.krossCompile)
  13. `maven-publish`
  14. signing
  15. }
  16. group = "io.github.zxing-cpp"
  17. version = "2.3.0-SNAPSHOT"
  18. Properties().apply {
  19. rootProject.file("local.properties").takeIf { it.exists() && it.isFile }?.let { load(it.reader()) }
  20. }.onEach { (key, value) ->
  21. if (key is String) ext[key] = value
  22. }
  23. val hostOs = System.getProperty("os.name")
  24. repositories {
  25. mavenCentral()
  26. google()
  27. }
  28. kotlin {
  29. val androidTargets = {
  30. listOf(
  31. androidNativeArm32(),
  32. androidNativeArm64(),
  33. androidNativeX86(),
  34. androidNativeX64(),
  35. )
  36. }
  37. val appleTargets = {
  38. listOf(
  39. iosX64(),
  40. iosArm64(),
  41. iosSimulatorArm64(),
  42. macosX64(),
  43. macosArm64(),
  44. watchosX64(),
  45. watchosArm32(),
  46. watchosArm64(),
  47. watchosSimulatorArm64(),
  48. tvosX64(),
  49. tvosArm64(),
  50. tvosSimulatorArm64(),
  51. )
  52. }
  53. val linuxTargets = {
  54. listOf(
  55. linuxX64(),
  56. linuxArm64(),
  57. )
  58. }
  59. // TODO: Linking failed, keep up with https://youtrack.jetbrains.com/issue/KT-65671
  60. // val windowsTargets = {
  61. // listOf(
  62. // mingwX64(),
  63. // )
  64. // }
  65. val enabledTargetList = mutableListOf<KotlinNativeTarget>()
  66. enabledTargetList.addAll(androidTargets())
  67. enabledTargetList.addAll(linuxTargets())
  68. // TODO: Linking failed, keep up with https://youtrack.jetbrains.com/issue/KT-65671
  69. // enabledTargetList.addAll(windowsTargets())
  70. if (hostOs == "Mac OS X") enabledTargetList.addAll(appleTargets())
  71. }
  72. krossCompile {
  73. libraries {
  74. val cmakeDir = project.layout.buildDirectory.dir("cmake").get().asFile.absolutePath
  75. val zxingCpp by creating {
  76. sourceDir = file("../../core").absolutePath
  77. outputPath = ""
  78. libraryArtifactNames = listOf("libZXing.a")
  79. cinterop {
  80. val buildDir = "$cmakeDir/{libraryName}/{targetName}"
  81. packageName = "zxingcpp.cinterop"
  82. includeDirs.from(buildDir)
  83. headers = listOf("$sourceDir/src/ZXingC.h")
  84. compilerOpts += "-DZXING_EXPERIMENTAL_API=ON"
  85. }
  86. cmake.apply {
  87. val buildDir = "$cmakeDir/{projectName}/{targetName}"
  88. configParams {
  89. this.buildDir = buildDir
  90. }
  91. configParams += (ModifiablePlatformEntriesImpl().apply {
  92. buildType = "Release"
  93. buildSharedLibs = false
  94. } + CustomCMakeCacheEntries(
  95. mapOf(
  96. "ZXING_READERS" to "ON",
  97. "ZXING_WRITERS" to "NEW",
  98. "ZXING_EXPERIMENTAL_API" to "ON",
  99. "ZXING_USE_BUNDLED_ZINT" to "ON",
  100. "ZXING_C_API" to "ON",
  101. )
  102. )).asCMakeParams
  103. buildParams {
  104. this.buildDir = buildDir
  105. config = "Release"
  106. }
  107. buildParams += CustomCMakeParams(listOf("-j16"))
  108. }
  109. androidNativeX64.ndk()
  110. androidNativeX86.ndk()
  111. androidNativeArm32.ndk()
  112. androidNativeArm64.ndk()
  113. // TODO: Find a way to build linux targets with cxx20. Detail: https://github.com/zxing-cpp/zxing-cpp/pull/719#discussion_r1485701269
  114. linuxX64.konan {
  115. cmake {
  116. configParams += CustomCMakeCacheEntries(
  117. mapOf(
  118. "CMAKE_CXX_STANDARD" to "17",
  119. )
  120. ).asCMakeParams
  121. }
  122. }
  123. linuxArm64.konan {
  124. cmake {
  125. configParams += CustomCMakeCacheEntries(
  126. mapOf(
  127. "CMAKE_CXX_STANDARD" to "17",
  128. )
  129. ).asCMakeParams
  130. }
  131. }
  132. // TODO: Linking failed, keep up with https://youtrack.jetbrains.com/issue/KT-65671
  133. // mingwX64.konan()
  134. if (hostOs == "Mac OS X") {
  135. iosX64.xcode()
  136. iosArm64.xcode()
  137. iosSimulatorArm64.xcode()
  138. macosX64.xcode()
  139. macosArm64.xcode()
  140. watchosX64.xcode()
  141. watchosArm32.xcode()
  142. watchosArm64.xcode()
  143. watchosSimulatorArm64.xcode()
  144. tvosX64.xcode()
  145. tvosArm64.xcode()
  146. tvosSimulatorArm64.xcode()
  147. }
  148. }
  149. }
  150. }
  151. publishing {
  152. publications.withType<MavenPublication>().all {
  153. artifactId = artifactId.replace(project.name, "kotlin-native")
  154. groupId = project.group.toString()
  155. version = project.version.toString()
  156. pom {
  157. name = "zxing-cpp"
  158. description = "Wrapper for zxing-cpp barcode image processing library"
  159. url = "https://github.com/zxing-cpp/zxing-cpp"
  160. licenses {
  161. license {
  162. name = "The Apache License, Version 2.0"
  163. url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
  164. }
  165. }
  166. developers {
  167. developer {
  168. id = "zxing-cpp"
  169. name = "zxing-cpp community"
  170. email = "zxingcpp@gmail.com"
  171. }
  172. }
  173. scm {
  174. connection = "scm:git:git://github.com/zxing-cpp/zxing-cpp.git"
  175. developerConnection = "scm:git:git://github.com/zxing-cpp/zxing-cpp.git"
  176. url = "https://github.com/zxing-cpp/zxing-cpp"
  177. }
  178. }
  179. }
  180. repositories {
  181. maven {
  182. name = "sonatype"
  183. val releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
  184. val snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
  185. setUrl(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
  186. credentials {
  187. val ossrhUsername: String? by project
  188. val ossrhPassword: String? by project
  189. username = ossrhUsername
  190. password = ossrhPassword
  191. }
  192. }
  193. }
  194. }
  195. signing {
  196. val signingKey: String? by project
  197. val signingPassword: String? by project
  198. if (signingKey != null && signingPassword != null) {
  199. useInMemoryPgpKeys(signingKey, signingPassword)
  200. sign(publishing.publications)
  201. }
  202. }