Skip to content

Commit

Permalink
Move OpenCV find_package closely to benchmark_app (openvinotoolkit#8654)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov authored and OpenVINO-dev-contest committed Nov 23, 2021
1 parent 6ae4833 commit 933d9fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
18 changes: 2 additions & 16 deletions inference-engine/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,15 @@ include(CMakeParseArguments)
# [HEADERS <header files>]
# [INCLUDE_DIRECTORIES <include dir>]
# [DEPENDENCIES <dependencies>]
# [OPENCV_DEPENDENCIES <opencv modules>]
# [EXCLUDE_CLANG_FORMAT]
#
macro(ie_add_sample)
set(options EXCLUDE_CLANG_FORMAT)
set(oneValueArgs NAME)
set(multiValueArgs SOURCES HEADERS DEPENDENCIES OPENCV_DEPENDENCIES INCLUDE_DIRECTORIES)
set(multiValueArgs SOURCES HEADERS DEPENDENCIES INCLUDE_DIRECTORIES)
cmake_parse_arguments(IE_SAMPLE "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

# Find OpenCV components if exist
if(IE_SAMPLE_OPENCV_DEPENDENCIES)
find_package(OpenCV COMPONENTS ${IE_SAMPLE_OPENCV_DEPENDENCIES} QUIET)
if(NOT OpenCV_FOUND)
message(WARNING "OPENCV is disabled or not found, ${IE_SAMPLE_NAME} skipped")
return()
endif()
endif()

# Create named folders for the sources within the .vcproj
# Empty name lists them directly under the .vcproj
source_group("src" FILES ${IE_SAMPLE_SOURCES})
Expand All @@ -196,9 +186,6 @@ macro(ie_add_sample)

# Create executable file from sources
add_executable(${IE_SAMPLE_NAME} ${IE_SAMPLE_SOURCES} ${IE_SAMPLE_HEADERS})
if(IE_SAMPLE_OPENCV_DEPENDENCIES)
target_compile_definitions(${IE_SAMPLE_NAME} PRIVATE USE_OPENCV)
endif()

set(folder_name cpp_samples)
if(IE_SAMPLE_NAME MATCHES ".*_c$")
Expand All @@ -221,8 +208,7 @@ macro(ie_add_sample)
endif()
target_include_directories(${IE_SAMPLE_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../common")

target_link_libraries(${IE_SAMPLE_NAME} PRIVATE ${OpenCV_LIBRARIES} ${ov_link_libraries}
${IE_SAMPLE_DEPENDENCIES})
target_link_libraries(${IE_SAMPLE_NAME} PRIVATE ${ov_link_libraries} ${IE_SAMPLE_DEPENDENCIES})
if(NOT c_sample)
target_link_libraries(${IE_SAMPLE_NAME} PRIVATE gflags)
endif()
Expand Down
19 changes: 13 additions & 6 deletions inference-engine/samples/benchmark_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

set(TARGET_NAME "benchmark_app")

if(ENABLE_OPENCV)
set(OPENCV_MODULES core)
endif()

file (GLOB SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file (GLOB HDR ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)

ie_add_sample(NAME ${TARGET_NAME}
SOURCES ${SRC}
HEADERS ${HDR}
DEPENDENCIES format_reader ie_samples_utils
OPENCV_DEPENDENCIES ${OPENCV_MODULES})
DEPENDENCIES format_reader ie_samples_utils)

# Optional OpenCL dependnency

find_package(OpenCL)

Expand Down Expand Up @@ -51,3 +48,13 @@ if(OpenCL_FOUND AND OpenCL_HEADERS)
target_include_directories(${TARGET_NAME} PRIVATE ${OpenCL_HEADERS})
target_compile_definitions(${TARGET_NAME} PRIVATE HAVE_GPU_DEVICE_MEM_SUPPORT)
endif()

# Optional OpenCV dependnency

find_package(OpenCV COMPONENTS core QUIET)
if(NOT OpenCV_FOUND)
message(WARNING "OpenCV is disabled or not found, ${TARGET_NAME} will be built without OpenCV support. Set OpenCV_DIR")
else()
target_compile_definitions(${TARGET_NAME} PRIVATE USE_OPENCV)
target_link_libraries(${TARGET_NAME} PRIVATE opencv_core)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ add_library(${TARGET_NAME} SHARED ${MAIN_SRC} ${LIBRARY_HEADERS})
# Find OpenCV components if exist
find_package(OpenCV COMPONENTS core imgproc imgcodecs QUIET)
if(NOT OpenCV_FOUND)
message(WARNING "OPENCV is disabled or not found, ${TARGET_NAME} will be built without OPENCV support")
message(WARNING "OpenCV is disabled or not found, ${TARGET_NAME} will be built without OpenCV support")
else()
target_link_libraries(${TARGET_NAME} PRIVATE ${OpenCV_LIBRARIES} ie_samples_utils)
if(UNIX AND NOT APPLE)
Expand Down

0 comments on commit 933d9fb

Please sign in to comment.