Skip to content

Commit

Permalink
Copy lots of JNI stuff from allwpilib
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Dec 23, 2023
1 parent 0356eee commit 4a7de52
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 7 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id "com.diffplug.spotless" version "6.22.0"
id "edu.wpi.first.NativeUtils" version "2024.6.1" apply false
id 'edu.wpi.first.GradleJni' version '1.1.0'
id "edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin" version "2020.2"
id "edu.wpi.first.GradleRIO" version "2024.1.1-beta-4"
id 'edu.wpi.first.WpilibTools' version '1.3.0'
Expand Down Expand Up @@ -90,3 +91,8 @@ spotless {
wrapper {
gradleVersion '8.4'
}

import edu.wpi.first.toolchain.NativePlatforms
ext.getCurrentArch = {
return NativePlatforms.desktop
}
26 changes: 26 additions & 0 deletions photon-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
plugins {
id 'edu.wpi.first.WpilibTools' version '1.3.0'
}

import java.nio.file.Path

apply from: "${rootDir}/shared/common.gradle"

ext {
nativeName = "photoncore"

main_native_libs = [
"opencv_shared"
]

test_native_libs = [
"opencv_static"
]

dev_native_libs = [
"opencv_static",
]
}

def sharedCvConfigs = [photoncore: []]
def staticCvConfigs = [:]


dependencies {
// JOGL stuff (currently we only distribute for aarch64, which is Pi 4)
implementation "org.jogamp.gluegen:gluegen-rt:$joglVersion"
Expand All @@ -22,3 +46,5 @@ task writeCurrentVersion {
}

build.dependsOn writeCurrentVersion

apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
16 changes: 16 additions & 0 deletions photon-core/src/dev/native/cpp/devmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "test.h"

#include <opencv2/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgcodecs.hpp>

#include <stdio.h>

int main() {

cv::Mat mat = cv::imread("/home/matt/Documents/GitHub/photonvision/test-resources/testimages/2022/WPI/FarLaunchpad13ft10in.png");

printf("DevMain! mat size %i %i\n", mat.rows, mat.cols);

return 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static boolean isSupported() {
*
* @param width Camera video mode width in pixels
* @param height Camera video mode height in pixels
* @param fps Camera video mode FPS
* @param rotation Asdf
* @return success of creating a camera object
*/
public static native boolean createCamera(int width, int height, int rotation);
Expand Down
8 changes: 8 additions & 0 deletions photon-core/src/main/native/cpp/jni/TestJni.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <jni.h>

extern "C" {
JNIEXPORT jint JNICALL
some_native_function() {
return 0;
}
}
16 changes: 16 additions & 0 deletions photon-core/src/main/native/cpp/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "test.h"

#include <opencv2/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgcodecs.hpp>

#include <stdio.h>

int some_test() {

cv::Mat mat = cv::imread("/home/matt/Documents/GitHub/photonvision/test-resources/testimages/2022/WPI/FarLaunchpad13ft10in.png");

printf("mat size %i %i\n", mat.rows, mat.cols);

return 1;
}
2 changes: 2 additions & 0 deletions photon-core/src/main/native/include/test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
int some_test();
7 changes: 7 additions & 0 deletions photon-core/src/test/native/cpp/devmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "test.h"
#include <stdio.h>

int main(int argc, char** argv) {
printf("hello!\n");
return some_test();
}
15 changes: 15 additions & 0 deletions photon-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ ext {
includePhotonTargeting = true
// Include the generated Version file
generatedHeaders = "src/generate/native/include"

test_native_libs = [
"cscore_shared",
"cameraserver_shared",
"wpilib_executable_shared",
"googletest_static",
"apriltag_shared",
"opencv_shared",
]

main_native_libs = [
"wpilib_shared", "apriltag_shared", "opencv_shared"
]

dev_native_libs = []
}

apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
Expand Down
15 changes: 15 additions & 0 deletions photon-targeting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ plugins {

ext {
nativeName = "photontargeting"

main_native_libs = [
"wpilib_shared", "apriltag_shared", "opencv_shared"
]

test_native_libs = [
"cscore_shared",
"cameraserver_shared",
"wpilib_executable_shared",
"googletest_static",
"apriltag_shared",
"opencv_shared",
]

dev_native_libs = []
}

apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
90 changes: 84 additions & 6 deletions shared/javacpp/setupBuild.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'cpp'
apply plugin: 'google-test-test-suite'
apply plugin: 'edu.wpi.first.NativeUtils'
apply plugin: 'edu.wpi.first.GradleJni'

apply from: "${rootDir}/shared/config.gradle"
apply from: "${rootDir}/shared/javacommon.gradle"
Expand Down Expand Up @@ -60,6 +61,86 @@ model {
nativeUtils.useRequiredLibrary(it, "wpilib_shared")
nativeUtils.useRequiredLibrary(it, "apriltag_shared")
nativeUtils.useRequiredLibrary(it, "opencv_shared")
main_native_libs.each { name ->
nativeUtils.useRequiredLibrary(it, name)
}
}
// By default, a development executable will be generated. This is to help the case of
// testing specific functionality of the library.
"${nativeName}Dev"(NativeExecutableSpec) {
targetBuildTypes 'debug'
sources {
cpp {
source {
srcDirs 'src/dev/native/cpp'
include '**/*.cpp'
}
exportedHeaders {
srcDir 'src/main/native/include'
if (project.hasProperty('generatedHeaders')) {
srcDir generatedHeaders
}
}
}
}
binaries.all {
lib library: nativeName, linkage: 'shared'
it.tasks.withType(CppCompile) {
// it.dependsOn generateProto
}
if (project.hasProperty('exeSplitSetup')) {
exeSplitSetup(it)
}
}
dev_native_libs.each { name ->
nativeUtils.useRequiredLibrary(it, name)
}
}
"${nativeName}JNI"(JniNativeLibrarySpec) {
baseName = nativeName + 'jni'

enableCheckTask !project.hasProperty('skipJniCheck')
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/cpp'
if (project.hasProperty('generatedSources')) {
srcDir generatedSources
}
include '**/jni/**/*.cpp'
}
exportedHeaders {
srcDir 'src/main/native/include'
if (project.hasProperty('generatedHeaders')) {
srcDir generatedHeaders
}
include '**/*.h'
}
}
}

binaries.all {
if (it instanceof StaticLibraryBinarySpec) {
it.buildable = false
return
}
lib library: "${nativeName}", linkage: 'shared'
if (!project.hasProperty('noWpiutil')) {
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
}
if (project.hasProperty('jniSplitSetup')) {
jniSplitSetup(it)
}
}

if(project.hasProperty("jni_native_libs")) jni_native_libs.each { name ->
nativeUtils.useRequiredLibrary(it, name)
}
}
}
testSuites {
Expand Down Expand Up @@ -88,12 +169,9 @@ model {
}
}

nativeUtils.useRequiredLibrary(it, "cscore_shared")
nativeUtils.useRequiredLibrary(it, "cameraserver_shared")
nativeUtils.useRequiredLibrary(it, "wpilib_executable_shared")
nativeUtils.useRequiredLibrary(it, "googletest_static")
nativeUtils.useRequiredLibrary(it, "apriltag_shared")
nativeUtils.useRequiredLibrary(it, "opencv_shared")
test_native_libs.each { name ->
nativeUtils.useRequiredLibrary(it, name)
}
}
}
}
Expand Down

0 comments on commit 4a7de52

Please sign in to comment.