Files
allwpilib/build.gradle
2015-10-31 14:28:54 -04:00

166 lines
5.0 KiB
Groovy

import org.gradle.internal.os.OperatingSystem
apply plugin: 'cpp'
apply plugin: 'visual-studio'
// Find the target platform. The main wpilib build will set the target platform as a project property. You can also manually build for
// arm by using ./gradlew build -PbuildPlatform=arm
allprojects {
if (!project.hasProperty('armBuild')) {
ext.buildPlatform = OperatingSystem.current().getFamilyName()
} else {
ext.buildPlatform = 'arm'
}
}
ext.getPlatformPath = { binary ->
if (binary.targetPlatform.architecture.arm) {
return 'Linux/arm'
} else if (binary.targetPlatform.operatingSystem.linux) {
if (binary.targetPlatform.architecture.amd64) {
return 'Linux/amd64'
} else {
return 'Linux/' + binary.targetPlatform.architecture.name
}
} else if (binary.targetPlatform.operatingSystem.windows) {
if (binary.targetPlatform.architecture.amd64) {
return 'Windows/amd64'
} else {
return 'Windows/' + binary.targetPlatform.architecture.name
}
} else {
return binary.targetPlatform.operatingSystem.name + '/' + binary.targetPlatform.architecture.name
}
}
// Apply the correct toolchain settings for the target platform
if (buildPlatform == 'arm') {
apply from: 'toolchains/arm.gradle'
} else if (OperatingSystem.current().isLinux()) {
apply from: 'toolchains/linux.gradle'
} else if (OperatingSystem.current().isMacOsX()) {
apply from: 'toolchains/mac.gradle'
} else if (OperatingSystem.current().isWindows()) {
apply from: 'toolchains/windows.gradle'
} else {
throw new GradleException("ntcore does not support building on ${OperatingSystem.current().getFamilyName()}.")
}
// We only build and run the tests when building for the native platform. If we just build arm, there's not much point.
if (buildPlatform != 'arm') {
apply from: 'test/tests.gradle'
}
if (!hasProperty('skipJava')) {
apply from: 'java/java.gradle'
}
model {
platforms {
if (project.buildPlatform == 'arm') {
arm {
architecture 'arm'
operatingSystem 'linux'
}
} else {
x86 {
architecture 'x86'
operatingSystem project.buildPlatform
}
x64 {
architecture 'x86_64'
operatingSystem project.buildPlatform
}
}
}
components {
ntcore(NativeLibrarySpec) {
if (project.buildPlatform == 'arm') {
targetPlatform 'arm'
binaries.all {
if (project.hasProperty('debug')) {
setupDebugDefines(cppCompiler, linker)
} else {
setupReleaseDefines(cppCompiler, linker)
}
}
} else {
targetPlatform 'x86'
targetPlatform 'x64'
binaries.all {
if (project.hasProperty('debug')) {
setupDebugDefines(cppCompiler, linker)
} else {
setupReleaseDefines(cppCompiler, linker)
}
}
}
if (!project.hasProperty('skipJava')) {
setupJniIncludes(binaries)
}
sources {
cpp {
source {
srcDirs = ['src']
if (!project.hasProperty('skipJava')) {
srcDirs "java/lib"
}
includes = ['**/*.cpp']
}
exportedHeaders {
srcDirs = ['include']
if (!project.hasProperty('skipJava')) {
jniHeadersNetworkTables.outputs.files.each { file ->
srcDirs file.getPath()
}
}
includes = ['**/*.h']
}
}
}
}
}
}
task ntcoreZip(type: Zip) {
description = 'Creates platform-specific zip of the desktop ntcore libraries.'
group = 'WPILib'
destinationDir = project.buildDir
baseName = 'ntcore'
from(file('include')) {
into 'include'
}
binaries.withType(StaticLibraryBinarySpec) { binary ->
from(binary.staticLibraryFile) {
into getPlatformPath(binary)
}
}
binaries.withType(SharedLibraryBinarySpec) { binary ->
from(binary.sharedLibraryFile) {
into getPlatformPath(binary)
}
}
}
releaseSetup(ntcoreZip)
if (!hasProperty('skipJava')) {
jar.dependsOn ntcoreZip
}
tasks.whenTaskAdded { task ->
def name = task.name.toLowerCase()
if (name.contains("ntcoresharedlibrary") || name.contains("ntcorestaticlibrary") ||
name.contains("ntcoretest")) {
ntcoreZip.dependsOn task
}
}
apply from: 'publish.gradle'