Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | apply plugin: 'cpp' |
| 2 | apply plugin: 'google-test-test-suite' |
| 3 | apply plugin: 'visual-studio' |
| 4 | apply plugin: 'edu.wpi.first.NativeUtils' |
| 5 | apply plugin: SingleNativeBuild |
| 6 | apply plugin: ExtraTasks |
| 7 | |
| 8 | apply from: "${rootDir}/shared/config.gradle" |
| 9 | |
| 10 | ext { |
| 11 | baseId = nativeName |
| 12 | groupId = "edu.wpi.first.${nativeName}" |
| 13 | } |
| 14 | |
| 15 | apply from: "${rootDir}/shared/java/javacommon.gradle" |
| 16 | |
| 17 | project(':').libraryBuild.dependsOn build |
| 18 | |
| 19 | ext { |
| 20 | staticGtestConfigs = [:] |
| 21 | } |
| 22 | |
| 23 | staticGtestConfigs["${nativeName}Test"] = [] |
| 24 | |
| 25 | apply from: "${rootDir}/shared/googletest.gradle" |
| 26 | |
| 27 | model { |
| 28 | components { |
| 29 | "${nativeName}Base"(NativeLibrarySpec) { |
| 30 | sources { |
| 31 | cpp { |
| 32 | source { |
| 33 | srcDirs 'src/main/native/cpp' |
| 34 | include '**/*.cpp' |
| 35 | } |
| 36 | exportedHeaders { |
| 37 | srcDirs 'src/main/native/include' |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | binaries.all { |
| 42 | if (it instanceof SharedLibraryBinarySpec) { |
| 43 | it.buildable = false |
| 44 | return |
| 45 | } |
| 46 | if (project.hasProperty('extraSetup')) { |
| 47 | extraSetup(it) |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | "${nativeName}"(NativeLibrarySpec) { |
| 52 | sources { |
| 53 | cpp { |
| 54 | source { |
| 55 | srcDirs "${rootDir}/shared/singlelib" |
| 56 | include '**/*.cpp' |
| 57 | } |
| 58 | exportedHeaders { |
| 59 | srcDirs 'src/main/native/include' |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | appendDebugPathToBinaries(binaries) |
| 64 | } |
| 65 | // By default, a development executable will be generated. This is to help the case of |
| 66 | // testing specific functionality of the library. |
| 67 | "${nativeName}Dev"(NativeExecutableSpec) { |
| 68 | targetBuildTypes 'debug' |
| 69 | sources { |
| 70 | cpp { |
| 71 | source { |
| 72 | srcDirs 'src/dev/native/cpp' |
| 73 | include '**/*.cpp' |
| 74 | lib library: nativeName |
| 75 | } |
| 76 | exportedHeaders { |
| 77 | srcDirs 'src/dev/native/include' |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | testSuites { |
| 84 | "${nativeName}Test"(GoogleTestTestSuiteSpec) { |
| 85 | for(NativeComponentSpec c : $.components) { |
| 86 | if (c.name == nativeName) { |
| 87 | testing c |
| 88 | break |
| 89 | } |
| 90 | } |
| 91 | sources { |
| 92 | cpp { |
| 93 | source { |
| 94 | srcDirs 'src/test/native/cpp' |
| 95 | include '**/*.cpp' |
| 96 | } |
| 97 | exportedHeaders { |
| 98 | srcDirs 'src/test/native/include', 'src/main/native/cpp' |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | binaries { |
| 105 | withType(GoogleTestTestSuiteBinarySpec) { |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 106 | lib library: nativeName, linkage: 'shared' |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | tasks { |
| 110 | def c = $.components |
| 111 | project.tasks.create('runCpp', Exec) { |
| 112 | group = 'WPILib' |
| 113 | description = "Run the ${nativeName}Dev executable" |
| 114 | def found = false |
| 115 | def systemArch = getCurrentArch() |
| 116 | c.each { |
| 117 | if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") { |
| 118 | it.binaries.each { |
| 119 | if (!found) { |
James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 120 | def arch = it.targetPlatform.name |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 121 | if (arch == systemArch) { |
| 122 | dependsOn it.tasks.install |
| 123 | commandLine it.tasks.install.runScriptFile.get().asFile.toString() |
| 124 | def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' |
| 125 | test.dependsOn it.tasks.install |
| 126 | test.systemProperty 'java.library.path', filePath |
| 127 | test.environment 'LD_LIBRARY_PATH', filePath |
| 128 | test.workingDir filePath |
| 129 | run.dependsOn it.tasks.install |
| 130 | run.systemProperty 'java.library.path', filePath |
| 131 | run.environment 'LD_LIBRARY_PATH', filePath |
| 132 | run.workingDir filePath |
| 133 | |
| 134 | found = true |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
James Kuszmaul | 397f6fe | 2020-01-04 16:21:52 -0800 | [diff] [blame] | 144 | apply from: "${rootDir}/shared/cppDesktopTestTask.gradle" |
| 145 | apply from: "${rootDir}/shared/javaDesktopTestTask.gradle" |
| 146 | |
Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 147 | tasks.withType(RunTestExecutable) { |
| 148 | args "--gtest_output=xml:test_detail.xml" |
| 149 | outputs.dir outputDir |
| 150 | } |
| 151 | |
| 152 | apply from: "${rootDir}/shared/javacpp/publish.gradle" |