ext { nativeName = "photontargeting" } apply plugin: 'cpp' apply plugin: 'c' apply plugin: 'google-test-test-suite' apply plugin: 'edu.wpi.first.NativeUtils' apply plugin: 'org.photonvision.tools.WpilibTools' apply plugin: 'edu.wpi.first.GradleJni' ext.licenseFile = file("$rootDir/LICENSE") apply from: "${rootDir}/shared/config.gradle" apply from: "${rootDir}/shared/javacommon.gradle" apply from: "${rootDir}/versioningHelper.gradle" nativeUtils { exportsConfigs { "${nativeName}" {} } } sourceSets.main.java.srcDir "${projectDir}/src/generated/main/java" model { components { "${nativeName}"(NativeLibrarySpec) { sources { c { source { srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp", "$buildDir/generated/native/cpp" include '**/*.c' } } cpp { source { srcDirs 'src/main/native/cpp', "$buildDir/generated/source/proto/main/cpp", 'src/generated/main/native/cpp' include '**/*.cpp', '**/*.cc' } exportedHeaders { srcDirs 'src/main/native/include', 'src/generated/main/native/include', "$buildDir/generated/source/proto/main/cpp", 'src/generated/main/native/include' if (project.hasProperty('generatedHeaders')) { srcDir generatedHeaders } include "**/*.h" } } } binaries.all { it.tasks.withType(CppCompile) { it.dependsOn generateProto } } nativeUtils.useRequiredLibrary(it, "wpiutil_shared") nativeUtils.useRequiredLibrary(it, "wpimath_shared") nativeUtils.useRequiredLibrary(it, "wpinet_shared") nativeUtils.useRequiredLibrary(it, "ntcore_shared") nativeUtils.useRequiredLibrary(it, "apriltag_shared") nativeUtils.useRequiredLibrary(it, "opencv_shared") } "${nativeName}JNI"(JniNativeLibrarySpec) { enableCheckTask project.hasProperty('doJniCheck') javaCompileTasks << compileJava jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.roborio) jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm32) jniCrossCompileOptions << JniCrossCompileOptions(nativeUtils.wpi.platforms.linuxarm64) sources { cpp { source { srcDirs 'src/main/native/jni' include '**/*.cpp', '**/*.cc' } } } binaries.all { lib library: nativeName, linkage: 'shared' } nativeUtils.useRequiredLibrary(it, "wpiutil_shared") nativeUtils.useRequiredLibrary(it, "wpimath_shared") nativeUtils.useRequiredLibrary(it, "wpinet_shared") nativeUtils.useRequiredLibrary(it, "ntcore_shared") nativeUtils.useRequiredLibrary(it, "cscore_shared") nativeUtils.useRequiredLibrary(it, "opencv_shared") } } testSuites { "${nativeName}Test"(GoogleTestTestSuiteSpec) { for(NativeComponentSpec c : $.components) { if (c.name == nativeName) { testing c break } } sources { cpp { source { srcDirs 'src/test/native/cpp' include '**/*.cpp' } exportedHeaders { srcDirs 'src/test/native/include', "$buildDir/generated/source/proto/main/cpp" } } } binaries.all { lib library: nativeName, linkage: 'shared' lib library: "${nativeName}JNI", linkage: 'shared' it.tasks.withType(CppCompile) { it.dependsOn generateProto } } nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared") nativeUtils.useRequiredLibrary(it, "googletest_static") nativeUtils.useRequiredLibrary(it, "apriltag_shared") nativeUtils.useRequiredLibrary(it, "cscore_shared") nativeUtils.useRequiredLibrary(it, "opencv_shared") } } tasks { def c = $.testSuites project.tasks.create('runCpp', Exec) { description = "Run the photon-lib executable" def found = false def systemArch = getCurrentArch() c.each { if (it in GoogleTestTestSuiteSpec && it.name == "${nativeName}Test") { it.binaries.each { if (!found) { def arch = it.targetPlatform.name if (arch == systemArch) { dependsOn it.tasks.install commandLine it.tasks.install.runScriptFile.get().asFile.toString() def filePath = it.tasks.install.installDirectory.get().toString() + File.separatorChar + 'lib' test.dependsOn it.tasks.install test.systemProperty 'java.library.path', filePath test.environment 'LD_LIBRARY_PATH', filePath test.environment 'DYLD_LIBRARY_PATH', filePath test.workingDir filePath found = true } } } } } } } } apply from: "${rootDir}/shared/javacpp/publish.gradle" // Add photon serde headers to our published sources cppHeadersZip { from('src/generated/main/native/include') { into '/' } } // setup wpilib bundled native libs wpilibTools.deps.wpilibVersion = wpi.versions.wpilibVersion.get() def nativeConfigName = 'wpilibNatives' def nativeConfig = configurations.create(nativeConfigName) def nativeTasks = wpilibTools.createExtractionTasks { configurationName = nativeConfigName } nativeTasks.addToSourceSetResources(sourceSets.test) nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpiutil") nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpimath") nativeConfig.dependencies.add wpilibTools.deps.wpilib("wpinet") nativeConfig.dependencies.add wpilibTools.deps.wpilib("ntcore") nativeConfig.dependencies.add wpilibTools.deps.wpilib("hal") nativeConfig.dependencies.add wpilibTools.deps.wpilib("cscore") nativeConfig.dependencies.add wpilibTools.deps.wpilibOpenCv("frc" + openCVYear, wpi.versions.opencvVersion.get()) nativeConfig.dependencies.add wpilibTools.deps.wpilib("apriltag")