Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 1 | ext { |
| 2 | useJava = true |
| 3 | useCpp = true |
| 4 | baseId = 'wpimath' |
| 5 | groupId = 'edu.wpi.first.wpimath' |
| 6 | |
| 7 | nativeName = 'wpimath' |
| 8 | devMain = 'edu.wpi.first.wpiutil.math.DevMain' |
| 9 | } |
| 10 | |
| 11 | apply from: "${rootDir}/shared/jni/setupBuild.gradle" |
| 12 | |
| 13 | nativeUtils.exportsConfigs { |
| 14 | wpimath { |
| 15 | x86ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure', |
| 16 | '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure', |
| 17 | '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range', |
| 18 | '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast'] |
| 19 | x64ExcludeSymbols = ['_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure', |
| 20 | '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure', |
| 21 | '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range', |
| 22 | '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast'] |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | cppHeadersZip { |
| 27 | from('src/main/native/eigeninclude') { |
| 28 | into '/' |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | model { |
| 33 | components { |
| 34 | all { |
| 35 | it.sources.each { |
| 36 | it.exportedHeaders { |
| 37 | srcDirs 'src/main/native/include', 'src/main/native/eigeninclude' |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | dependencies { |
| 45 | api "org.ejml:ejml-simple:0.38" |
| 46 | api "com.fasterxml.jackson.core:jackson-annotations:2.10.0" |
| 47 | api "com.fasterxml.jackson.core:jackson-core:2.10.0" |
| 48 | api "com.fasterxml.jackson.core:jackson-databind:2.10.0" |
| 49 | } |
| 50 | |
| 51 | def wpilibNumberFileInput = file("src/generate/GenericNumber.java.in") |
| 52 | def natFileInput = file("src/generate/Nat.java.in") |
| 53 | def natGetterInput = file("src/generate/NatGetter.java.in") |
| 54 | def wpilibNumberFileOutputDir = file("$buildDir/generated/java/edu/wpi/first/wpiutil/math/numbers") |
| 55 | def wpilibNatFileOutput = file("$buildDir/generated/java/edu/wpi/first/wpiutil/math/Nat.java") |
| 56 | def maxNum = 20 |
| 57 | |
| 58 | task generateNumbers() { |
| 59 | description = "Generates generic number classes from template" |
| 60 | group = "WPILib" |
| 61 | |
| 62 | inputs.file wpilibNumberFileInput |
| 63 | outputs.dir wpilibNumberFileOutputDir |
| 64 | |
| 65 | doLast { |
| 66 | if(wpilibNumberFileOutputDir.exists()) { |
| 67 | wpilibNumberFileOutputDir.delete() |
| 68 | } |
| 69 | wpilibNumberFileOutputDir.mkdirs() |
| 70 | |
| 71 | for(i in 0..maxNum) { |
| 72 | def outputFile = new File(wpilibNumberFileOutputDir, "N${i}.java") |
| 73 | def read = wpilibNumberFileInput.text.replace('${num}', i.toString()) |
| 74 | outputFile.write(read) |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | task generateNat() { |
| 80 | description = "Generates Nat.java" |
| 81 | group = "WPILib" |
| 82 | inputs.files([natFileInput, natGetterInput]) |
| 83 | outputs.file wpilibNatFileOutput |
| 84 | dependsOn generateNumbers |
| 85 | |
| 86 | doLast { |
| 87 | if(wpilibNatFileOutput.exists()) { |
| 88 | wpilibNatFileOutput.delete() |
| 89 | } |
| 90 | |
| 91 | def template = natFileInput.text + "\n" |
| 92 | |
| 93 | def importsString = ""; |
| 94 | |
| 95 | for(i in 0..maxNum) { |
| 96 | importsString += "import edu.wpi.first.wpiutil.math.numbers.N${i};\n" |
| 97 | template += natGetterInput.text.replace('${num}', i.toString()) + "\n" |
| 98 | } |
| 99 | template += "}\n" // Close the class body |
| 100 | |
| 101 | template = template.replace('{{REPLACEWITHIMPORTS}}', importsString) |
| 102 | |
| 103 | wpilibNatFileOutput.write(template) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | sourceSets.main.java.srcDir "${buildDir}/generated/java" |
| 108 | compileJava.dependsOn generateNumbers |
| 109 | compileJava.dependsOn generateNat |