Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterofbread committed May 1, 2024
1 parent c7f95cf commit a134862
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,26 @@ enum class Arch {
val PKG_CONFIG_PATH: String get() = "/usr/lib/$libdir_name/pkgconfig"

companion object {
fun byName(name: String): Arch =
when (name.lowercase()) {
"x86_64", "amd64" -> X86_64
"aarch64", "arm64" -> ARM64
else -> throw GradleException("Unsupported CPU architecture '$name'")
}

fun getCurrent(): Arch =
byName(System.getProperty("os.arch"))

fun getTarget(project: Project): Arch {
val target_arch: String =
val target_override: String? =
project.findProperty("SPMS_ARCH")?.toString()
?: System.getenv("SPMS_ARCH")
?: System.getProperty("os.arch")

return when (target_arch.lowercase()) {
"x86_64", "amd64" -> X86_64
"aarch64", "arm64" -> ARM64
else -> throw GradleException("Unsupported CPU architecture '$target_arch'")
if (target_override == null) {
return getCurrent()
}

return byName(target_override)
}
}
}
Expand Down Expand Up @@ -90,26 +99,29 @@ enum class Platform {
LINUX_X86, LINUX_ARM64, WINDOWS
)

fun byName(name: String, arch: Arch): Platform =
if (name.lowercase() == "linux")
when (arch) {
Arch.X86_64 -> LINUX_X86
Arch.ARM64 -> LINUX_ARM64
}
else if (name.lowercase().startsWith("windows") && arch == Arch.X86_64) WINDOWS
else throw GradleException("Unsupported host OS and architecture '$name' ($arch)")

fun getCurrent(arch: Arch = Arch.getCurrent()): Platform =
byName(System.getProperty("os.name"), arch)

fun getTarget(project: Project): Platform {
val target_os: String =
val arch: Arch = Arch.getTarget(project)
val target_override: String? =
project.findProperty("SPMS_OS")?.toString()
?: System.getenv("SPMS_OS")
?: System.getProperty("os.name")
val target_arch: Arch = Arch.getTarget(project)

val os: String = target_os.lowercase()

if (os == "linux") {
return when (target_arch) {
Arch.X86_64 -> LINUX_X86
Arch.ARM64 -> LINUX_ARM64
}
}
else if (os.startsWith("windows") && target_arch == Arch.X86_64) {
return WINDOWS
if (target_override == null) {
return getCurrent(arch)
}

throw GradleException("Unsupported host OS and architecture '$target_os' ($target_arch)")
return byName(target_override, arch)
}
}
}
Expand Down Expand Up @@ -253,7 +265,7 @@ enum class CinteropLibraries {
cflags: Boolean = false,
libs: Boolean = false
): List<String> {
if (platform == Platform.WINDOWS) {
if (Platform.getCurrent() == Platform.WINDOWS) {
return emptyList()
}

Expand Down

0 comments on commit a134862

Please sign in to comment.