@@ -82,7 +82,7 @@ tasks.withType(CppCompile::class).configureEach {
82
82
83
83
dependencies {
84
84
implementation(project(" :DrOpt" ))
85
- testImplementation(" org.gradle.cpp-samples:googletest:1.9.0-gr4-SNAPSHOT" )
85
+ // testImplementation("org.gradle.cpp-samples:googletest:1.9.0-gr4-SNAPSHOT")
86
86
}
87
87
88
88
/* *
@@ -95,11 +95,32 @@ val operatingSystemFamilyByPublicationName: MutableMap<String, OperatingSystemFa
95
95
* MacOS x86 is no longer built because it requires and older version of Xcode and Apple makes it too difficult to install on newer versions of Mac
96
96
* Windows x86 is no longer built because the Adopt OpenJDK has crash failures.
97
97
*/
98
- val targetPlatformsToBuild = listOf (machines.windows.x86_64, machines.linux.x86_64, machines.macOS.x86_64)
98
+ val targetPlatformsToBuild = listOf (machines.windows.x86_64, machines.linux.x86_64, machines.macOS.x86_64, machines.macOS.architecture( " aarch64 " ) )
99
99
100
100
application {
101
101
targetMachines.set(targetPlatformsToBuild)
102
102
103
+ toolChains.configureEach {
104
+ if (this is Clang ) {
105
+ target(" host:x86-64" ) {
106
+ cppCompiler.withArguments { add(" --target=x86_64-apple-darwin" ) }
107
+ getcCompiler().withArguments { add(" --target=x86_64-apple-darwin" ) }
108
+ objcCompiler.withArguments { add(" --target=x86_64-apple-darwin" ) }
109
+ objcppCompiler.withArguments { add(" --target=x86_64-apple-darwin" ) }
110
+ linker.withArguments { add(" --target=x86_64-apple-darwin" ) }
111
+ assembler.withArguments { add(" --target=x86_64-apple-darwin" ) }
112
+ }
113
+ target(" host:aarch64" ) {
114
+ cppCompiler.withArguments { add(" --target=arm64-apple-darwin" ) }
115
+ getcCompiler().withArguments { add(" --target=arm64-apple-darwin" ) }
116
+ objcCompiler.withArguments { add(" --target=arm64-apple-darwin" ) }
117
+ objcppCompiler.withArguments { add(" --target=arm64-apple-darwin" ) }
118
+ linker.withArguments { add(" --target=arm64-apple-darwin" ) }
119
+ assembler.withArguments { add(" --target=arm64-apple-darwin" ) }
120
+ }
121
+ }
122
+ }
123
+
103
124
binaries.configureEach(CppExecutable ::class .java) {
104
125
logger.debug(" Configuring executable ${this .name} " )
105
126
@@ -161,6 +182,7 @@ application {
161
182
when (targetMachine.architecture.name) {
162
183
MachineArchitecture .X86 -> args(" i386" )
163
184
MachineArchitecture .X86_64 -> args(" x86_64" )
185
+ " aarch64" -> args(" arm64" )
164
186
else -> throw GradleException (" Don't know the lipo -arch flag for architecture ${targetMachine.architecture.name} " )
165
187
}
166
188
args(executableFile.get().asFile.absolutePath)
@@ -247,10 +269,34 @@ application {
247
269
unitTest {
248
270
targetMachines.set(targetPlatformsToBuild)
249
271
272
+ toolChains.configureEach {
273
+ if (this is Clang ) {
274
+ target(" host:x86-64" ) {
275
+ cppCompiler.withArguments { add(" --target=x86_64-apple-darwin" ) }
276
+ getcCompiler().withArguments { add(" --target=x86_64-apple-darwin" ) }
277
+ objcCompiler.withArguments { add(" --target=x86_64-apple-darwin" ) }
278
+ objcppCompiler.withArguments { add(" --target=x86_64-apple-darwin" ) }
279
+ linker.withArguments { add(" --target=x86_64-apple-darwin" ) }
280
+ assembler.withArguments { add(" --target=x86_64-apple-darwin" ) }
281
+ }
282
+ target(" host:aarch64" ) {
283
+ cppCompiler.withArguments { add(" --target=arm64-apple-darwin" ) }
284
+ getcCompiler().withArguments { add(" --target=arm64-apple-darwin" ) }
285
+ objcCompiler.withArguments { add(" --target=arm64-apple-darwin" ) }
286
+ objcppCompiler.withArguments { add(" --target=arm64-apple-darwin" ) }
287
+ linker.withArguments { add(" --target=arm64-apple-darwin" ) }
288
+ assembler.withArguments { add(" --target=arm64-apple-darwin" ) }
289
+ }
290
+ }
291
+ }
292
+
250
293
binaries.configureEach(CppTestExecutable ::class .java) {
294
+ val binaryCompileTask = compileTask.get()
251
295
val binaryLinkTask = linkTask.get()
252
296
when (toolChain) {
253
297
is Gcc -> {
298
+ binaryCompileTask.compilerArgs.add(" -std=c++14" )
299
+
254
300
if (targetMachine.operatingSystemFamily.isLinux) {
255
301
binaryLinkTask.linkerArgs.add(" -lpthread" )
256
302
}
@@ -259,11 +305,16 @@ unitTest {
259
305
binaryLinkTask.linkerArgs.add(" -fno-pie" )
260
306
}
261
307
is Clang -> {
308
+ binaryCompileTask.compilerArgs.add(" -std=c++14" )
309
+
262
310
binaryLinkTask.linkerArgs.add(" -ldl" )
263
311
}
264
312
is VisualCpp -> {
265
- compileTask.get().macros[" UNICODE" ] = null
266
- compileTask.get().macros[" _UNICODE" ] = null
313
+ binaryCompileTask.macros[" UNICODE" ] = null
314
+ binaryCompileTask.macros[" _UNICODE" ] = null
315
+
316
+ binaryCompileTask.compilerArgs.add(" /std:c++14" )
317
+
267
318
binaryLinkTask.linkerArgs.add(" /SUBSYSTEM:CONSOLE" )
268
319
binaryLinkTask.linkerArgs.add(" Shell32.lib" )
269
320
}
@@ -275,6 +326,8 @@ unitTest {
275
326
}
276
327
277
328
addJvmHeaders(compileTask.get(), this )
329
+
330
+ addGoogleTest(compileTask.get())
278
331
}
279
332
}
280
333
@@ -398,3 +451,9 @@ fun addJvmHeaders(binaryCompileTask: CppCompile, cppBinary: CppBinary) {
398
451
}
399
452
}
400
453
}
454
+
455
+ fun addGoogleTest (binaryCompileTask : CppCompile ) {
456
+ binaryCompileTask.includes(file(" ${rootProject.projectDir} /googletest" ))
457
+ binaryCompileTask.includes(file(" ${rootProject.projectDir} /googletest/include" ))
458
+ binaryCompileTask.source(file(" ${rootProject.projectDir} /googletest/src/gtest-all.cc" ))
459
+ }
0 commit comments