From 582a7f32d572e70e41e374d0f10ce2c519d0c0c8 Mon Sep 17 00:00:00 2001 From: James Choi Date: Tue, 6 Aug 2024 13:25:39 -0400 Subject: [PATCH] Merge pull request #25832 from chachoi-world:4.x Add support for QNX #25832 Build and test instruction for QNX: https://github.com/chachoi-world/qnx-ports/blob/main/opencv/README.md ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- CMakeLists.txt | 2 +- cmake/OpenCVFindLibsGrfmt.cmake | 24 ++++++++++++++++--- cmake/OpenCVInstallLayout.cmake | 18 ++++++++++++++ cmake/OpenCVUtils.cmake | 6 ++++- .../opencv2/core/utils/filesystem.private.hpp | 2 +- modules/core/src/parallel.cpp | 8 ++++++- modules/core/src/system.cpp | 9 +++++++ modules/core/src/utils/filesystem.cpp | 8 +++---- modules/ts/src/ts.cpp | 3 ++- 9 files changed, 68 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29d05cd86b..2639208157 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -773,7 +773,7 @@ if(UNIX OR MINGW) elseif(EMSCRIPTEN) # no need to link to system libs with emscripten elseif(QNXNTO) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} m) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} m regex) elseif(MINGW) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} pthread) else() diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake index 04755c4c2c..e059305938 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -24,7 +24,13 @@ else() set(_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES .so) endif() - find_package(ZLIB "${MIN_VER_ZLIB}") + if(QNX) + set(ZLIB_FOUND TRUE) + set(ZLIB_LIBRARY z) + set(ZLIB_LIBRARIES z) + else() + find_package(ZLIB "${MIN_VER_ZLIB}") + endif() if(ANDROID) set(CMAKE_FIND_LIBRARY_SUFFIXES ${_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) unset(_zlib_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) @@ -67,7 +73,13 @@ if(WITH_JPEG) ocv_clear_vars(JPEG_FOUND) else() ocv_clear_internal_cache_vars(JPEG_LIBRARY JPEG_INCLUDE_DIR) - include(FindJPEG) + if(QNX) + set(JPEG_LIBRARY jpeg) + set(JPEG_LIBRARIES jpeg) + set(JPEG_FOUND TRUE) + else() + include(FindJPEG) + endif() endif() if(NOT JPEG_FOUND) @@ -113,7 +125,13 @@ if(WITH_TIFF) ocv_clear_vars(TIFF_FOUND) else() ocv_clear_internal_cache_vars(TIFF_LIBRARY TIFF_INCLUDE_DIR) - include(FindTIFF) + if(QNX) + set(TIFF_LIBRARY tiff) + set(TIFF_LIBRARIES tiff) + set(TIFF_FOUND TRUE) + else() + include(FindTIFF) + endif() if(TIFF_FOUND) ocv_parse_header("${TIFF_INCLUDE_DIR}/tiff.h" TIFF_VERSION_LINES TIFF_VERSION_CLASSIC TIFF_VERSION_BIG TIFF_VERSION TIFF_BIGTIFF_VERSION) endif() diff --git a/cmake/OpenCVInstallLayout.cmake b/cmake/OpenCVInstallLayout.cmake index d5f35798dc..25aede72c5 100644 --- a/cmake/OpenCVInstallLayout.cmake +++ b/cmake/OpenCVInstallLayout.cmake @@ -56,6 +56,24 @@ elseif(WIN32 AND CMAKE_HOST_SYSTEM_NAME MATCHES Windows) ocv_update(OPENCV_JNI_INSTALL_PATH "java${_jni_suffix}") ocv_update(OPENCV_JNI_BIN_INSTALL_PATH "${OPENCV_JNI_INSTALL_PATH}") +elseif(QNX) + ocv_update(OPENCV_BIN_INSTALL_PATH "${CPUVARDIR}/usr/bin") + ocv_update(OPENCV_TEST_INSTALL_PATH "${OPENCV_BIN_INSTALL_PATH}") + ocv_update(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OPENCV_BIN_INSTALL_PATH}") + ocv_update(OPENCV_LIB_INSTALL_PATH "${CPUVARDIR}/usr/lib") + ocv_update(OPENCV_LIB_ARCHIVE_INSTALL_PATH "${OPENCV_LIB_INSTALL_PATH}") + ocv_update(OPENCV_3P_LIB_INSTALL_PATH "${CPUVARDIR}/usr/lib") + ocv_update(OPENCV_CONFIG_INSTALL_PATH "${CPUVARDIR}/usr/share/OpenCV") + ocv_update(OPENCV_INCLUDE_INSTALL_PATH "usr/include/OpenCV/opencv4") + ocv_update(OPENCV_OTHER_INSTALL_PATH "usr/share/OpenCV") + ocv_update(OPENCV_SAMPLES_SRC_INSTALL_PATH "samples/native") + ocv_update(OPENCV_LICENSES_INSTALL_PATH "${OPENCV_OTHER_INSTALL_PATH}/licenses") + ocv_update(OPENCV_TEST_DATA_INSTALL_PATH "${OPENCV_OTHER_INSTALL_PATH}/testdata") + ocv_update(OPENCV_DOC_INSTALL_PATH "doc") + ocv_update(OPENCV_JAR_INSTALL_PATH "${CMAKE_INSTALL_DATAROOTDIR}/java/opencv4") + ocv_update(OPENCV_JNI_INSTALL_PATH "${OPENCV_JAR_INSTALL_PATH}") + ocv_update(OPENCV_JNI_BIN_INSTALL_PATH "${OPENCV_JNI_INSTALL_PATH}") + else() # UNIX include(GNUInstallDirs) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index ae660f86b1..94f87d9a12 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -309,7 +309,11 @@ function(ocv_include_directories) dir MATCHES "/usr/include$") # workaround for GCC 6.x bug else() - include_directories(AFTER SYSTEM "${dir}") + if(${CMAKE_SYSTEM_NAME} MATCHES QNX) + include_directories(AFTER "${dir}") + else() + include_directories(AFTER SYSTEM "${dir}") + endif() endif() endforeach() include_directories(BEFORE ${__add_before}) diff --git a/modules/core/include/opencv2/core/utils/filesystem.private.hpp b/modules/core/include/opencv2/core/utils/filesystem.private.hpp index c6bd5b316a..80c9a5282c 100644 --- a/modules/core/include/opencv2/core/utils/filesystem.private.hpp +++ b/modules/core/include/opencv2/core/utils/filesystem.private.hpp @@ -13,7 +13,7 @@ /* not supported */ # elif defined __ANDROID__ || defined __linux__ || defined _WIN32 || \ defined __FreeBSD__ || defined __bsdi__ || defined __HAIKU__ || \ - defined __GNU__ + defined __GNU__ || defined __QNX__ # define OPENCV_HAVE_FILESYSTEM_SUPPORT 1 # elif defined(__APPLE__) # include diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index d81577cfed..5799d73599 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -72,6 +72,10 @@ #endif #endif +#if defined (__QNX__) + #include +#endif + #ifndef OPENCV_DISABLE_THREAD_SUPPORT #include #endif @@ -1011,7 +1015,9 @@ int getNumberOfCPUs_() static unsigned cpu_count_sysconf = (unsigned)sysconf( _SC_NPROCESSORS_ONLN ); ncpus = minNonZero(ncpus, cpu_count_sysconf); - +#elif defined (__QNX__) + static unsigned cpu_count_sysconf = _syspage_ptr->num_cpu; + ncpus = minNonZero(ncpus, cpu_count_sysconf); #endif return ncpus != 0 ? ncpus : 1; diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 9d5304ac5a..7e819acac7 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -46,6 +46,15 @@ #include #include +#ifdef __QNX__ + #include + #include + #include +#ifdef __aarch64__ + #include +#endif +#endif + #include #include diff --git a/modules/core/src/utils/filesystem.cpp b/modules/core/src/utils/filesystem.cpp index f598558616..d416284062 100644 --- a/modules/core/src/utils/filesystem.cpp +++ b/modules/core/src/utils/filesystem.cpp @@ -34,7 +34,7 @@ #include #include #include -#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ || defined __GNU__ || defined __EMSCRIPTEN__ +#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ || defined __GNU__ || defined __EMSCRIPTEN__ || defined __QNX__ #include #include #include @@ -194,7 +194,7 @@ cv::String getcwd() sz = GetCurrentDirectoryA((DWORD)buf.size(), buf.data()); return cv::String(buf.data(), (size_t)sz); #endif -#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ || defined __EMSCRIPTEN__ +#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ || defined __EMSCRIPTEN__ || defined __QNX__ for(;;) { char* p = ::getcwd(buf.data(), buf.size()); @@ -228,7 +228,7 @@ bool createDirectory(const cv::String& path) #else int result = _mkdir(path.c_str()); #endif -#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ || defined __EMSCRIPTEN__ +#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ || defined __EMSCRIPTEN__ || defined __QNX__ int result = mkdir(path.c_str(), 0777); #else int result = -1; @@ -343,7 +343,7 @@ private: Impl& operator=(const Impl&); // disabled }; -#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ || defined __GNU__ || defined __EMSCRIPTEN__ +#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__ || defined __GNU__ || defined __EMSCRIPTEN__ || defined __QNX__ struct FileLock::Impl { diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index f60ba9dd2b..163b573b3e 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -1035,7 +1035,8 @@ static std::string findData(const std::string& relative_path, bool required, boo } } #ifdef OPENCV_TEST_DATA_INSTALL_PATH - datapath = path_join("./", OPENCV_TEST_DATA_INSTALL_PATH); + datapath = OPENCV_TEST_DATA_INSTALL_PATH; + if (isDirectory(datapath)) { for(size_t i = search_subdir.size(); i > 0; i--)