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 | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame^] | 27 | ext.skip_gz_msgs = false |
| 28 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 29 | if (project.hasProperty("forceGazebo")) { |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 30 | if (!protobuf_version?.trim()) { |
| 31 | println "Protobuf is not available. (pkg-config --modversion protobuf failed)" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 32 | println "forceGazebo set. Forcing build - failure likely." |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 33 | } |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 34 | } else { |
| 35 | ext.skip_gz_msgs = true |
| 36 | println "Skipping gz msgs." |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | tasks.whenTaskAdded { task -> |
| 40 | task.onlyIf { !project.hasProperty('skip_gz_msgs') } |
| 41 | } |
| 42 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame^] | 43 | if (!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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /* There is a nice gradle plugin for protobuf, and the protoc tool |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 51 | 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 54 | protobuf { |
| 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 | |
| 71 | model { |
| 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame] | 90 | |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |