Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | plugins { |
| 2 | id 'cpp' |
| 3 | id 'java' |
| 4 | id 'com.google.protobuf' version '0.8.8' |
| 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 |
| 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 | |
| 22 | def protobuf_version = "" |
| 23 | try { |
| 24 | protobuf_version = "pkg-config --modversion protobuf".execute().text.trim() |
| 25 | println "Protobuf version is [${protobuf_version}]" |
| 26 | } catch(Exception ex) { |
| 27 | } |
| 28 | |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 29 | if (project.hasProperty("makeSim")) { |
| 30 | if (!protobuf_version?.trim()) { |
| 31 | println "Protobuf is not available. (pkg-config --modversion protobuf failed)" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 32 | println "makeSim set. Forcing build - failure likely." |
| 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 | |
| 43 | dependencies { |
| 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 */ |
| 52 | protobuf { |
| 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 | |
| 69 | model { |
| 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 Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 88 | |
| 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 Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |