Keep enum values since valueOf(String) can depend on them along with name().
[SquirrelJME.git] / settings.gradle
blob141a69f5f6c382ff68a146a63e1c9a7a68e1364a
1 import java.nio.file.Paths
2 import java.nio.file.Files
3 import java.util.regex.Pattern
4 import java.util.stream.Collectors
6 // Poking PATH is used by multiple systems
7 def envRawPathProperty = System.getenv("PATH")
8 def envPath = (envRawPathProperty != null ?
9         Arrays.asList(
10                 envRawPathProperty.split(Pattern.quote(File.pathSeparator)))
11                         .stream().<java.nio.file.Path>map({it -> Paths.get(it)})
12                         .collect(Collectors.toList()) :
13                         Collections.<java.nio.file.Path>emptyList())
15 // Do we have Termux in our PATH?
16 def foundTermuxRoot = false
17 for (java.nio.file.Path path : envPath) {
18         def fullPath = path.toAbsolutePath();
19         if (fullPath.toString().startsWith("/data/data/com.termux/")) {
20                 foundTermuxRoot = true;
21         }
24 // Did we find Termux in our PATH?
25 if ((foundTermuxRoot && System.getProperty("force.termux") == null) ||
26         Boolean.getBoolean("force.termux")) {
27         // squirreljmeTermuxCompiler
28         logger.lifecycle("Appears we are in Termux, kludging compiler build...")
29         
30         // Enable it
31         gradle.beforeProject({proj ->
32                 proj.ext.squirreljmeTermuxCompiler = true
33         })
36 // Is this Mac OS?
37 def osName = System.getProperty("os.name")
38 if (osName.equalsIgnoreCase('Mac OS X')) {
39         gradle.beforeProject({proj ->
40                 proj.ext.squirreljmeIsOnMacOs = true
41         })
44 // If we are on M1 Macs, perform some modifications so that Gradle can compile
45 // C++ code
46 def osArch = System.getProperty("os.arch")  
47 if (osName.equalsIgnoreCase('Mac OS X') &&
48         (osArch.equalsIgnoreCase('aarch64') || osArch.equalsIgnoreCase('arm64') ||
49         osArch.equalsIgnoreCase('arm64-v8'))) {
50         
51         gradle.beforeProject({proj ->
52                 proj.ext.squirreljmeMacOsArmCpp = true
53         })
56 // If we have a really high Java version being used then the parameters
57 // for -source and -target were likely removed, so as such we cannot rely on
58 // the project being able to be built in such versions.
59 if (JavaVersion.current() >= JavaVersion.VERSION_HIGHER ||
60         Boolean.getBoolean("force.ecj")) {
61         // Emit a warning to indicate that the version is quite new
62         logger.warn("The current Java version is quite new, " +
63                 "if Eclipse Java Compiler (ECJ) exists on the system " +
64                 "then it will be used to compile the modules instead.")
65         
66         // Does ECJ exist in the system PATH?
67         def foundEcjBinary = false
68         for (java.nio.file.Path path : envPath) {
69                 if (Files.exists(path.resolve("ecj"))) {
70                         foundEcjBinary = true
71                 }
72         }
73         
74         // If we have the binary, use it
75         if (foundEcjBinary) {
76                 logger.lifecycle("Found ECJ binary, using it!")
77                 
78                 gradle.beforeProject({proj ->
79                         proj.ext.squirreljmeEcjEnabled = true
80                 })
81         } else {
82                 logger.warn("Could not find ECJ, build may fail!")
83         }
86 // Modules and available platforms
87 include "modules"
88 include "emulators"
89 include "tools"
91 // Recursively include all modules
92 file(rootProject.projectDir.toPath().resolve("modules"))
93         .eachDir(
94         { subdir ->
95                 if (subdir.toPath().resolve("build.gradle").toFile().exists())
96                 {
97                         include "modules:" + subdir.name
98                 }
99         })
101 // Recursively include all emulators
102 file(rootProject.projectDir.toPath().resolve("emulators"))
103         .eachDir(
104         { subdir ->
105                 if (subdir.toPath().resolve("build.gradle").toFile().exists())
106                 {
107                         include "emulators:" + subdir.name
108                 }
109         })
111 // Recursively include all tools
112 file(rootProject.projectDir.toPath().resolve("tools"))
113         .eachDir(
114         { subdir ->
115                 if (subdir.toPath().resolve("build.gradle").toFile().exists())
116                 {
117                         include "tools:" + subdir.name
118                 }
119         })