From 0f313fb9ab5afd532dbdaf92fd3d6dc54fb322dd Mon Sep 17 00:00:00 2001 From: CircuitCraft42 <46874825+CircuitCraft42@users.noreply.github.com> Date: Mon, 10 Feb 2020 20:30:54 -0500 Subject: [PATCH] cmake: Improved portability of OpenCV Java binding search (#2348) The CMake option OPENCV_JAVA_INSTALL_DIR can be set to the location to search for the jar file. Note that the file name cannot be changed, as, after checking several Linux package repositories, that seems to be constant across all of them. Fixes #2346. --- CMakeLists.txt | 10 ++++++++++ README-CMAKE.md | 2 ++ cscore/CMakeLists.txt | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a54492009..3930be2748 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ option(USE_VCPKG_LIBUV "Use vcpkg libuv" OFF) option(USE_VCPKG_EIGEN "Use vcpkg eigen" OFF) option(FLAT_INSTALL_WPILIB "Use a flat install directory" OFF) option(WITH_SIMULATION_MODULES "build simulation modules" OFF) +set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file") if (NOT WITHOUT_JAVA AND NOT BUILD_SHARED_LIBS) message(FATAL_ERROR " @@ -64,6 +65,15 @@ FATAL: Cannot build static libs with Java enabled. ") endif() +if (WITHOUT_JAVA OR WITHOUT_CSCORE) + if(NOT "${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "") + message(WARNING " +WARNING: OpenCV Java dir set but java is not enabled! +It will be ignored. +") + endif() +endif() + set( wpilib_dest wpilib) set( include_dest wpilib/include ) set( main_lib_dest wpilib/lib ) diff --git a/README-CMAKE.md b/README-CMAKE.md index 68e817548a..52edec0979 100644 --- a/README-CMAKE.md +++ b/README-CMAKE.md @@ -34,6 +34,8 @@ The following build options are available: * TODO * EXTERNAL_HAL_FILE * TODO +* OPENCV_JAVA_INSTALL_DIR + * Set this option to the location of the archive of the OpenCV Java bindings (it should be called opencv-xxx.jar, with the x'es being version numbers). NOTE: set it to the LOCATION of the file, not the file itself! ## Build Setup diff --git a/cscore/CMakeLists.txt b/cscore/CMakeLists.txt index a87ab7d539..f5b4751d2f 100644 --- a/cscore/CMakeLists.txt +++ b/cscore/CMakeLists.txt @@ -69,7 +69,9 @@ if (NOT WITHOUT_JAVA) #find java files, copy them locally - set(OPENCV_JAVA_INSTALL_DIR ${OpenCV_INSTALL_PATH}/share/OpenCV/java/) + if("${OPENCV_JAVA_INSTALL_DIR}" STREQUAL "") + set(OPENCV_JAVA_INSTALL_DIR ${OpenCV_INSTALL_PATH}/share/OpenCV/java/) + endif() find_file(OPENCV_JAR_FILE NAMES opencv-${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.jar PATHS ${OPENCV_JAVA_INSTALL_DIR} ${OpenCV_INSTALL_PATH}/bin NO_DEFAULT_PATH) find_file(OPENCV_JNI_FILE NAMES libopencv_java${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}.so