Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions samples/cpp/fetch_opencv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function(ov_genai_link_opencv target_name)
set(required_components core imgproc videoio imgcodecs)
endif()

set(OpenCV_STATIC ON)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a significant change to compiled samples size?

@olpipi olpipi Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. text2video on Linux:
~3Mb -> ~70Mb for Debug
~130Kb -> 28Mb for Release

find_package(OpenCV QUIET COMPONENTS ${required_components})

Comment thread
olpipi marked this conversation as resolved.
if(NOT OpenCV_FOUND)
Expand All @@ -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 CACHE BOOL "" FORCE)
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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 0 additions & 16 deletions samples/cpp/image_generation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<TARGET_FILE:opencv_core>"
"$<TARGET_FILE:opencv_imgproc>"
"$<TARGET_FILE:opencv_imgcodecs>"
"$<TARGET_FILE:opencv_videoio>"
DESTINATION samples_bin/
COMPONENT samples_bin
EXCLUDE_FROM_ALL)
endif()

install(TARGETS denoising_process
RUNTIME DESTINATION samples_bin/
COMPONENT samples_bin
Expand Down
Loading