blob: 31f3df498584f4769cdf048d315ae81029f92a98 [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 Schuh75263e32022-02-22 18:05:32 -080027ext.skip_gz_msgs = false
28
Austin Schuh812d0d12021-11-04 20:16:48 -070029if (project.hasProperty("forceGazebo")) {
Austin Schuh1e69f942020-11-14 15:06:14 -080030 if (!protobuf_version?.trim()) {
31 println "Protobuf is not available. (pkg-config --modversion protobuf failed)"
Austin Schuh812d0d12021-11-04 20:16:48 -070032 println "forceGazebo set. Forcing build - failure likely."
Brian Silverman8fce7482020-01-05 13:18:21 -080033 }
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
Austin Schuh75263e32022-02-22 18:05:32 -080043if (!ext.skip_gz_msgs) {
44 dependencies {
45 implementation "com.google.protobuf:protobuf-java:${protobuf_version}"
46 implementation "com.google.protobuf:protoc:${protobuf_version}"
47 }
Brian Silverman8fce7482020-01-05 13:18:21 -080048}
49
50/* There is a nice gradle plugin for protobuf, and the protoc tool
Austin Schuh812d0d12021-11-04 20:16:48 -070051 is included; using it simplifies our build process.
52 The trick is that we have to use the same version as the system
53 copy of libprotobuf-dev */
Brian Silverman8fce7482020-01-05 13:18:21 -080054protobuf {
55 protoc {
56 artifact = "com.google.protobuf:protoc:${protobuf_version}"
57 }
58
59 generatedFilesBaseDir = "$buildDir/generated"
60 generateProtoTasks {
61 all().each { task ->
62 task.builtins {
63 cpp {
64 outputSubDir = 'simulation/gz_msgs'
65 }
66 }
67 }
68 }
69}
70
71model {
72 components {
73 gz_msgs(NativeLibrarySpec) {
74 sources {
75 cpp {
76 source {
77 srcDir "$buildDir/generated/main/simulation/gz_msgs"
78 builtBy tasks.generateProto
79 }
80 exportedHeaders {
81 srcDir "src/include"
82 srcDir "$buildDir/generated/main"
83 }
84 }
85 }
86 /* We must compile with -fPIC to link the static library into an so */
87 binaries {
88 all {
89 cppCompiler.args "-fPIC"
Austin Schuh1e69f942020-11-14 15:06:14 -080090
91 // Disable -Wzero-length-array on Clang
92 if (it.targetPlatform.operatingSystem.isMacOsX()) {
93 it.cppCompiler.args.add('-Wno-error=zero-length-array')
94 }
Brian Silverman8fce7482020-01-05 13:18:21 -080095 }
96 }
97 }
98 }
99}