blob: d07dc09f3974a9a9ed6e815607a16ac7573a5f4e [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001plugins {
2 id 'cpp'
3 id 'java'
4 id 'com.google.protobuf' version '0.8.8'
5 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
16 files; on Debian, those are supplied by libprotobuf-dev.
17
18 This should get skipped on Windows.
19
20 TODO: Add Windows support for the simulation code */
21
22def protobuf_version = ""
23try {
24 protobuf_version = "pkg-config --modversion protobuf".execute().text.trim()
25 println "Protobuf version is [${protobuf_version}]"
26} catch(Exception ex) {
27}
28
Austin Schuh1e69f942020-11-14 15:06:14 -080029if (project.hasProperty("makeSim")) {
30 if (!protobuf_version?.trim()) {
31 println "Protobuf is not available. (pkg-config --modversion protobuf failed)"
Brian Silverman8fce7482020-01-05 13:18:21 -080032 println "makeSim set. Forcing build - failure likely."
33 }
Austin Schuh1e69f942020-11-14 15:06:14 -080034} else {
35 ext.skip_gz_msgs = true
36 println "Skipping gz msgs."
Brian Silverman8fce7482020-01-05 13:18:21 -080037}
38
39tasks.whenTaskAdded { task ->
40 task.onlyIf { !project.hasProperty('skip_gz_msgs') }
41}
42
43dependencies {
44 implementation "com.google.protobuf:protobuf-java:${protobuf_version}"
45 implementation "com.google.protobuf:protoc:${protobuf_version}"
46}
47
48/* There is a nice gradle plugin for protobuf, and the protoc tool
49 is included; using it simplifies our build process.
50 The trick is that we have to use the same version as the system
51 copy of libprotobuf-dev */
52protobuf {
53 protoc {
54 artifact = "com.google.protobuf:protoc:${protobuf_version}"
55 }
56
57 generatedFilesBaseDir = "$buildDir/generated"
58 generateProtoTasks {
59 all().each { task ->
60 task.builtins {
61 cpp {
62 outputSubDir = 'simulation/gz_msgs'
63 }
64 }
65 }
66 }
67}
68
69model {
70 components {
71 gz_msgs(NativeLibrarySpec) {
72 sources {
73 cpp {
74 source {
75 srcDir "$buildDir/generated/main/simulation/gz_msgs"
76 builtBy tasks.generateProto
77 }
78 exportedHeaders {
79 srcDir "src/include"
80 srcDir "$buildDir/generated/main"
81 }
82 }
83 }
84 /* We must compile with -fPIC to link the static library into an so */
85 binaries {
86 all {
87 cppCompiler.args "-fPIC"
Austin Schuh1e69f942020-11-14 15:06:14 -080088
89 // Disable -Wzero-length-array on Clang
90 if (it.targetPlatform.operatingSystem.isMacOsX()) {
91 it.cppCompiler.args.add('-Wno-error=zero-length-array')
92 }
Brian Silverman8fce7482020-01-05 13:18:21 -080093 }
94 }
95 }
96 }
97}