blob: 1f3ff10acc152bd53def2f0bd121b28067022207 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -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 {
James Kuszmaulb13e13f2023-11-22 20:44:04 -080033 srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp"
34 include '**/*.cpp', '**/*.cc'
Brian Silverman8fce7482020-01-05 13:18:21 -080035 }
36 exportedHeaders {
James Kuszmaulb13e13f2023-11-22 20:44:04 -080037 srcDirs 'src/main/native/include', "$buildDir/generated/source/proto/main/cpp"
Brian Silverman8fce7482020-01-05 13:18:21 -080038 }
39 }
40 }
41 binaries.all {
42 if (it instanceof SharedLibraryBinarySpec) {
43 it.buildable = false
44 return
45 }
James Kuszmaulb13e13f2023-11-22 20:44:04 -080046 it.tasks.withType(CppCompile) {
47 it.dependsOn generateProto
48 }
Brian Silverman8fce7482020-01-05 13:18:21 -080049 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080084 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 Silverman8fce7482020-01-05 13:18:21 -0800109 }
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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800135 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 Silverman8fce7482020-01-05 13:18:21 -0800146 }
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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800167 test.environment 'DYLD_LIBRARY_PATH', filePath
Brian Silverman8fce7482020-01-05 13:18:21 -0800168 test.workingDir filePath
169 run.dependsOn it.tasks.install
170 run.systemProperty 'java.library.path', filePath
171 run.environment 'LD_LIBRARY_PATH', filePath
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800172 run.environment 'DYLD_LIBRARY_PATH', filePath
Brian Silverman8fce7482020-01-05 13:18:21 -0800173 run.workingDir filePath
174
175 found = true
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183}
184
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800185apply from: "${rootDir}/shared/cppJavaDesktopTestTask.gradle"
Brian Silverman8fce7482020-01-05 13:18:21 -0800186
187tasks.withType(RunTestExecutable) {
188 args "--gtest_output=xml:test_detail.xml"
189 outputs.dir outputDir
190}
191
192apply from: "${rootDir}/shared/javacpp/publish.gradle"