John Park | 7eb9042 | 2018-01-27 12:04:57 -0800 | [diff] [blame] | 1 | import edu.wpi.first.nativeutils.NativeUtils |
| 2 | |
| 3 | buildscript { |
| 4 | repositories { |
| 5 | mavenLocal() |
| 6 | maven { |
| 7 | url "https://plugins.gradle.org/m2/" |
| 8 | } |
| 9 | } |
| 10 | dependencies { |
| 11 | classpath 'gradle.plugin.edu.wpi.first:native-utils:1.5.1' |
| 12 | classpath 'gradle.plugin.edu.wpi.first.wpilib.versioning:wpilib-version-plugin:2.0' |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | ext.getClassifier = { binary-> |
| 17 | return NativeUtils.getClassifier(binary) |
| 18 | } |
| 19 | |
| 20 | ext.getPlatformPath = { binary-> |
| 21 | return NativeUtils.getPlatformPath(binary) |
| 22 | } |
| 23 | |
| 24 | apply plugin: 'cpp' |
| 25 | apply plugin: 'google-test' |
| 26 | apply plugin: 'visual-studio' |
| 27 | apply plugin: 'edu.wpi.first.NativeUtils' |
| 28 | apply plugin: 'java' |
| 29 | |
| 30 | apply from: 'config.gradle' |
| 31 | |
| 32 | sourceSets { |
| 33 | dev |
| 34 | } |
| 35 | |
| 36 | task run(type: JavaExec) { |
| 37 | classpath = sourceSets.dev.runtimeClasspath |
| 38 | |
| 39 | main = 'edu.wpi.first.wpiutil.DevMain' |
| 40 | } |
| 41 | |
| 42 | build.dependsOn devClasses |
| 43 | |
| 44 | dependencies { |
| 45 | testCompile 'junit:junit:4.12' |
| 46 | devCompile sourceSets.main.output |
| 47 | } |
| 48 | |
| 49 | model { |
| 50 | // Exports config is a utility to enable exporting all symbols in a C++ library on windows to a DLL. |
| 51 | // This removes the need for DllExport on a library. However, the gradle C++ builder has a bug |
| 52 | // where some extra symbols are added that cannot be resolved at link time. This configuration |
| 53 | // lets you specify specific symbols to exlude from exporting. |
| 54 | exportsConfigs { |
| 55 | wpiutil(ExportsConfig) { |
| 56 | x86ExcludeSymbols = [ '_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure', |
| 57 | '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure', |
| 58 | '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range', |
| 59 | '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast' ] |
| 60 | x64ExcludeSymbols = [ '_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure', |
| 61 | '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure', |
| 62 | '_TI5?AVfailure', '_CT??_R0?AVout_of_range', '_CTA3?AVout_of_range', |
| 63 | '_TI3?AVout_of_range', '_CT??_R0?AVbad_cast' ] |
| 64 | } |
| 65 | } |
| 66 | jniConfigs { |
| 67 | wpiutilTestingBaseTest(JNIConfig) { |
| 68 | jniArmHeaderLocations = [ all: file("${rootDir}/src/arm-linux-jni") ] |
| 69 | onlyIncludeSystemHeaders = true |
| 70 | } |
| 71 | } |
| 72 | components { |
| 73 | wpiutil(NativeLibrarySpec) { |
| 74 | sources { |
| 75 | cpp { |
| 76 | source { |
| 77 | srcDirs 'src/main/native/cpp' |
| 78 | include '**/*.cpp' |
| 79 | } |
| 80 | exportedHeaders { |
| 81 | srcDirs 'src/main/native/include' |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | // By default, a development executable will be generated. This is to help the case of |
| 87 | // testing specific functionality of the library. |
| 88 | if (!project.hasProperty('skipDevExe')) { |
| 89 | wpiutilDev(NativeExecutableSpec) { |
| 90 | sources { |
| 91 | cpp { |
| 92 | source { |
| 93 | srcDirs 'src/dev/native/cpp' |
| 94 | include '**/*.cpp' |
| 95 | lib library: "wpiutil" |
| 96 | } |
| 97 | exportedHeaders { |
| 98 | srcDirs 'src/dev/native/include' |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | // The TestingBase library is a workaround for an issue with the GoogleTest plugin. |
| 105 | // The plugin by default will rebuild the entire test source set, which increases |
| 106 | // build time. By testing an empty library, and then just linking the already built component |
| 107 | // into the test, we save the extra build |
| 108 | wpiutilTestingBase(NativeLibrarySpec) { } |
| 109 | } |
| 110 | testSuites { |
| 111 | wpiutilTestingBaseTest { |
| 112 | sources { |
| 113 | cpp { |
| 114 | source { |
| 115 | srcDirs 'src/test/native/cpp' |
| 116 | include '**/*.cpp' |
| 117 | } |
| 118 | exportedHeaders { |
| 119 | srcDirs 'src/test/native/include', 'src/main/native/cpp' |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | binaries { |
| 126 | withType(GoogleTestTestSuiteBinarySpec) { |
| 127 | if (it.component.testedComponent.name.contains('TestingBase') && !project.hasProperty('onlyAthena')) { |
| 128 | lib project: ':gmock', library: 'gmock', linkage: 'static' |
| 129 | lib library: 'wpiutil', linkage: 'shared' |
| 130 | } else { |
| 131 | it.buildable = false |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | tasks { |
| 136 | def c = $.components |
| 137 | project.tasks.create('runCpp', Exec) { |
| 138 | def found = false |
| 139 | c.each { |
| 140 | if (it in NativeExecutableSpec && it.name == 'wpiutilDev') { |
| 141 | it.binaries.each { |
| 142 | if (!found) { |
| 143 | def arch = it.targetPlatform.architecture.name |
| 144 | if (arch == 'x86-64' || arch == 'x86') { |
| 145 | dependsOn it.tasks.install |
| 146 | commandLine it.tasks.install.runScript |
| 147 | found = true |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | getHeaders(Task) { |
| 155 | def list = [] |
| 156 | $.components.each { |
| 157 | if (it in NativeLibrarySpec && (it.name == 'wpiutil')) { |
| 158 | it.sources.each { |
| 159 | it.exportedHeaders.srcDirs.each { |
| 160 | list.add(it) |
| 161 | } |
| 162 | } |
| 163 | it.binaries.each { |
| 164 | it.libs.each { |
| 165 | it.includeRoots.each { |
| 166 | list.add(it) |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | list = list.unique(false) |
| 173 | doLast { |
| 174 | list.each { |
| 175 | print "WPIHEADER: " |
| 176 | println it |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | apply from: 'publish.gradle' |
| 184 | |
| 185 | task wrapper(type: Wrapper) { |
| 186 | gradleVersion = '4.1' |
| 187 | } |