Merge pull request #27 from 333fred/master

Gradle Update
This commit is contained in:
Peter Johnson
2015-10-31 10:46:43 -07:00
14 changed files with 650 additions and 365 deletions

View File

@@ -1,284 +1,164 @@
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.os.OperatingSystem
if (!project.hasProperty('skipJava')) {
apply plugin: 'java'
apply plugin: 'maven-publish'
}
apply plugin: 'cpp'
apply plugin: 'visual-studio'
def generatedJNIHeaderLoc = 'build/include'
// 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'
}
}
def platformSpecificIncludeFlag(loc, cppCompiler) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
cppCompiler.args "/I$loc"
} else {
cppCompiler.args '-I', loc
}
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 {
toolChains {
gcc(Gcc) {
target("arm"){
// We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
// If this ever changes, the prefix will need to be changed here
def compilerPrefix = 'arm-frc-linux-gnueabi-'
cppCompiler.executable = compilerPrefix + cppCompiler.executable
linker.executable = compilerPrefix + linker.executable
assembler.executable = compilerPrefix + assembler.executable
// Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
// arm, and doesn't understand this flag, so it is removed from both
cppCompiler.withArguments { args ->
args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-O0' << '-g3' << '-rdynamic'
//TODO: When the compiler allows us to actually call deprecated functions from within
// deprecated function, remove this line (this will cause calling deprecated functions
// to be treated as a warning rather than an error).
args << '-Wno-error=deprecated-declarations'
args.remove('-m32')
platforms {
if (project.buildPlatform == 'arm') {
arm {
architecture 'arm'
operatingSystem 'linux'
}
} else {
x86 {
architecture 'x86'
operatingSystem project.buildPlatform
}
x64 {
architecture 'x86_64'
operatingSystem project.buildPlatform
}
}
linker.withArguments { args ->
args << '-rdynamic'
args.remove('-m32')
}
staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable
}
target('x86') {
cppCompiler.withArguments { args ->
args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-O0' << '-g3' << '-rdynamic'
//TODO: When the compiler allows us to actually call deprecated functions from within
// deprecated function, remove this line (this will cause calling deprecated functions
// to be treated as a warning rather than an error).
args << '-Wno-error=deprecated-declarations'
args << '-m32'
}
linker.withArguments { args ->
args << '-rdynamic'
args << '-m32'
}
}
target('x64') {
cppCompiler.withArguments { args ->
args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-O0' << '-g3' << '-rdynamic'
//TODO: When the compiler allows us to actually call deprecated functions from within
// deprecated function, remove this line (this will cause calling deprecated functions
// to be treated as a warning rather than an error).
args << '-Wno-error=deprecated-declarations'
}
linker.withArguments { args ->
args << '-rdynamic'
}
}
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
visualCpp(VisualCpp) {
def vs14Dir = file('C:\\Program Files (x86)\\Microsoft Visual Studio 14.0')
// If vs2015 is installed, fall back to vs2013 for now, until Gradle pulls in the right
// includes for the win10 sdk.
if (vs14Dir.exists()) {
def vs12Dir = file('C:\\Program Files (x86)\\Microsoft Visual Studio 12.0')
if (!vs12Dir.exists()) {
throw new GradleException('Compilation with VS 2015 is not currently supported by Gradle. Please install VS 2013, or use the CMake build option.')
}
installDir = vs12Dir
}
eachPlatform {
cppCompiler.withArguments { args ->
args << '/EHsc' << '/DNOMINMAX' << '/D_SCL_SECURE_NO_WARNINGS' << '/D_WINSOCK_DEPRECATED_NO_WARNINGS'
}
linker.withArguments { args ->
args << '/DEF:ntcore.def'
}
}
}
}
}
platforms {
arm {
architecture "arm"
operatingSystem 'linux'
}
x86 {
architecture "x86"
}
x64 {
architecture "x86_64"
}
}
components {
ntcore(NativeLibrarySpec) {
targetPlatform 'arm'
targetPlatform 'x86'
targetPlatform 'x64'
binaries.all {
tasks.withType(CppCompile) {
if (!project.hasProperty('skipJava')) {
if (targetPlatform == platforms.arm) {
// ARM JDK is included for jni.h. We also need the arm-linux specific headers.
// This does not need to change when compiling on Windows
// The JNI headers are put into the build/include directory by the jniHeaders task
sources {
arm(CppSourceSet) {
source {
includes "java/arm-linux"
includes "java/arm-linux/linux"
}
components {
ntcore(NativeLibrarySpec) {
if (project.buildPlatform == 'arm') {
targetPlatform 'arm'
binaries.all {
if (project.hasProperty('debug')) {
setupDebugDefines(cppCompiler, linker)
} else {
setupReleaseDefines(cppCompiler, linker)
}
}
}
} else {
def jdkLocation = org.gradle.internal.jvm.Jvm.current().javaHome
platformSpecificIncludeFlag("${jdkLocation}/include", cppCompiler)
if (targetPlatform.operatingSystem.macOsX) {
platformSpecificIncludeFlag("${jdkLocation}/include/darwin", cppCompiler)
} else if (targetPlatform.operatingSystem.linux) {
platformSpecificIncludeFlag("${jdkLocation}/include/linux", cppCompiler)
} else if (targetPlatform.operatingSystem.windows) {
platformSpecificIncludeFlag("${jdkLocation}/include/win32", cppCompiler)
} else if (targetPlatform.operatingSystem.freeBSD) {
platformSpecificIncludeFlag("${jdkLocation}/include/freebsd", cppCompiler)
}
targetPlatform 'x86'
targetPlatform 'x64'
binaries.all {
if (project.hasProperty('debug')) {
setupDebugDefines(cppCompiler, linker)
} else {
setupReleaseDefines(cppCompiler, linker)
}
}
}
jniHeadersNetworkTables.outputs.files.each { file ->
if (targetPlatform == platforms.arm) {
cppCompiler.args '-I', file.getPath()
} else {
platformSpecificIncludeFlag(file.getPath(), cppCompiler)
}
}
dependsOn jniHeadersNetworkTables
}
}
}
sources {
cpp {
source {
srcDirs = ["src"]
if (!project.hasProperty('skipJava')) {
srcDirs "java/lib"
setupJniIncludes(binaries)
}
includes = ["**/*.cpp"]
}
exportedHeaders {
srcDirs = ["include"]
if (!project.hasProperty('skipJava')) {
jniHeadersNetworkTables.outputs.files.each { file ->
srcDirs file.getPath()
}
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']
}
}
}
includes = ["**/*.h"]
}
}
}
}
}
}
if (!project.hasProperty('skipJava')) {
publishing {
publications {
java(MavenPublication) {
artifact jar
artifact (networktablesJavaSource) {
classifier = 'sources'
}
artifact(networktablesJavadoc) {
classifier = 'javadoc'
}
groupId 'edu.wpi.first.wpilib.networktables.java'
artifactId 'NetworkTables'
version '3.0.0-SNAPSHOT'
}
}
}
compileJava {
options.compilerArgs << "-Xlint:unchecked"
}
sourceSets {
main {
java {
srcDirs = ["java/src"]
}
}
}
jar {
description = 'Generates NetworkTables jar, with the JNI shared libraries embedded'
dependsOn { armNtcoreSharedLibrary }
dependsOn { x64NtcoreSharedLibrary }
dependsOn { x86NtcoreSharedLibrary }
dependsOn { classes }
binaries.withType(SharedLibraryBinary) { binary ->
from(file(binary.sharedLibraryFile)) {
if (binary.targetPlatform == platforms.arm) {
into "Linux/arm"
} else if (binary.targetPlatform.operatingSystem.name == "Linux") {
if (binary.targetPlatform.architecture.name == "x86-64") {
into "Linux/amd64"
} else {
into "Linux/" + binary.targetPlatform.architecture.name
}
} else if (binary.targetPlatform.operatingSystem.name.startsWith("Windows")) {
if (binary.targetPlatform.architecture.name == "x86-64") {
into "Windows/amd64"
} else {
into "Windows/" + binary.targetPlatform.architecture.name
}
} else {
into binary.targetPlatform.operatingSystem.name + "/" + binary.targetPlatform.architecture.name
}
}
}
}
task networktablesJavaSource(type: Jar, dependsOn: classes) {
description = 'Generates the source jar for NetworkTables java'
task ntcoreZip(type: Zip) {
description = 'Creates platform-specific zip of the desktop ntcore libraries.'
group = 'WPILib'
classifier = 'classes'
from sourceSets.main.allJava
}
destinationDir = project.buildDir
task networktablesJavadoc(type: Jar, dependsOn: javadoc) {
description = 'Generates the javadoc jar for NetworkTables java'
group = 'WPILib'
classifier = 'javadoc'
from javadoc.destinationDir
}
/**
* Generates the JNI headers
*/
task jniHeadersNetworkTables {
description = 'Generates JNI headers from edu.wpi.first.wpilibj.networktables.*'
group = 'WPILib'
def outputFolder = file(generatedJNIHeaderLoc)
inputs.files sourceSets.main.output
outputs.file outputFolder
doLast {
outputFolder.mkdirs()
exec {
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-d', outputFolder
args '-classpath', sourceSets.main.output.classesDir
args 'edu.wpi.first.wpilibj.networktables.NetworkTablesJNI'
}
from(file('include')) {
into 'include'
}
}
clean {
delete generatedJNIHeaderLoc
}
binaries.withType(StaticLibraryBinarySpec) { binary ->
from(binary.staticLibraryFile) {
into getPlatformPath(binary)
}
}
} // skipJava
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'

View File

@@ -1,45 +1,55 @@
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.os.OperatingSystem
apply plugin: 'cpp'
apply plugin: 'visual-studio'
model {
toolChains {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
visualCpp(VisualCpp) {
def vs14Dir = file('C:\\Program Files (x86)\\Microsoft Visual Studio 14.0')
// If vs2015 is installed, fall back to vs2013 for now, until Gradle pulls in the right
// includes for the win10 sdk.
if (vs14Dir.exists()) {
def vs12Dir = file('C:\\Program Files (x86)\\Microsoft Visual Studio 12.0')
if (!vs12Dir.exists()) {
throw new GradleException('Compilation with VS 2015 is not currently supported by Gradle. Please install VS 2013, or use the CMake build option.')
}
installDir = vs12Dir
}
}
}
}
components {
gmock(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs = ['src', 'gtest/src']
includes = ['*-all.cc']
}
exportedHeaders {
srcDirs = ['include', 'gtest/include', '.', 'gtest']
includes = ['**/*.h', '**/*.cc']
}
}
}
binaries.all {
if (toolChain in VisualCpp) {
cppCompiler.args '-D_UNICODE', '-DUNICODE', '-DWIN32', '-D_WIN32', '-DSTRICT', '-DWIN32_LEAN_AND_MEAN', '-D_HAS_EXCEPTIONS=1'
} else {
cppCompiler.args '-Wall', '-Wshadow', '-fexceptions', '-Wextra', '-Wno-unused-parameter', '-Wno-missing-field-initializers', '-lpthreads', '-fPIC'
}
}
}
}
// 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()}.")
}
model {
platforms {
x86 {
architecture 'x86'
operatingSystem OperatingSystem.current().getFamilyName()
}
x64 {
architecture 'x86_64'
operatingSystem OperatingSystem.current().getFamilyName()
}
}
components {
gmock(NativeLibrarySpec) {
targetPlatform 'x86'
targetPlatform 'x64'
sources {
cpp {
source {
srcDirs = ['src', 'gtest/src']
includes = ['*-all.cc']
}
exportedHeaders {
srcDirs = ['include', 'gtest/include', '.', 'gtest']
includes = ['**/*.h', '**/*.cc']
}
}
}
binaries.all {
if (toolChain in VisualCpp) {
cppCompiler.args '-D_UNICODE', '-DUNICODE', '-DWIN32', '-D_WIN32', '-DSTRICT', '-DWIN32_LEAN_AND_MEAN', '-D_HAS_EXCEPTIONS=1'
} else {
cppCompiler.args '-Wall', '-Wshadow', '-fexceptions', '-Wextra', '-Wno-unused-parameter', '-Wno-missing-field-initializers', '-lpthreads', '-fPIC'
}
}
}
}
}

Binary file not shown.

View File

@@ -1,6 +1,6 @@
#Sat Sep 19 10:44:07 EDT 2015
#Sat Oct 31 11:10:48 EDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-bin.zip

6
gradlew vendored
View File

@@ -42,11 +42,6 @@ case "`uname`" in
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
@@ -114,6 +109,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`

120
java/java.gradle Normal file
View File

@@ -0,0 +1,120 @@
import org.gradle.internal.os.OperatingSystem
apply plugin: 'java'
def generatedJNIHeaderLoc = 'build/include'
sourceSets {
main {
java {
srcDirs = ['java/src']
}
}
}
jar {
description = 'Generates NetworkTables jar, with the JNI shared libraries embedded'
if (buildPlatform == 'arm') {
dependsOn { ntcoreSharedLibrary }
} else {
dependsOn { x64NtcoreSharedLibrary }
dependsOn { x86NtcoreSharedLibrary }
}
dependsOn { classes }
binaries.withType(SharedLibraryBinary) { binary ->
from(file(binary.sharedLibraryFile)) {
into getPlatformPath(binary)
}
}
}
task networktablesJavaSource(type: Jar, dependsOn: classes) {
description = 'Generates the source jar for NetworkTables java'
group = 'WPILib'
classifier = 'source'
from sourceSets.main.allJava
}
task networktablesJavadoc(type: Jar, dependsOn: javadoc) {
description = 'Generates the javadoc jar for NetworkTables java'
group = 'WPILib'
classifier = 'javadoc'
from javadoc.destinationDir
}
/**
* Generates the JNI headers
*/
task jniHeadersNetworkTables {
description = 'Generates JNI headers from edu.wpi.first.wpilibj.networktables.*'
group = 'WPILib'
def outputFolder = file(generatedJNIHeaderLoc)
inputs.files sourceSets.main.output
outputs.file outputFolder
doLast {
outputFolder.mkdirs()
exec {
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-d', outputFolder
args '-classpath', sourceSets.main.output.classesDir
args 'edu.wpi.first.wpilibj.networktables.NetworkTablesJNI'
}
}
}
clean {
delete generatedJNIHeaderLoc
}
compileJava {
options.compilerArgs << '-Xlint:unchecked'
}
javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
}
// This creates a lambda that the main build.gradle can access, which sets up the JNI includes for the
// target build platform. This lambda is exposed as a property in the main build.gradle.
ext.setupJniIncludes = { binaries ->
def platformSpecificIncludeFlag = { loc, cppCompiler ->
if (OperatingSystem.current().isWindows()) {
cppCompiler.args "/I$loc"
} else {
cppCompiler.args '-I', loc
}
}
binaries.all {
tasks.withType(CppCompile) {
if (buildPlatform == 'arm') {
cppCompiler.args '-I', file('java/arm-linux').absolutePath
cppCompiler.args '-I', file('java/arm-linux/linux').absolutePath
} else {
def jdkLocation = org.gradle.internal.jvm.Jvm.current().javaHome
platformSpecificIncludeFlag("${jdkLocation}/include", cppCompiler)
if (targetPlatform.operatingSystem.macOsX) {
platformSpecificIncludeFlag("${jdkLocation}/include/darwin", cppCompiler)
} else if (targetPlatform.operatingSystem.linux) {
platformSpecificIncludeFlag("${jdkLocation}/include/linux", cppCompiler)
} else if (targetPlatform.operatingSystem.windows) {
platformSpecificIncludeFlag("${jdkLocation}/include/win32", cppCompiler)
} else if (targetPlatform.operatingSystem.freeBSD) {
platformSpecificIncludeFlag("${jdkLocation}/include/freebsd", cppCompiler)
}
}
jniHeadersNetworkTables.outputs.files.each { file ->
if (buildPlatform == 'arm') {
cppCompiler.args '-I', file.getPath()
} else {
platformSpecificIncludeFlag(file.getPath(), cppCompiler)
}
}
dependsOn jniHeadersNetworkTables
}
}
}

50
publish.gradle Normal file
View File

@@ -0,0 +1,50 @@
import org.gradle.internal.os.OperatingSystem
apply plugin: 'maven-publish'
publishing {
publications {
if (!project.hasProperty('skipJava')) {
java(MavenPublication) {
artifact jar {
// If we're building the regular ntcore for arm, it has no classifier. Otherwise, classify
// the platform this jar is built for.
classifier = buildPlatform
}
artifact (networktablesJavaSource) {
classifier = 'sources'
}
artifact(networktablesJavadoc) {
classifier = 'javadoc'
}
groupId 'edu.wpi.first.wpilib.networktables.java'
artifactId 'NetworkTables'
version '3.0.0-SNAPSHOT'
}
}
cpp(MavenPublication) {
artifact ntcoreZip {
classifier = buildPlatform
}
groupId 'edu.wpi.first.wpilib.networktables.cpp'
artifactId 'NetworkTables'
version '3.0.0-SNAPSHOT'
}
}
// If we want to publish to a specific repository on Jenkins, we specify it on the command line. The valid
// repository names are:
// release
// stable
// beta
// development
if (project.hasProperty('repo')) {
repositories {
maven {
url "${System.getProperty('user.home')}/releases/maven/$repo"
}
}
}
}

View File

@@ -1 +1,2 @@
include 'gmock', 'test'
if (!hasProperty('armBuild'))
include 'gmock'

View File

@@ -1,59 +0,0 @@
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'cpp'
apply plugin: 'google-test'
apply plugin: 'visual-studio'
model {
toolChains {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
visualCpp(VisualCpp) {
def vs14Dir = file('C:\\Program Files (x86)\\Microsoft Visual Studio 14.0')
// If vs2015 is installed, fall back to vs2013 for now, until Gradle pulls in the right
// includes for the win10 sdk.
if (vs14Dir.exists()) {
def vs12Dir = file('C:\\Program Files (x86)\\Microsoft Visual Studio 12.0')
if (!vs12Dir.exists()) {
throw new GradleException('Compilation with VS 2015 is not currently supported by Gradle. Please install VS 2013, or use the CMake build option.')
}
installDir = vs12Dir
}
}
}
}
components {
tests(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs = ["unit", "../src"]
includes = ["**/*.cpp"]
}
exportedHeaders {
srcDirs = ["../include", "../src", "../gmock/include", "../gmock/gtest/include"]
includes = ["**/*.h"]
}
}
}
binaries.all {
lib project: ':gmock', library: "gmock", linkage: "static"
if (toolChain in Gcc) {
cppCompiler.args '-std=c++1y', '-Wformat=2', '-Wall', '-Wextra', '-Werror', '-pedantic', '-Wno-unused-parameter'
linker.args '-pthread'
}
if (toolChain in VisualCpp) {
cppCompiler.args '/EHsc', '/DNOMINMAX', '/D_SCL_SECURE_NO_WARNINGS', '/D_WINSOCK_DEPRECATED_NO_WARNINGS'
}
}
}
}
}
binaries.withType(GoogleTestTestSuiteBinarySpec) {
lib project: ':gmock', library: "gmock", linkage: "static"
if (targetPlatform.operatingSystem.linux) {
cppCompiler.args '-pthread', '-std=c++1y'
linker.args '-pthread'
} else {
cppCompiler.args '/EHsc', '/DNOMINMAX', '/D_SCL_SECURE_NO_WARNINGS', '/D_WINSOCK_DEPRECATED_NO_WARNINGS'
}
}

45
test/tests.gradle Normal file
View File

@@ -0,0 +1,45 @@
apply plugin: 'google-test'
task check() {}
model {
testSuites {
ntcoreTest {
if (!project.hasProperty('skipJava')) {
setupJniIncludes(binaries)
}
sources {
cpp {
source {
srcDirs = ['test/unit']
includes = ['**/*.cpp']
}
exportedHeaders {
srcDirs = ['include', 'src', 'gmock/include', 'gmock/gtest/include']
includes = ['**/*.h']
}
}
}
binaries.all {
if (project.hasProperty('wpilib')) {
lib project: ':ntcore:gmock', library: "gmock", linkage: "static"
} else {
lib project: ':gmock', library: "gmock", linkage: "static"
}
}
}
}
}
binaries.withType(GoogleTestTestSuiteBinarySpec) {
if (project.hasProperty('wpilib')) {
lib project: ':ntcore:gmock', library: "gmock", linkage: "static"
} else {
lib project: ':gmock', library: "gmock", linkage: "static"
}
if (targetPlatform.operatingSystem.linux) {
cppCompiler.args '-pthread', '-std=c++1y'
linker.args '-pthread'
} else {
cppCompiler.args '/EHsc', '/DNOMINMAX', '/D_SCL_SECURE_NO_WARNINGS', '/D_WINSOCK_DEPRECATED_NO_WARNINGS'
}
}

66
toolchains/arm.gradle Normal file
View File

@@ -0,0 +1,66 @@
def compilerPrefix = 'arm-frc-linux-gnueabi-'
model {
toolChains {
gcc(Gcc) {
target("arm"){
// We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
// If this ever changes, the prefix will need to be changed here
cppCompiler.executable = compilerPrefix + cppCompiler.executable
linker.executable = compilerPrefix + linker.executable
assembler.executable = compilerPrefix + assembler.executable
// Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
// arm, and doesn't understand this flag, so it is removed from both
cppCompiler.withArguments { args ->
args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic'
//TODO: When the compiler allows us to actually call deprecated functions from within
// deprecated function, remove this line (this will cause calling deprecated functions
// to be treated as a warning rather than an error).
args << '-Wno-error=deprecated-declarations'
args.remove('-m32')
}
linker.withArguments { args ->
args << '-rdynamic'
args.remove('-m32')
}
staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable
}
}
}
}
ext.setupReleaseDefines = { cppCompiler, linker ->
cppCompiler.args '-O2', '-g'
}
ext.setupDebugDefines = { cppCompiler, linker ->
cppCompiler.args '-g', '-O0'
}
ext.releaseSetup = { releaseTask ->
binaries.withType(SharedLibraryBinarySpec) { binary ->
if (!project.hasProperty('debug')) {
def library = binary.sharedLibraryFile.absolutePath
def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug"
if (project.tasks.findByName("firstObjcopy${binary.name}") == null) {
def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task ->
task.commandLine "${compilerPrefix}objcopy", '--only-keep-debug', library, debugLibrary
}
def strip = project.tasks.create("strip${binary.name}", Exec) { task ->
task.commandLine "${compilerPrefix}strip", '-g', library
}
def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task ->
task.commandLine "${compilerPrefix}objcopy", "--add-gnu-debuglink=$debugLibrary", library
}
secondObjcopy.dependsOn strip
strip.dependsOn firstObjcopy
binary.tasks.whenObjectAdded { task ->
if (task.name.contains('link')) {
firstObjcopy.dependsOn task
}
}
}
releaseTask.dependsOn project.tasks.getByName("secondObjcopy${binary.name}")
}
}
}

70
toolchains/linux.gradle Normal file
View File

@@ -0,0 +1,70 @@
model {
toolChains {
gcc(Gcc) {
target('x86') {
cppCompiler.withArguments { args ->
args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic'
//TODO: When the compiler allows us to actually call deprecated functions from within
// deprecated function, remove this line (this will cause calling deprecated functions
// to be treated as a warning rather than an error).
args << '-Wno-error=deprecated-declarations'
args << '-m32'
}
linker.withArguments { args ->
args << '-rdynamic'
args << '-m32'
}
}
target('x64') {
cppCompiler.withArguments { args ->
args << '-std=c++11' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic'
//TODO: When the compiler allows us to actually call deprecated functions from within
// deprecated function, remove this line (this will cause calling deprecated functions
// to be treated as a warning rather than an error).
args << '-Wno-error=deprecated-declarations'
}
linker.withArguments { args ->
args << '-rdynamic'
}
}
}
}
}
ext.setupReleaseDefines = { cppCompiler, linker ->
cppCompiler.args '-O2', '-g'
}
ext.setupDebugDefines = { cppCompiler, linker ->
cppCompiler.args '-g', '-O0'
}
ext.releaseSetup = { releaseTask ->
binaries.withType(SharedLibraryBinarySpec) { binary ->
if (!project.hasProperty('debug')) {
def library = binary.sharedLibraryFile.absolutePath
def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug"
if (project.tasks.findByName("firstObjcopy${binary.name}") == null) {
def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task ->
task.commandLine 'objcopy', '--only-keep-debug', library, debugLibrary
}
def strip = project.tasks.create("strip${binary.name}", Exec) { task ->
task.commandLine 'strip', '-g', library
}
def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task ->
task.commandLine 'objcopy', "--add-gnu-debuglink=$debugLibrary", library
}
secondObjcopy.dependsOn strip
strip.dependsOn firstObjcopy
binary.tasks.whenObjectAdded { task ->
if (task.name.contains('link')) {
firstObjcopy.dependsOn task
}
}
}
releaseTask.dependsOn project.tasks.getByName("secondObjcopy${binary.name}")
}
}
}

57
toolchains/mac.gradle Normal file
View File

@@ -0,0 +1,57 @@
model {
toolChains {
clang(Clang) {
target('x86') {
cppCompiler.withArguments { args ->
args << '-std=c++11' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic-errors'
args << '-Wno-unused-parameter' << '-fPIC' << '-m32'
}
linker.withArguments { args ->
args << '-m32'
}
}
target('x64') {
cppCompiler.withArguments { args ->
args << '-std=c++11' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic-errors'
args << '-Wno-unused-parameter' << '-fPIC'
}
}
}
}
}
ext.setupReleaseDefines = { cppCompiler, linker ->
cppCompiler.args '-O2'
}
ext.setupDebugDefines = { cppCompiler, linker ->
cppCompiler.args '-g', '-O0'
}
ext.releaseSetup = { releaseTask ->
binaries.withType(SharedLibraryBinarySpec) { binary ->
if (!project.hasProperty('debug')) {
def library = binary.sharedLibraryFile.absolutePath
def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug"
if (project.tasks.findByName("firstObjcopy${binary.name}") == null) {
def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task ->
task.commandLine 'objcopy', '--only-keep-debug', library, debugLibrary
}
def strip = project.tasks.create("strip${binary.name}", Exec) { task ->
task.commandLine 'strip', '-g', library
}
def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task ->
task.commandLine 'objcopy', "--add-gnu-debuglink=$debugLibrary", library
}
secondObjcopy.dependsOn strip
strip.dependsOn firstObjcopy
binary.tasks.whenObjectAdded { task ->
if (task.name.contains('link')) {
firstObjcopy.dependsOn task
}
}
}
releaseTask.dependsOn project.tasks.getByName("secondObjcopy${binary.name}")
}
}
}

49
toolchains/windows.gradle Normal file
View File

@@ -0,0 +1,49 @@
model {
toolChains {
visualCpp(VisualCpp) {
// Workaround for VS2015 adapted from https://github.com/couchbase/couchbase-lite-java-native/issues/23
def VS_2015_INCLUDE_DIR = "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"
def VS_2015_LIB_DIR = "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt"
def VS_2015_INSTALL_DIR = 'C:/Program Files (x86)/Microsoft Visual Studio 14.0'
def vsInstallDir = file(VS_2015_INSTALL_DIR)
// If you ever happen to install and uninstall any other version of VS, Gradle will misdetect the compiler
// and linker to run. This fixes that by manually setting the install dir
if (vsInstallDir.exists()) {
installDir = vsInstallDir
}
eachPlatform {
cppCompiler.withArguments { args ->
args << '/EHsc' << '/DNOMINMAX' << '/D_SCL_SECURE_NO_WARNINGS' << '/D_WINSOCK_DEPRECATED_NO_WARNINGS'
if (file(VS_2015_INCLUDE_DIR).exists()) {
args << "/I$VS_2015_INCLUDE_DIR"
}
}
linker.withArguments { args ->
if (file(VS_2015_LIB_DIR).exists()) {
if (platform.architecture.name == 'x86') {
args << "/LIBPATH:$VS_2015_LIB_DIR/x86"
} else {
args << "/LIBPATH:$VS_2015_LIB_DIR/x64"
}
}
}
}
}
}
}
ext.setupReleaseDefines = { cppCompiler, linker ->
cppCompiler.args '/O2', '/Zi', '/FS'
linker.args '/DEF:ntcore.def'
}
ext.setupDebugDefines = { cppCompiler, linker ->
cppCompiler.args '/Zi', '/FS'
linker.args '/DEBUG', '/DEF:ntcore.def'
}
// This is a noop on Windows. On gcc platforms, we strip the release binary and create a separate
// debug library, but Windows already separates debug symbols into a .pdb file.
ext.releaseSetup = {}