blob: 31f3df498584f4769cdf048d315ae81029f92a98 [file] [log] [blame]
plugins {
id 'cpp'
id 'java'
id 'com.google.protobuf' version '0.8.17'
id 'edu.wpi.first.NativeUtils'
}
description = "A C++ and Java library to pass FRC Simulation Messages in and out of Gazebo."
/* The simulation does not run on real hardware; so we always skip Athena */
ext.skiplinuxathena = true
ext.skiplinuxraspbian = true
apply from: "${rootDir}/shared/config.gradle"
/* Use a sort of poor man's autoconf to find the protobuf development
files; on Debian, those are supplied by libprotobuf-dev.
This should get skipped on Windows.
TODO: Add Windows support for the simulation code */
def protobuf_version = ""
try {
protobuf_version = "pkg-config --modversion protobuf".execute().text.trim()
println "Protobuf version is [${protobuf_version}]"
} catch(Exception ex) {
}
ext.skip_gz_msgs = false
if (project.hasProperty("forceGazebo")) {
if (!protobuf_version?.trim()) {
println "Protobuf is not available. (pkg-config --modversion protobuf failed)"
println "forceGazebo set. Forcing build - failure likely."
}
} else {
ext.skip_gz_msgs = true
println "Skipping gz msgs."
}
tasks.whenTaskAdded { task ->
task.onlyIf { !project.hasProperty('skip_gz_msgs') }
}
if (!ext.skip_gz_msgs) {
dependencies {
implementation "com.google.protobuf:protobuf-java:${protobuf_version}"
implementation "com.google.protobuf:protoc:${protobuf_version}"
}
}
/* There is a nice gradle plugin for protobuf, and the protoc tool
is included; using it simplifies our build process.
The trick is that we have to use the same version as the system
copy of libprotobuf-dev */
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protobuf_version}"
}
generatedFilesBaseDir = "$buildDir/generated"
generateProtoTasks {
all().each { task ->
task.builtins {
cpp {
outputSubDir = 'simulation/gz_msgs'
}
}
}
}
}
model {
components {
gz_msgs(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir "$buildDir/generated/main/simulation/gz_msgs"
builtBy tasks.generateProto
}
exportedHeaders {
srcDir "src/include"
srcDir "$buildDir/generated/main"
}
}
}
/* We must compile with -fPIC to link the static library into an so */
binaries {
all {
cppCompiler.args "-fPIC"
// Disable -Wzero-length-array on Clang
if (it.targetPlatform.operatingSystem.isMacOsX()) {
it.cppCompiler.args.add('-Wno-error=zero-length-array')
}
}
}
}
}
}