blob: 353f4ad2047dfc87ca516e2e9c4cd67c93d7f40c [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
29if (!protobuf_version?.trim()) {
30 println "Protobuf is not available. (pkg-config --modversion protobuf failed)"
31 protobuf_version = "+"
32 if (project.hasProperty("makeSim")) {
33 /* Force the build even though we did not find protobuf. */
34 println "makeSim set. Forcing build - failure likely."
35 }
36 else {
37 ext.skip_gz_msgs = true
38 println "Skipping gz_msgs."
39 }
40}
41
42tasks.whenTaskAdded { task ->
43 task.onlyIf { !project.hasProperty('skip_gz_msgs') }
44}
45
46dependencies {
47 implementation "com.google.protobuf:protobuf-java:${protobuf_version}"
48 implementation "com.google.protobuf:protoc:${protobuf_version}"
49}
50
51/* There is a nice gradle plugin for protobuf, and the protoc tool
52 is included; using it simplifies our build process.
53 The trick is that we have to use the same version as the system
54 copy of libprotobuf-dev */
55protobuf {
56 protoc {
57 artifact = "com.google.protobuf:protoc:${protobuf_version}"
58 }
59
60 generatedFilesBaseDir = "$buildDir/generated"
61 generateProtoTasks {
62 all().each { task ->
63 task.builtins {
64 cpp {
65 outputSubDir = 'simulation/gz_msgs'
66 }
67 }
68 }
69 }
70}
71
72model {
73 components {
74 gz_msgs(NativeLibrarySpec) {
75 sources {
76 cpp {
77 source {
78 srcDir "$buildDir/generated/main/simulation/gz_msgs"
79 builtBy tasks.generateProto
80 }
81 exportedHeaders {
82 srcDir "src/include"
83 srcDir "$buildDir/generated/main"
84 }
85 }
86 }
87 /* We must compile with -fPIC to link the static library into an so */
88 binaries {
89 all {
90 cppCompiler.args "-fPIC"
91 }
92 }
93 }
94 }
95}