Skip to content

Commit

Permalink
Build against wpilib opencv (#14)
Browse files Browse the repository at this point in the history
* Swap to wpilib opencv

Update main.yml

* system-include opencv
  • Loading branch information
mcm001 authored Mar 4, 2024
1 parent 75fc678 commit 2693ec0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
bind_mount_repository: true
commands: |
apt-get update
apt-get install -y libopencv-dev libegl1-mesa-dev libcamera-dev cmake build-essential libdrm-dev libgbm-dev default-jdk openjdk-17-jdk
apt show libcamera*
apt-get install -y libegl1-mesa-dev libcamera-dev cmake build-essential libdrm-dev libgbm-dev default-jdk openjdk-17-jdk
cmake -B cmake_build -DCMAKE_BUILD_TYPE=Release
cmake --build cmake_build -j 4
Expand Down
45 changes: 41 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,40 @@ set(CMAKE_CXX_EXTENSIONS OFF)
find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(OpenGL REQUIRED COMPONENTS OpenGL EGL)
find_package(OpenCV REQUIRED)
pkg_check_modules(LIBDRM REQUIRED libdrm)
pkg_check_modules(LIBCAMERA REQUIRED libcamera)
pkg_check_modules(LIBGBM REQUIRED gbm)

set(OPENCV_YEAR "frc2024")
set(OPENCV_VERSION "4.8.0-2")
# also valid: windowsx86-64

# type can be "", "debug", "static", or "staticdebug"
set(OPENCV_TYPE "")
set(OPENCV_ARCH "linuxarm64")

# Download opencv, and save the path
include(FetchContent)
FetchContent_Declare(
opencv_lib
URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-${OPENCV_ARCH}${OPENCV_TYPE}.zip
)
FetchContent_MakeAvailable(opencv_lib)

# download OpenCV headers
FetchContent_Declare(
opencv_header
URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-headers.zip
)
FetchContent_MakeAvailable(opencv_header)

file(GLOB_RECURSE OPENCV_LIB_PATH
"${opencv_lib_SOURCE_DIR}/**/*.lib"
"${opencv_lib_SOURCE_DIR}/**/*.so*"
)
SET(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR})
message("Depending on opencv ${OPENCV_LIB_PATH} / ${OPENCV_INCLUDE_PATH}")

find_package(JNI)
if(JNI_FOUND)
# Fixes odd AWT dependency
Expand Down Expand Up @@ -47,9 +76,13 @@ target_include_directories(
${LIBDRM_INCLUDE_DIRS}
${LIBCAMERA_INCLUDE_DIRS}
${LIBGBM_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${JNI_INCLUDE_DIRS}
)
target_include_directories(
photonlibcamera
SYSTEM PUBLIC
${OPENCV_INCLUDE_PATH}
)
target_link_libraries(
photonlibcamera
PUBLIC
Expand All @@ -58,7 +91,7 @@ target_link_libraries(
Threads::Threads
${LIBCAMERA_LINK_LIBRARIES}
${LIBGBM_LINK_LIBRARIES}
${OpenCV_LIBS}
${OPENCV_LIB_PATH}
${LIBDRM_LINK_LIBRARIES}
)
target_compile_options(photonlibcamera PRIVATE -Wall -Wextra -Wpedantic -Werror)
Expand All @@ -71,7 +104,11 @@ target_include_directories(
${LIBDRM_INCLUDE_DIRS}
${LIBCAMERA_INCLUDE_DIRS}
${LIBGBM_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${JNI_INCLUDE_DIRS}
)
target_include_directories(
libcamera_meme
SYSTEM PUBLIC
${OPENCV_INCLUDE_PATH}
)
target_link_libraries(libcamera_meme photonlibcamera)

0 comments on commit 2693ec0

Please sign in to comment.