import edu.wpi.first.nativeutils.NativeUtils import org.gradle.api.file.FileCollection import org.gradle.internal.os.OperatingSystem import edu.wpi.first.nativeutils.tasks.JNIHeaders buildscript { repositories { mavenLocal() maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath 'gradle.plugin.edu.wpi.first:native-utils:1.2.12' classpath 'gradle.plugin.edu.wpi.first.wpilib.versioning:wpilib-version-plugin:2.0' } } repositories { mavenCentral() } ext.getClassifier = { binary-> return NativeUtils.getClassifier(binary) } ext.getPlatformPath = { binary-> return NativeUtils.getPlatformPath(binary) } ext.getJNIHeadersClass = { return JNIHeaders } apply plugin: 'cpp' apply plugin: 'google-test' apply plugin: 'visual-studio' apply plugin: 'edu.wpi.first.NativeUtils' apply plugin: 'java' apply from: 'config.gradle' if (project.hasProperty('onlyAthena')) { test.enabled = false } sourceSets { dev } task nativeTestFilesJar(type: Jar) { destinationDir = project.buildDir classifier = "nativeTestFiles" project.model { binaries { withType(SharedLibraryBinarySpec) { binary -> if (binary.component.name == 'cscoreJNI') { from(binary.sharedLibraryFile) { into NativeUtils.getPlatformPath(binary) } dependsOn binary.buildTask } } } } } task run(type: JavaExec) { classpath = sourceSets.dev.runtimeClasspath main = 'edu.wpi.cscore.DevMain' } test.dependsOn nativeTestFilesJar run.dependsOn nativeTestFilesJar build.dependsOn devClasses dependencies { compile 'edu.wpi.first.wpiutil:wpiutil-java:3.+' compile 'org.opencv:opencv-java:3.2.0' testCompile 'junit:junit:4.12' testRuntime files(project(':').nativeTestFilesJar.archivePath) testRuntime 'org.opencv:opencv-jni:3.2.0:all' devCompile 'edu.wpi.first.wpiutil:wpiutil-java:3.+' devCompile 'org.opencv:opencv-java:3.2.0' devCompile sourceSets.main.output devRuntime files(project(':').nativeTestFilesJar.archivePath) devRuntime 'org.opencv:opencv-jni:3.2.0:all' } model { jniConfigs { cscore(JNIConfig) { jniDefinitionClasses = [ "edu.wpi.cscore.CameraServerJNI" ] jniArmHeaderLocations = [ all: file("${rootDir}/src/arm-linux-jni") ] sourceSets = [ project.sourceSets.main ] } cscoreJNI(JNIConfig) { jniDefinitionClasses = [ "edu.wpi.cscore.CameraServerJNI" ] jniArmHeaderLocations = [ all: file("${rootDir}/src/arm-linux-jni") ] sourceSets = [ project.sourceSets.main ] } } exportsConfigs { cscore(ExportsConfig) { x86ExcludeSymbols = [ '_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure', '_CT??_R0?AVbad_cast', '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure', '_TI5?AVfailure' ] x64ExcludeSymbols = [ '_CT??_R0?AV_System_error', '_CT??_R0?AVexception', '_CT??_R0?AVfailure', '_CT??_R0?AVbad_cast', '_CT??_R0?AVruntime_error', '_CT??_R0?AVsystem_error', '_CTA5?AVfailure', '_TI5?AVfailure' ] } cscoreJNI(ExportsConfig) { x86SymbolFilter = { symbols-> def retList = [] symbols.each { symbol-> if (symbol.startsWith('NT_') || symbol.startsWith('Java_') || symbol.startsWith('JNI_')) { retList << symbol } } return retList } x64SymbolFilter = { symbols-> def retList = [] symbols.each { symbol-> if (symbol.startsWith('NT_') || symbol.startsWith('Java_') || symbol.startsWith('JNI_')) { retList << symbol } } return retList } } } dependencyConfigs { wpiutil(DependencyConfig) { groupId = 'edu.wpi.first.wpiutil' artifactId = 'wpiutil-cpp' headerClassifier = 'headers' ext = 'zip' version = '3.+' sharedConfigs = [ cscore: [], cscoreDev: [], cscoreTestingBaseTest: [] ] staticConfigs = [ cscoreJNI: [] ] } opencv(DependencyConfig) { groupId = 'org.opencv' artifactId = 'opencv-cpp' headerClassifier = 'headers' ext = 'zip' version = '3.2.0' sharedConfigs = [ cscore: [], cscoreDev: [], cscoreTestingBaseTest: [] ] staticConfigs = [ cscoreJNI: [] ] } } components { cscore(NativeLibrarySpec) { sources { cpp { source { srcDirs 'src/main/native/cpp' include '**/*.cpp' } exportedHeaders { srcDirs 'src/main/native/include' } } } } cscoreJNI(NativeLibrarySpec) { baseName = 'cscore' sources { cpp { source { srcDirs 'src/main/native/cpp' include '**/*.cpp' } exportedHeaders { srcDirs 'src/main/native/include' } } } } if (!project.hasProperty('skipTestExe')) { cscoreDev(NativeExecutableSpec) { sources { cpp { lib library: "cscore" source { srcDirs 'src/dev/native/cpp' include '**/*.cpp' } exportedHeaders { srcDirs 'src/dev/native/include' } } } } } cscoreTestingBase(NativeLibrarySpec) { } } testSuites { cscoreTestingBaseTest { sources { cpp.source.srcDir 'src/test/native/cpp' cpp.exportedHeaders { srcDirs 'src/test/native/include', 'src/main/native/cpp' } } } } binaries { withType(StaticLibraryBinarySpec) { if (it.component.name == 'cscoreJNI') { it.buildable = false } } withType(GoogleTestTestSuiteBinarySpec) { if (it.component.testedComponent.name.contains('TestingBase') && !project.hasProperty('onlyAthena')) { lib project: ':gmock', library: 'gmock', linkage: 'static' lib library: 'cscore', linkage: 'shared' } else { it.buildable = false } } } tasks { def c = $.components project.tasks.create('runCpp', Exec) { def found = false c.each { if (it in NativeExecutableSpec && it.name == 'cscoreDev') { it.binaries.each { if (!found) { def arch = it.targetPlatform.architecture.name if (arch == 'x86-64' || arch == 'x86') { dependsOn it.tasks.install commandLine it.tasks.install.runScript found = true } } } } } } } } apply from: 'publish.gradle' task wrapper(type: Wrapper) { gradleVersion = '4.1' }