blob: b9689e96b35af6ab069c0a1eec680d157e7acc12 [file] [log] [blame]
James Kuszmaulb13e13f2023-11-22 20:44:04 -08001import org.gradle.internal.os.OperatingSystem
2
3if (project.hasProperty('onlylinuxathena')) {
4 return;
5}
6
7description = 'System identification for robot mechanisms'
8
9apply plugin: 'cpp'
10apply plugin: 'google-test-test-suite'
11apply plugin: 'visual-studio'
12apply plugin: 'edu.wpi.first.NativeUtils'
13
14if (OperatingSystem.current().isWindows()) {
15 apply plugin: 'windows-resources'
16}
17
18ext {
19 nativeName = 'sysid'
20}
21
22apply from: "${rootDir}/shared/resources.gradle"
23apply from: "${rootDir}/shared/config.gradle"
24
25def wpilibVersionFileInput = file("src/main/generate/WPILibVersion.cpp.in")
26def wpilibVersionFileOutput = file("$buildDir/generated/main/cpp/WPILibVersion.cpp")
27
28apply from: "${rootDir}/shared/imgui.gradle"
29
30task generateCppVersion() {
31 description = 'Generates the wpilib version class'
32 group = 'WPILib'
33
34 outputs.file wpilibVersionFileOutput
35 inputs.file wpilibVersionFileInput
36
37 if (wpilibVersioning.releaseMode) {
38 outputs.upToDateWhen { false }
39 }
40
41 // We follow a simple set of checks to determine whether we should generate a new version file:
42 // 1. If the release type is not development, we generate a new version file
43 // 2. If there is no generated version number, we generate a new version file
44 // 3. If there is a generated build number, and the release type is development, then we will
45 // only generate if the publish task is run.
46 doLast {
47 def version = wpilibVersioning.version.get()
48 println "Writing version ${version} to $wpilibVersionFileOutput"
49
50 if (wpilibVersionFileOutput.exists()) {
51 wpilibVersionFileOutput.delete()
52 }
53 def read = wpilibVersionFileInput.text.replace('${wpilib_version}', version)
54 wpilibVersionFileOutput.write(read)
55 }
56}
57
58gradle.taskGraph.addTaskExecutionGraphListener { graph ->
59 def willPublish = graph.hasTask(publish)
60 if (willPublish) {
61 generateCppVersion.outputs.upToDateWhen { false }
62 }
63}
64
65def generateTask = createGenerateResourcesTask('main', 'SYSID', 'sysid', project)
66
67project(':').libraryBuild.dependsOn build
68tasks.withType(CppCompile) {
69 dependsOn generateTask
70 dependsOn generateCppVersion
71}
72
73model {
74 components {
75 // By default, a development executable will be generated. This is to help the case of
76 // testing specific functionality of the library.
77 "${nativeName}"(NativeExecutableSpec) {
78 baseName = 'sysid'
79 sources {
80 cpp {
81 source {
82 srcDirs 'src/main/native/cpp', "$buildDir/generated/main/cpp"
83 include '**/*.cpp'
84 }
85 exportedHeaders {
86 srcDirs 'src/main/native/include'
87 }
88 }
89 if (OperatingSystem.current().isWindows()) {
90 rc.source {
91 srcDirs 'src/main/native/win'
92 include '*.rc'
93 }
94 }
95 }
96 binaries.all {
97 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
98 it.buildable = false
99 return
100 }
101 lib project: ':glass', library: 'glassnt', linkage: 'static'
102 lib project: ':glass', library: 'glass', linkage: 'static'
103 project(':ntcore').addNtcoreDependency(it, 'static')
104 lib project: ':wpinet', library: 'wpinet', linkage: 'static'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800105 lib project: ':wpimath', library: 'wpimath', linkage: 'static'
Maxwell Henderson80bec322024-01-09 15:48:44 -0800106 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800107 lib project: ':wpigui', library: 'wpigui', linkage: 'static'
108 nativeUtils.useRequiredLibrary(it, 'imgui')
109 if (it.targetPlatform.operatingSystem.isWindows()) {
110 it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib'
111 it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind'
112 } else if (it.targetPlatform.operatingSystem.isMacOsX()) {
113 it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore'
114 if (it.buildType.getName() == "release") {
115 it.linker.args << '-s'
116 }
117 } else {
118 it.linker.args << '-lX11'
119 if (it.targetPlatform.name.startsWith('linuxarm')) {
120 it.linker.args << '-lGL'
121 }
122 }
123 }
124 }
125 }
126 testSuites {
127 "${nativeName}Test"(GoogleTestTestSuiteSpec) {
128 for (NativeComponentSpec c : $.components) {
129 if (c.name == nativeName) {
130 testing c
131 break
132 }
133 }
134 sources.cpp.source {
135 srcDirs "src/test/native/cpp"
136 include "**/*.cpp"
137 }
138 binaries.all {
139 if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
140 it.buildable = false
141 return
142 }
143 lib project: ':glass', library: 'glassnt', linkage: 'static'
144 lib project: ':glass', library: 'glass', linkage: 'static'
145 project(':ntcore').addNtcoreDependency(it, 'static')
146 lib project: ':wpinet', library: 'wpinet', linkage: 'static'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800147 lib project: ':wpimath', library: 'wpimath', linkage: 'static'
Maxwell Henderson80bec322024-01-09 15:48:44 -0800148 lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800149 lib project: ':wpigui', library: 'wpigui', linkage: 'static'
150 nativeUtils.useRequiredLibrary(it, 'imgui')
151 if (it.targetPlatform.operatingSystem.isWindows()) {
152 it.linker.args << 'Gdi32.lib' << 'Shell32.lib' << 'd3d11.lib' << 'd3dcompiler.lib'
153 it.linker.args << '/DELAYLOAD:MF.dll' << '/DELAYLOAD:MFReadWrite.dll' << '/DELAYLOAD:MFPlat.dll' << '/delay:nobind'
154 } else if (it.targetPlatform.operatingSystem.isMacOsX()) {
155 it.linker.args << '-framework' << 'Metal' << '-framework' << 'MetalKit' << '-framework' << 'Cocoa' << '-framework' << 'IOKit' << '-framework' << 'CoreFoundation' << '-framework' << 'CoreVideo' << '-framework' << 'QuartzCore'
156 if (it.buildType.getName() == "release") {
157 it.linker.args << '-s'
158 }
159 } else {
160 it.linker.args << '-lX11'
161 if (it.targetPlatform.name.startsWith('linuxarm')) {
162 it.linker.args << '-lGL'
163 }
164 }
165 nativeUtils.useRequiredLibrary(it, "googletest_static")
166 it.cppCompiler.define("RUNNING_SYSID_TESTS")
167 }
168 }
169 }
170}
171
172apply from: 'publish.gradle'