Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | plugins { |
| 2 | id 'cpp' |
| 3 | id 'java' |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 4 | id 'com.google.protobuf' version '0.8.17' |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 5 | id 'edu.wpi.first.NativeUtils' |
| 6 | } |
| 7 | |
| 8 | description = "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 */ |
| 11 | ext.skiplinuxathena = true |
| 12 | ext.skiplinuxraspbian = true |
| 13 | apply from: "${rootDir}/shared/config.gradle" |
| 14 | |
| 15 | /* Use a sort of poor man's autoconf to find the protobuf development |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 16 | 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 19 | |
| 20 | def protobuf_version = "" |
| 21 | try { |
| 22 | protobuf_version = "pkg-config --modversion protobuf".execute().text.trim() |
| 23 | println "Protobuf version is [${protobuf_version}]" |
| 24 | } catch(Exception ex) { |
| 25 | } |
| 26 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 27 | if (project.hasProperty("forceGazebo")) { |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 28 | if (!protobuf_version?.trim()) { |
| 29 | println "Protobuf is not available. (pkg-config --modversion protobuf failed)" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 30 | println "forceGazebo set. Forcing build - failure likely." |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 31 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 32 | } else { |
| 33 | ext.skip_gz_msgs = true |
| 34 | println "Skipping gz msgs." |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | tasks.whenTaskAdded { task -> |
| 38 | task.onlyIf { !project.hasProperty('skip_gz_msgs') } |
| 39 | } |
| 40 | |
| 41 | dependencies { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 42 | implementation "com.google.protobuf:protobuf-java:${protobuf_version}" |
| 43 | implementation "com.google.protobuf:protoc:${protobuf_version}" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | /* There is a nice gradle plugin for protobuf, and the protoc tool |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame^] | 47 | 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 50 | protobuf { |
| 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 | |
| 67 | model { |
| 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 86 | |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |