Add formal parameter names as MSVC requires it.
[SquirrelJME.git] / settings.gradle
blob51f078bb57a2e80a93f99760666c70666a469a1e
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         logger.warn("Faking x86_64 for M1 Macs...")
51         
52         gradle.beforeProject({proj ->
53                 proj.ext.squirreljmeMacOsArmCpp = true
54         })
55 } else if (osArch.equalsIgnoreCase("ppc") ||
56         osArch.equalsIgnoreCase("powerpc") ||
57         osArch.equalsIgnoreCase("ppc64") ||
58         osArch.equalsIgnoreCase("ppc64le") ||
59         osArch.equalsIgnoreCase("riscv") ||
60         osArch.equalsIgnoreCase("riscv32") ||
61         osArch.equalsIgnoreCase("riscv64") ||
62         osArch.equalsIgnoreCase('aarch64') ||
63         osArch.equalsIgnoreCase('arm64') ||
64         osArch.equalsIgnoreCase('arm64-v8')) {
65         logger.warn("Faking x86_64 for other architectures...")
66         
67         gradle.beforeProject({proj ->
68                 proj.ext.squirreljmeClaimX8664 = true
69         })
72 // If we have a really high Java version being used then the parameters
73 // for -source and -target were likely removed, so as such we cannot rely on
74 // the project being able to be built in such versions.
75 if (JavaVersion.current() >= JavaVersion.VERSION_HIGHER ||
76         Boolean.getBoolean("force.ecj")) {
77         // Emit a warning to indicate that the version is quite new
78         logger.warn("The current Java version is quite new, " +
79                 "if Eclipse Java Compiler (ECJ) exists on the system " +
80                 "then it will be used to compile the modules instead.")
81         
82         // Does ECJ exist in the system PATH?
83         def foundEcjBinary = false
84         for (java.nio.file.Path path : envPath) {
85                 if (Files.exists(path.resolve("ecj"))) {
86                         foundEcjBinary = true
87                 }
88         }
89         
90         // If we have the binary, use it
91         if (foundEcjBinary) {
92                 logger.lifecycle("Found ECJ binary, using it!")
93                 
94                 gradle.beforeProject({proj ->
95                         proj.ext.squirreljmeEcjEnabled = true
96                 })
97         } else {
98                 logger.warn("Could not find ECJ, build may fail!")
99         }
102 // On Java 8 we have tools.jar for JavaDoc
103 FileCollection toolsJar = files(Paths.get("${System.properties['java.home']}")
104         .getParent().resolve("lib").resolve("tools.jar"))
105 if (!Files.exists(toolsJar.singleFile.toPath())) {
106         // If on Java 9 or higher the module must be pulled in, but it does not
107         // exist since Java 17
108         if (JavaVersion.current() >= JavaVersion.VERSION_1_9 &&
109                 JavaVersion.current() < JavaVersion.VERSION_16) {
110                 // Windows/Linux
111                 toolsJar = files(Paths.get("${System.properties['java.home']}")
112                         .getParent().resolve("jmods").resolve("jdk.javadoc.jmod"))
113                 
114                 // Mac OS
115                 if (!Files.exists(toolsJar.singleFile.toPath())) {
116                         toolsJar = files(Paths.get("${System.properties['java.home']}")
117                                 .resolve("jmods").resolve("jdk.javadoc.jmod"))
118                 }
119         }
122 // What should we do for this?
123 def squirreljmeFakeJavaDocSdk =
124         !Files.exists(toolsJar.singleFile.toPath())
125 if (squirreljmeFakeJavaDocSdk) {
126         // Use fake API for building
127         gradle.beforeProject({proj ->
128                 proj.ext.squirreljmeFakeJavaDocSdk = true
129         })
130 } else {
131         // Use the real tools Jar for this
132         gradle.beforeProject({proj ->
133                 proj.ext.squirreljmeToolsJar = toolsJar
134         })
137 // Modules and available platforms
138 include "modules"
139 include "emulators"
140 include "sdk"
141 include "tools"
143 // Recursively include all modules
144 file(rootProject.projectDir.toPath().resolve("modules"))
145         .eachDir(
146         { subdir ->
147                 if (subdir.toPath().resolve("build.gradle").toFile().exists())
148                 {
149                         include "modules:" + subdir.name
150                 }
151         })
153 // Recursively include all emulators
154 file(rootProject.projectDir.toPath().resolve("emulators"))
155         .eachDir(
156         { subdir ->
157                 if (subdir.toPath().resolve("build.gradle").toFile().exists())
158                 {
159                         include "emulators:" + subdir.name
160                 }
161         })
163 // Recursively include all tools
164 file(rootProject.projectDir.toPath().resolve("tools"))
165         .eachDir(
166         { subdir ->
167                 // We may or may not want to include this accordingly
168                 if ("fake-javadoc-sdk".equals(subdir.name)) {
169                         if (squirreljmeFakeJavaDocSdk) {
170                                 logger.lifecycle("Including Fake JavaDoc SDK!")
171                         } else {
172                                 logger.lifecycle("Not including Fake JavaDoc SDK, becuase " +
173                                         "${toolsJar.getFiles()} exists...")
174                                 return
175                         }
176                 }
177                 
178                 if (subdir.toPath().resolve("build.gradle").toFile().exists())
179                 {
180                         include "tools:" + subdir.name
181                 }
182         })