blob: 04086ad4e51c4c7ae76aa2293a6bdff82e293f30 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001apply plugin: 'cpp'
2apply plugin: 'google-test-test-suite'
3apply plugin: 'visual-studio'
4apply plugin: 'edu.wpi.first.NativeUtils'
5apply plugin: SingleNativeBuild
6apply plugin: ExtraTasks
7
8apply from: "${rootDir}/shared/config.gradle"
9
10ext {
11 baseId = nativeName
12 groupId = "edu.wpi.first.${nativeName}"
13}
14
15apply from: "${rootDir}/shared/java/javacommon.gradle"
16
17project(':').libraryBuild.dependsOn build
18
19ext {
20 staticGtestConfigs = [:]
21}
22
23staticGtestConfigs["${nativeName}Test"] = []
24
25apply from: "${rootDir}/shared/googletest.gradle"
26
27model {
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 Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800106 lib library: nativeName, linkage: 'shared'
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800107 }
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 Kuszmaul4f3ad3c2019-12-01 16:35:21 -0800120 def arch = it.targetPlatform.name
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800121 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 Kuszmaul397f6fe2020-01-04 16:21:52 -0800144apply from: "${rootDir}/shared/cppDesktopTestTask.gradle"
145apply from: "${rootDir}/shared/javaDesktopTestTask.gradle"
146
Brian Silverman41cdd3e2019-01-19 19:48:58 -0800147tasks.withType(RunTestExecutable) {
148 args "--gtest_output=xml:test_detail.xml"
149 outputs.dir outputDir
150}
151
152apply from: "${rootDir}/shared/javacpp/publish.gradle"