Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -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 { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 33 | srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp" |
| 34 | include '**/*.cpp', '**/*.cc' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 35 | } |
| 36 | exportedHeaders { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 37 | srcDirs 'src/main/native/include', "$buildDir/generated/source/proto/main/cpp" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | } |
| 41 | binaries.all { |
| 42 | if (it instanceof SharedLibraryBinarySpec) { |
| 43 | it.buildable = false |
| 44 | return |
| 45 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 46 | it.tasks.withType(CppCompile) { |
| 47 | it.dependsOn generateProto |
| 48 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 49 | if (project.hasProperty('extraSetup')) { |
| 50 | extraSetup(it) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | "${nativeName}"(NativeLibrarySpec) { |
| 55 | sources { |
| 56 | cpp { |
| 57 | source { |
| 58 | srcDirs "${rootDir}/shared/singlelib" |
| 59 | include '**/*.cpp' |
| 60 | } |
| 61 | exportedHeaders { |
| 62 | srcDirs 'src/main/native/include' |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | appendDebugPathToBinaries(binaries) |
| 67 | } |
| 68 | // By default, a development executable will be generated. This is to help the case of |
| 69 | // testing specific functionality of the library. |
| 70 | "${nativeName}Dev"(NativeExecutableSpec) { |
| 71 | targetBuildTypes 'debug' |
| 72 | sources { |
| 73 | cpp { |
| 74 | source { |
| 75 | srcDirs 'src/dev/native/cpp' |
| 76 | include '**/*.cpp' |
| 77 | lib library: nativeName |
| 78 | } |
| 79 | exportedHeaders { |
| 80 | srcDirs 'src/dev/native/include' |
| 81 | } |
| 82 | } |
| 83 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 84 | binaries.all { |
| 85 | lib library: nativeName, linkage: 'shared' |
| 86 | if (!project.hasProperty('noWpiutil')) { |
| 87 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 88 | if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 89 | nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries') |
| 90 | } |
| 91 | } |
| 92 | if (project.hasProperty('exeSplitSetup')) { |
| 93 | exeSplitSetup(it) |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | "${nativeName}TestLib"(NativeLibrarySpec) { |
| 98 | sources { |
| 99 | cpp { |
| 100 | source { |
| 101 | srcDirs 'src/testlib/native/cpp' |
| 102 | include '**/*.cpp' |
| 103 | } |
| 104 | exportedHeaders { |
| 105 | srcDirs 'src/test/native/include' |
| 106 | } |
| 107 | } |
| 108 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | testSuites { |
| 112 | "${nativeName}Test"(GoogleTestTestSuiteSpec) { |
| 113 | for(NativeComponentSpec c : $.components) { |
| 114 | if (c.name == nativeName) { |
| 115 | testing c |
| 116 | break |
| 117 | } |
| 118 | } |
| 119 | sources { |
| 120 | cpp { |
| 121 | source { |
| 122 | srcDirs 'src/test/native/cpp' |
| 123 | include '**/*.cpp' |
| 124 | } |
| 125 | exportedHeaders { |
| 126 | srcDirs 'src/test/native/include', 'src/main/native/cpp' |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | binaries { |
| 133 | withType(GoogleTestTestSuiteBinarySpec) { |
| 134 | lib library: nativeName, linkage: 'shared' |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 135 | lib library: "${nativeName}TestLib", linkage: 'shared' |
| 136 | if (!project.hasProperty('noWpiutil')) { |
| 137 | lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' |
| 138 | lib project: ':wpiutil', library: 'wpiutilTestLib', linkage: 'shared' |
| 139 | if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) { |
| 140 | nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries') |
| 141 | } |
| 142 | } |
| 143 | if (project.hasProperty('exeSplitSetup')) { |
| 144 | exeSplitSetup(it) |
| 145 | } |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | tasks { |
| 149 | def c = $.components |
| 150 | project.tasks.create('runCpp', Exec) { |
| 151 | group = 'WPILib' |
| 152 | description = "Run the ${nativeName}Dev executable" |
| 153 | def found = false |
| 154 | def systemArch = getCurrentArch() |
| 155 | c.each { |
| 156 | if (it in NativeExecutableSpec && it.name == "${nativeName}Dev") { |
| 157 | it.binaries.each { |
| 158 | if (!found) { |
| 159 | def arch = it.targetPlatform.name |
| 160 | if (arch == systemArch) { |
| 161 | dependsOn it.tasks.install |
| 162 | commandLine it.tasks.install.runScriptFile.get().asFile.toString() |
| 163 | def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' |
| 164 | test.dependsOn it.tasks.install |
| 165 | test.systemProperty 'java.library.path', filePath |
| 166 | test.environment 'LD_LIBRARY_PATH', filePath |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 167 | test.environment 'DYLD_LIBRARY_PATH', filePath |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 168 | test.workingDir filePath |
| 169 | run.dependsOn it.tasks.install |
| 170 | run.systemProperty 'java.library.path', filePath |
| 171 | run.environment 'LD_LIBRARY_PATH', filePath |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 172 | run.environment 'DYLD_LIBRARY_PATH', filePath |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 173 | run.workingDir filePath |
| 174 | |
| 175 | found = true |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 185 | apply from: "${rootDir}/shared/cppJavaDesktopTestTask.gradle" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 186 | |
| 187 | tasks.withType(RunTestExecutable) { |
| 188 | args "--gtest_output=xml:test_detail.xml" |
| 189 | outputs.dir outputDir |
| 190 | } |
| 191 | |
| 192 | apply from: "${rootDir}/shared/javacpp/publish.gradle" |