Skip to content

Commit f1e1fee

Browse files
authored
[JAVA] Benchmark app can be build without OpenCV, fixed CMakeLists for samples (opencv#4)
1 parent e929f98 commit f1e1fee

File tree

4 files changed

+73
-21
lines changed

4 files changed

+73
-21
lines changed
Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,64 @@
11
# Copyright (C) 2020 Intel Corporation
22

3-
find_package(OpenCV)
4-
if(NOT OpenCV_FOUND)
5-
message(WARNING ".jar file wasn't found for OpenCV. Java samples won't be build.")
6-
return()
7-
endif()
3+
# Find OpenCV components if exist
4+
5+
find_package(OpenCV QUIET)
86

97
if(EXISTS "${OpenCV_INSTALL_PATH}/share/java")
10-
file(GLOB_RECURSE java_opencv_src ${OpenCV_INSTALL_PATH}/share/java/*.jar)
8+
file(GLOB_RECURSE JAVA_OPENCV_SRC ${OpenCV_INSTALL_PATH}/share/java/*.jar)
119
elseif(EXISTS "${OpenCV_INSTALL_PATH}/bin")
12-
file(GLOB java_opencv_src ${OpenCV_INSTALL_PATH}/bin/*.jar)
10+
file(GLOB JAVA_OPENCV_SRC ${OpenCV_INSTALL_PATH}/bin/*.jar)
1311
endif()
1412

15-
if(EXISTS "${java_opencv_src}")
16-
file(GLOB java_samples ${CMAKE_CURRENT_SOURCE_DIR}/samples/*)
17-
foreach(sample IN LISTS java_samples)
18-
if(IS_DIRECTORY "${sample}")
19-
get_filename_component(sample_name "${sample}" NAME)
20-
file(GLOB_RECURSE sample_src ${sample}/*.java)
21-
add_jar("${sample_name}_jar"
22-
SOURCES ${sample_src}
23-
${PROJECT_SOURCE_DIR}/samples/ArgumentParser.java
24-
OUTPUT_NAME ${sample_name}
25-
OUTPUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
26-
INCLUDE_JARS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/* ${java_opencv_src})
13+
#
14+
# ie_add_java_sample(NAME <target name>
15+
# SOURCES <source files>
16+
# [DEPENDENCIES <dependencies>]
17+
# [OPENCV_DEPENDENCIES]
18+
#
19+
macro(ie_add_java_sample)
20+
set(options OPENCV_DEPENDENCIES)
21+
set(oneValueArgs NAME)
22+
cmake_parse_arguments(IE_SAMPLE "${options}" "${oneValueArgs}"
23+
"" ${ARGN} )
24+
25+
# Collect sample sources
26+
27+
file(GLOB_RECURSE SAMPLE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.java)
28+
list(APPEND SAMPLE_SOURCES ${PROJECT_SOURCE_DIR}/samples/ArgumentParser.java)
29+
30+
# Set InferenceEngine component
31+
32+
set(IE_JAVA_SRC ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/inference_engine_java_api.jar)
33+
34+
# Add OpenCV components if required
35+
36+
if(IE_SAMPLE_OPENCV_DEPENDENCIES)
37+
if(EXISTS "${JAVA_OPENCV_SRC}")
38+
list(APPEND IE_JAVA_SRC ${JAVA_OPENCV_SRC})
39+
else()
40+
message(WARNING "OPENCV .jar file is disabled or not found, " ${IE_SAMPLE_NAME} " skipped")
41+
return()
2742
endif()
28-
endforeach()
29-
endif()
43+
endif()
44+
45+
# Create .jar file from sources
46+
47+
add_jar("${IE_SAMPLE_NAME}_jar"
48+
SOURCES ${SAMPLE_SOURCES}
49+
OUTPUT_NAME ${IE_SAMPLE_NAME}
50+
OUTPUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
51+
INCLUDE_JARS ${IE_JAVA_SRC})
52+
add_dependencies(${IE_SAMPLE_NAME}_jar inference_engine_jar)
53+
endmacro()
54+
55+
# Collect all samples subdirectories
56+
57+
file(GLOB samples_dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
58+
59+
foreach(dir ${samples_dirs})
60+
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
61+
# Include subdirectory to the project.
62+
add_subdirectory(${dir})
63+
endif()
64+
endforeach()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (C) 2020 Intel Corporation
2+
3+
get_filename_component(sample_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
4+
5+
ie_add_java_sample(NAME ${sample_name})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (C) 2020 Intel Corporation
2+
3+
get_filename_component(sample_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
4+
5+
ie_add_java_sample(NAME ${sample_name} OPENCV_DEPENDENCIES)
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (C) 2020 Intel Corporation
2+
3+
get_filename_component(sample_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
4+
5+
ie_add_java_sample(NAME ${sample_name} OPENCV_DEPENDENCIES)
6+

0 commit comments

Comments
 (0)