Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- os: windows-latest
arch-name: windowsx86-64
extra-flags: -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_COMPILER=clang-cl
- os: macos-latest
arch-name: osxuniversal
extra-flags: -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"

runs-on: ${{ matrix.os }}
name: "mrcal-jni - Build - ${{ matrix.arch-name }}"
Expand All @@ -44,12 +47,16 @@ jobs:
java-version: 17
distribution: temurin

- name: Install deps
- name: Install deps (Linux)
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt-get install -y cmake ninja-build gcc g++ liblist-moreutils-perl

- name: Install deps (macOS)
if: runner.os == 'macOS'
run: sudo cpan -i List::MoreUtils

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
Expand Down
97 changes: 55 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ file(
GLOB_RECURSE OPENCV_LIB_PATH
"${opencv_lib_SOURCE_DIR}/**/*.lib"
"${opencv_lib_SOURCE_DIR}/**/*.so*"
"${opencv_lib_SOURCE_DIR}/**/*.*.dylib"
)
set(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR})
message("Depending on opencv ${OPENCV_LIB_PATH}")
Expand All @@ -66,43 +67,49 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Silence OpenBLAS/LAPACK warnings
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
set(BLA_VENDOR OpenBLAS)
FetchContent_Declare(
BLAS
GIT_REPOSITORY https://github.com/OpenMathLib/OpenBLAS.git
GIT_TAG v0.3.30
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(BLAS)

if(TARGET openblas)
set(OPENBLAS_TARGET openblas)
message(STATUS "Using openblas target")
elseif(TARGET OpenBLAS)
set(OPENBLAS_TARGET OpenBLAS)
message(STATUS "Using OpenBLAS target")
elseif(TARGET libopenblas)
set(OPENBLAS_TARGET libopenblas)
message(STATUS "Using libopenblas target")
else()
# Fallback: find the library file manually
find_library(
OPENBLAS_LIB
NAMES openblas libopenblas
PATHS
${openblas_external_BINARY_DIR}
${openblas_external_BINARY_DIR}/lib
${openblas_external_BINARY_DIR}/lib/Release
NO_DEFAULT_PATH
REQUIRED
)
message(STATUS "Using OpenBLAS library file: ${OPENBLAS_LIB}")
add_library(openblas_imported STATIC IMPORTED)
set_target_properties(
openblas_imported
PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIB}
if(NOT APPLE)
set(BLA_VENDOR OpenBLAS)
FetchContent_Declare(
BLAS
GIT_REPOSITORY https://github.com/OpenMathLib/OpenBLAS.git
GIT_TAG v0.3.30
OVERRIDE_FIND_PACKAGE
)
set(OPENBLAS_TARGET openblas_imported)
FetchContent_MakeAvailable(BLAS)

if(TARGET openblas)
set(OPENBLAS_TARGET openblas)
message(STATUS "Using openblas target")
elseif(TARGET OpenBLAS)
set(OPENBLAS_TARGET OpenBLAS)
message(STATUS "Using OpenBLAS target")
elseif(TARGET libopenblas)
set(OPENBLAS_TARGET libopenblas)
message(STATUS "Using libopenblas target")
else()
# Fallback: find the library file manually
find_library(
OPENBLAS_LIB
NAMES openblas libopenblas
PATHS
${openblas_external_BINARY_DIR}
${openblas_external_BINARY_DIR}/lib
${openblas_external_BINARY_DIR}/lib/Release
NO_DEFAULT_PATH
REQUIRED
)
message(STATUS "Using OpenBLAS library file: ${OPENBLAS_LIB}")
add_library(openblas_imported STATIC IMPORTED)
set_target_properties(
openblas_imported
PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIB}
)
set(OPENBLAS_TARGET openblas_imported)
endif()
else()
set(BLA_VENDOR Apple)
add_compile_definitions(ACCELERATE_NEW_LAPACK=1)
find_package(BLAS)
endif()

# Configure SuiteSparse to use BLAS
Expand All @@ -128,7 +135,11 @@ get_target_property(
INTERFACE_LINK_LIBRARIES
)
message(STATUS "CHOLMOD links to: ${CHOLMOD_LIBS}")
message(STATUS "BLAS is at: ${OPENBLAS_TARGET}")
if(NOT APPLE)
message(STATUS "BLAS is at: ${OPENBLAS_TARGET}")
else()
message(STATUS "BLAS is using Apple Accelerate")
endif()

# And pull in JNI
find_package(JNI)
Expand Down Expand Up @@ -195,6 +206,11 @@ target_link_libraries(
lapack
)

# vnlog for the test script
set(VNLOG_SRC_CPP vnlog/b64_cencode.c vnlog/vnlog-parser.c vnlog/vnlog.c)
add_library(vnlog STATIC ${VNLOG_SRC_CPP})
target_include_directories(vnlog SYSTEM PUBLIC ${PROJECT_SOURCE_DIR}/vnlog)

# Test script for checking our linker
add_executable(mrcal_jni_test src/mrcal_test.cpp)
target_link_libraries(mrcal_jni_test PUBLIC mrcal_jni)
Expand All @@ -203,11 +219,8 @@ target_include_directories(
SYSTEM
PRIVATE ${PROJECT_SOURCE_DIR}/vnlog
)
# add_dependencies(mrcal_jni_test )
target_link_libraries(
mrcal_jni_test
PRIVATE ${OpenCV_LIBS} ${PROJECT_SOURCE_DIR}/vnlog/libvnlog.so
)
add_dependencies(mrcal_jni_test mrcal_jni vnlog)
target_link_libraries(mrcal_jni_test PRIVATE ${OpenCV_LIBS} vnlog)

if(WITH_ASAN)
target_link_libraries(
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ See: http://mrcal.secretsauce.net/install.html

- Install cmake

```
```bash
sudo apt install cmake gcc g++ libmrcal-dev
cmake -B build . # You may need to add JAVA_HOME=/path/to/java
cmake --build build
```

For windows: `cmake -B build -S . -T ClangCl -A x64 -G "Visual Studio 17 2022"

For macOS:

```bash
cpan -i List::MoreUtils
cmake -B build -DOPENCV_ARCH=osxuniversal -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake --build build
```
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ test {
useJUnitPlatform()
}

ext.nativeName = wpilibTools.platformMapper.currentPlatform.platformName.replace('win', 'windows/').replace('mac', 'osx/').replace('linux', 'linux/').replace('x64', 'x86-64');
ext.nativeName = wpilibTools.platformMapper.wpilibClassifier
.replace('windows', 'windows/')
.replace('osx', 'osx/')
.replace('linux', 'linux/')
ext.outputsFolder = file("$buildDir/outputs")

println("Building for $nativeName")
Expand All @@ -67,7 +70,7 @@ tasks.register('copyNativeLibrary', Sync) {
from "${projectDir}/cmake_build/lib/"
// Hardcode to shared because we're not building static ever
into "${outputsFolder}/${nativeName}/shared/"
include "**/*.dll", "**/*.so"
include "**/*.dll", "**/*.so", "**/*.dylib"
includeEmptyDirs = false

build.dependsOn it
Expand Down
2 changes: 1 addition & 1 deletion publish.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'maven-publish'

def nativeName = wpilibTools.platformMapper.currentPlatform.platformName;
def nativeName = wpilibTools.platformMapper.wpilibClassifier;
def artifactGroupId = 'org.photonvision'
def baseArtifactId = "photon-mrcal"

Expand Down
2 changes: 1 addition & 1 deletion src/mrcal_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <malloc.h>
#include <stdint.h>
#include <stdlib.h>

#include <algorithm>
#include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion src/mrcal_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

#include "mrcal_wrapper.h"

#include <malloc.h>
#include <stdint.h>
#include <stdlib.h>

#include <algorithm>
#include <chrono>
Expand Down
1 change: 1 addition & 0 deletions src/mrcal_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
extern "C" {
// Seems to be missing C++ guards
#include <mrcal.h>

} // extern "C"

#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion vnlog