diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f54f603..9dcb731 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }}" @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 44911a1..a46ab1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") @@ -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 @@ -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) @@ -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) @@ -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( diff --git a/README.md b/README.md index c51c028..d60c1d9 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/build.gradle b/build.gradle index 97be2f1..115d671 100644 --- a/build.gradle +++ b/build.gradle @@ -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") @@ -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 diff --git a/publish.gradle b/publish.gradle index de0f924..ff28e54 100644 --- a/publish.gradle +++ b/publish.gradle @@ -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" diff --git a/src/mrcal_test.cpp b/src/mrcal_test.cpp index d20ee56..db8df2f 100644 --- a/src/mrcal_test.cpp +++ b/src/mrcal_test.cpp @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#include #include +#include #include #include diff --git a/src/mrcal_wrapper.cpp b/src/mrcal_wrapper.cpp index 805a61b..4690930 100644 --- a/src/mrcal_wrapper.cpp +++ b/src/mrcal_wrapper.cpp @@ -32,8 +32,8 @@ #include "mrcal_wrapper.h" -#include #include +#include #include #include diff --git a/src/mrcal_wrapper.h b/src/mrcal_wrapper.h index fb1cdd0..a047db4 100644 --- a/src/mrcal_wrapper.h +++ b/src/mrcal_wrapper.h @@ -35,6 +35,7 @@ extern "C" { // Seems to be missing C++ guards #include + } // extern "C" #include diff --git a/vnlog b/vnlog index be94ea1..4342e7e 160000 --- a/vnlog +++ b/vnlog @@ -1 +1 @@ -Subproject commit be94ea1348c1c050c38dcaf6ab9b9e054d6d904f +Subproject commit 4342e7e5ded6f90dc264b6633b8301733d95017a