blob: ccc933efa00e5b082ed15eb40ea039bdb92b31db [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001plugins {
2 id 'cpp'
3 id 'java'
Austin Schuh812d0d12021-11-04 20:16:48 -07004 id 'com.google.protobuf' version '0.8.17'
Brian Silverman8fce7482020-01-05 13:18:21 -08005 id 'edu.wpi.first.NativeUtils'
6}
7
8description = "A C++ and Java library to pass FRC Simulation Messages in and out of Gazebo."
9
10/* The simulation does not run on real hardware; so we always skip Athena */
11ext.skiplinuxathena = true
12ext.skiplinuxraspbian = true
13apply from: "${rootDir}/shared/config.gradle"
14
15/* Use a sort of poor man's autoconf to find the protobuf development
Austin Schuh812d0d12021-11-04 20:16:48 -070016 files; on Debian, those are supplied by libprotobuf-dev.
17 This should get skipped on Windows.
18 TODO: Add Windows support for the simulation code */
Brian Silverman8fce7482020-01-05 13:18:21 -080019
20def protobuf_version = ""
21try {
22 protobuf_version = "pkg-config --modversion protobuf".execute().text.trim()
23 println "Protobuf version is [${protobuf_version}]"
24} catch(Exception ex) {
25}
26
Austin Schuh812d0d12021-11-04 20:16:48 -070027if (project.hasProperty("forceGazebo")) {
Austin Schuh1e69f942020-11-14 15:06:14 -080028 if (!protobuf_version?.trim()) {
29 println "Protobuf is not available. (pkg-config --modversion protobuf failed)"
Austin Schuh812d0d12021-11-04 20:16:48 -070030 println "forceGazebo set. Forcing build - failure likely."
Brian Silverman8fce7482020-01-05 13:18:21 -080031 }
Austin Schuh1e69f942020-11-14 15:06:14 -080032} else {
33 ext.skip_gz_msgs = true
34 println "Skipping gz msgs."
Brian Silverman8fce7482020-01-05 13:18:21 -080035}
36
37tasks.whenTaskAdded { task ->
38 task.onlyIf { !project.hasProperty('skip_gz_msgs') }
39}
40
41dependencies {
Austin Schuh812d0d12021-11-04 20:16:48 -070042 implementation "com.google.protobuf:protobuf-java:${protobuf_version}"
43 implementation "com.google.protobuf:protoc:${protobuf_version}"
Brian Silverman8fce7482020-01-05 13:18:21 -080044}
45
46/* There is a nice gradle plugin for protobuf, and the protoc tool
Austin Schuh812d0d12021-11-04 20:16:48 -070047 is included; using it simplifies our build process.
48 The trick is that we have to use the same version as the system
49 copy of libprotobuf-dev */
Brian Silverman8fce7482020-01-05 13:18:21 -080050protobuf {
51 protoc {
52 artifact = "com.google.protobuf:protoc:${protobuf_version}"
53 }
54
55 generatedFilesBaseDir = "$buildDir/generated"
56 generateProtoTasks {
57 all().each { task ->
58 task.builtins {
59 cpp {
60 outputSubDir = 'simulation/gz_msgs'
61 }
62 }
63 }
64 }
65}
66
67model {
68 components {
69 gz_msgs(NativeLibrarySpec) {
70 sources {
71 cpp {
72 source {
73 srcDir "$buildDir/generated/main/simulation/gz_msgs"
74 builtBy tasks.generateProto
75 }
76 exportedHeaders {
77 srcDir "src/include"
78 srcDir "$buildDir/generated/main"
79 }
80 }
81 }
82 /* We must compile with -fPIC to link the static library into an so */
83 binaries {
84 all {
85 cppCompiler.args "-fPIC"
Austin Schuh1e69f942020-11-14 15:06:14 -080086
87 // Disable -Wzero-length-array on Clang
88 if (it.targetPlatform.operatingSystem.isMacOsX()) {
89 it.cppCompiler.args.add('-Wno-error=zero-length-array')
90 }
Brian Silverman8fce7482020-01-05 13:18:21 -080091 }
92 }
93 }
94 }
95}