/* * Build logic for Progressia * LWJGL dependency logic */ project.ext.lwjgl = new HashMap<>() // Version of LWJGL lwjgl.version = '3.3.0' /* * Target platforms for current operation. * This is filled in by the request* tasks. This is referenced by the addLwjglNatives task. * When empty, current platform is assumed. */ lwjgl.targets = new HashSet() // LWJGL components. To include org.lwjgl:lwjgl-foobar, add 'foobar' to this list. lwjgl.libraries = [ 'opengl', 'glfw', 'openal', 'stb' ] // Determine the architecture of the build environment import org.gradle.internal.os.OperatingSystem switch (OperatingSystem.current()) { case OperatingSystem.LINUX: def osArch = System.getProperty('os.arch') lwjgl.localArch = osArch.startsWith('arm') || osArch.startsWith('aarch64') ? "linux-${osArch.contains('64') || osArch.startsWith('armv8') ? 'arm64' : 'arm32'}" : 'linux' break case OperatingSystem.MAC_OS: project.ext.lwjglNatives = System.getProperty('os.arch').startsWith('aarch64') ? 'macos-arm64' : 'macos' break case OperatingSystem.WINDOWS: def osArch = System.getProperty('os.arch') project.ext.lwjglNatives = osArch.contains('64') ? "windows${osArch.startsWith('aarch64') ? '-arm64' : ''}" : 'windows-x86' break } configurations { create 'lwjglNatives' } // Declare pure-Java dependencies dependencies { // BOM def bom = platform("org.lwjgl:lwjgl-bom:${lwjgl.version}") implementation bom lwjglNatives bom // Core implementation 'org.lwjgl:lwjgl' // Local natives for core runtimeOnly "org.lwjgl:lwjgl::natives-${lwjgl.localArch}" // Components lwjgl.libraries.each { lib -> implementation "org.lwjgl:lwjgl-$lib" // Local natives for component runtimeOnly "org.lwjgl:lwjgl-$lib::natives-${lwjgl.localArch}" } } /* * Adds LWJGL native libraries to lwjglNatives configuration */ task lwjgl_addNativesToRuntimeOnly { doFirst { if (project.hasProperty('forceTargets')) { try { def oldTargets = lwjgl.targets.join(',') lwjgl.targets.clear() lwjgl.targets.addAll project.forceTargets.split(',')*.trim().collect { it == 'local' ? lwjgl.localArch : it } logger.info 'Overriding selected platforms {} with {}', oldTargets, lwjgl.targets.join(',') } catch (Exception e) { throw new GradleException("Could not parse forceTargets \"${project.forceTargets}\", expecting platform-1,platform-2,local", e) } } if (lwjgl.targets.isEmpty()) { logger.info 'Adding LWJGL native dependencies for local platform only: {}', lwjgl.localArch lwjgl.targets.add lwjgl.localArch } else { logger.info 'Adding LWJGL native dependencies for platforms: {}', lwjgl.targets.sort().join(', ') } dependencies { lwjgl.targets.each { target -> lwjglNatives "org.lwjgl:lwjgl::natives-$target" lwjgl.libraries.each { lib -> lwjglNatives "org.lwjgl:lwjgl-$lib::natives-$target" } } } } } // Replaces LWJGL natives in the given configuration with the requested ones lwjgl.replaceNativesIn = { config -> new ArrayList().tap { addAll config removeIf { it.name ==~ /.*lwjgl.*natives.*/ } addAll project.configurations.lwjglNatives } } task requestCrossPlatformDependencies { description 'Adds LWJGL natives for all available platforms.' lwjgl_addNativesToRuntimeOnly.mustRunAfter requestCrossPlatformDependencies } def requestTask(String name, String... targets) { def theTask = task "request${name}Dependencies" theTask.doFirst { lwjgl.targets.addAll targets } theTask.description "Adds LWJGL natives for $name (${targets.join(', ')})." requestCrossPlatformDependencies.dependsOn theTask lwjgl_addNativesToRuntimeOnly.mustRunAfter theTask } requestTask 'Linux', 'linux', 'linux-arm32', 'linux-arm64' requestTask 'Windows', 'windows', 'windows-arm64', 'windows-x86' requestTask 'MacOS', 'macos', 'macos-arm64'