From 0ab32e53b26c5ee6eb0638d8b8d7b3fb3c7ce339 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Mon, 6 Jul 2026 19:40:05 +0200 Subject: [PATCH 1/3] Link samples statically to OpenCV --- samples/cpp/fetch_opencv.cmake | 20 ++++---------------- samples/cpp/image_generation/CMakeLists.txt | 16 ---------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/samples/cpp/fetch_opencv.cmake b/samples/cpp/fetch_opencv.cmake index f075b8bc63..55b769e6ac 100644 --- a/samples/cpp/fetch_opencv.cmake +++ b/samples/cpp/fetch_opencv.cmake @@ -7,6 +7,7 @@ function(ov_genai_link_opencv target_name) set(required_components core imgproc videoio imgcodecs) endif() + set(OpenCV_STATIC ON) find_package(OpenCV QUIET COMPONENTS ${required_components}) if(NOT OpenCV_FOUND) @@ -16,7 +17,9 @@ function(ov_genai_link_opencv target_name) cmake_policy(SET CMP0135 NEW) endif() - set(BUILD_SHARED_LIBS ON) + set(BUILD_SHARED_LIBS OFF) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + set(OPENCV_ENABLE_PLUGINS OFF CACHE BOOL "" FORCE) set(WITH_FFMPEG ON) set(WITH_PROTOBUF OFF CACHE BOOL "" FORCE) set(WITH_GSTREAMER OFF CACHE BOOL "" FORCE) @@ -67,21 +70,6 @@ function(ov_genai_link_opencv target_name) target_include_directories(${target_name} PRIVATE ${OPENCV_MODULE_opencv_${component}_LOCATION}/include) endforeach() - - if(LINUX) - set_target_properties(${target_name} ${opencv_targets} PROPERTIES - INSTALL_RPATH "$ORIGIN/../lib" - INSTALL_RPATH_USE_LINK_PATH ON) - elseif(APPLE) - set_target_properties(${target_name} ${opencv_targets} PROPERTIES - INSTALL_RPATH "@loader_path/../lib" - INSTALL_RPATH_USE_LINK_PATH ON) - endif() - - # Signal to callers that OpenCV was built from source via FetchContent, - # so target-scoped CMake can emit any runtime deployment rules it needs - # (e.g., installing the fetched DLLs next to a Windows sample EXE). - set_property(GLOBAL PROPERTY OV_GENAI_FETCHED_OPENCV TRUE) else() set(opencv_targets ${OpenCV_LIBS}) if(OpenCV_INCLUDE_DIRS) diff --git a/samples/cpp/image_generation/CMakeLists.txt b/samples/cpp/image_generation/CMakeLists.txt index 94358783bc..fde6898ed3 100644 --- a/samples/cpp/image_generation/CMakeLists.txt +++ b/samples/cpp/image_generation/CMakeLists.txt @@ -54,22 +54,6 @@ set_target_properties(denoising_process PROPERTIES # Ensure out of box LC_RPATH on macOS with SIP INSTALL_RPATH_USE_LINK_PATH ON) -# Windows: when OpenCV was built from source via FetchContent, deploy the -# component DLLs next to denoising_process.exe in samples_bin/. The Windows -# loader has no rpath, and install/samples_bin/ is not on PATH at runtime -# unless the user puts it there. Skipped when find_package found a system -# OpenCV, since those installs ship their own runtime path. -get_property(_ov_genai_opencv_fetched GLOBAL PROPERTY OV_GENAI_FETCHED_OPENCV) -if(WIN32 AND _ov_genai_opencv_fetched) - install(FILES "$" - "$" - "$" - "$" - DESTINATION samples_bin/ - COMPONENT samples_bin - EXCLUDE_FROM_ALL) -endif() - install(TARGETS denoising_process RUNTIME DESTINATION samples_bin/ COMPONENT samples_bin From a1a711d3f20845f0dba793972487b3d001a6fc4d Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Tue, 7 Jul 2026 08:02:50 +0200 Subject: [PATCH 2/3] Apply comments --- samples/cpp/fetch_opencv.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/cpp/fetch_opencv.cmake b/samples/cpp/fetch_opencv.cmake index 55b769e6ac..ee148dfd4b 100644 --- a/samples/cpp/fetch_opencv.cmake +++ b/samples/cpp/fetch_opencv.cmake @@ -17,7 +17,7 @@ function(ov_genai_link_opencv target_name) cmake_policy(SET CMP0135 NEW) endif() - set(BUILD_SHARED_LIBS OFF) + set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(OPENCV_ENABLE_PLUGINS OFF CACHE BOOL "" FORCE) set(WITH_FFMPEG ON) From e5856e01854cd0ac33e4592200fd545920035cb2 Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Mon, 13 Jul 2026 14:15:30 +0200 Subject: [PATCH 3/3] Apply comments --- samples/cpp/fetch_opencv.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/cpp/fetch_opencv.cmake b/samples/cpp/fetch_opencv.cmake index ee148dfd4b..1bf91bdd6c 100644 --- a/samples/cpp/fetch_opencv.cmake +++ b/samples/cpp/fetch_opencv.cmake @@ -10,6 +10,10 @@ function(ov_genai_link_opencv target_name) set(OpenCV_STATIC ON) find_package(OpenCV QUIET COMPONENTS ${required_components}) + if(OpenCV_FOUND AND OpenCV_SHARED) + message(FATAL_ERROR "Found a shared OpenCV, but a static one is required. Set -DOpenCV_DIR to a static build or make it undiscoverable.") + endif() + if(NOT OpenCV_FOUND) include(FetchContent)