2022-01-19 01:07:49 +03:00
|
|
|
# Copyright (C) 2018-2022 Intel Corporation
|
2018-10-16 13:45:03 +03:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
#
|
2019-01-21 21:31:31 +03:00
|
|
|
|
2020-10-01 11:37:39 +03:00
|
|
|
cmake_minimum_required (VERSION 3.10)
|
2018-10-16 13:45:03 +03:00
|
|
|
|
2021-01-11 14:48:27 +03:00
|
|
|
# Enable CMAKE_<LANG>_COMPILER_ID AppleClang
|
|
|
|
|
cmake_policy(SET CMP0025 NEW)
|
2020-05-13 21:12:22 +03:00
|
|
|
|
2021-01-11 14:48:27 +03:00
|
|
|
project(Samples)
|
2020-04-13 21:17:23 +03:00
|
|
|
|
2021-11-27 14:58:24 +03:00
|
|
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "CMake build type")
|
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithDebInfo" "MinSizeRel")
|
2018-10-16 13:45:03 +03:00
|
|
|
|
2020-04-27 21:21:29 +03:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
|
2021-01-11 14:48:27 +03:00
|
|
|
if (NOT BIN_FOLDER)
|
2019-08-09 19:02:42 +03:00
|
|
|
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} ARCH)
|
2022-09-19 10:14:07 +04:00
|
|
|
if(ARCH STREQUAL "x86_64" OR ARCH STREQUAL "amd64" # Windows detects Intel's 64-bit CPU as AMD64
|
|
|
|
|
OR CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
|
2019-08-09 19:02:42 +03:00
|
|
|
set(ARCH intel64)
|
|
|
|
|
elseif(ARCH STREQUAL "i386")
|
|
|
|
|
set(ARCH ia32)
|
2018-10-16 13:45:03 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
set (BIN_FOLDER ${ARCH})
|
2021-01-11 18:38:11 +03:00
|
|
|
|
|
|
|
|
if(UNIX)
|
|
|
|
|
set(BIN_FOLDER "${BIN_FOLDER}/${CMAKE_BUILD_TYPE}")
|
|
|
|
|
endif()
|
2018-10-16 13:45:03 +03:00
|
|
|
endif()
|
|
|
|
|
|
2021-06-30 18:15:41 +03:00
|
|
|
if(OpenVINO_SOURCE_DIR)
|
2018-11-23 16:19:43 +03:00
|
|
|
# in case if samples are built from IE repo
|
2021-09-10 15:31:27 +03:00
|
|
|
set(IE_MAIN_SAMPLES_DIR "${OpenVINO_SOURCE_DIR}")
|
|
|
|
|
set(OpenVINO_DIR "${CMAKE_BINARY_DIR}")
|
2020-02-11 22:48:49 +03:00
|
|
|
else()
|
|
|
|
|
# in case if samples are built out of IE repo
|
|
|
|
|
set(IE_MAIN_SAMPLES_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
2018-10-16 13:45:03 +03:00
|
|
|
endif()
|
|
|
|
|
|
2022-08-12 12:10:03 +04:00
|
|
|
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER})
|
|
|
|
|
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER})
|
2021-01-11 18:38:11 +03:00
|
|
|
set (CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER})
|
|
|
|
|
set (CMAKE_PDB_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER})
|
|
|
|
|
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${IE_MAIN_SAMPLES_DIR}/${BIN_FOLDER})
|
2018-10-16 13:45:03 +03:00
|
|
|
|
2022-10-06 13:44:21 +04:00
|
|
|
if(TREAT_WARNING_AS_ERROR AND NOT DEFINED CMAKE_COMPILE_WARNING_AS_ERROR)
|
|
|
|
|
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
|
|
|
|
|
endif()
|
|
|
|
|
|
2018-10-16 13:45:03 +03:00
|
|
|
if (WIN32)
|
2019-01-21 21:31:31 +03:00
|
|
|
set_property (DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _CRT_SECURE_NO_WARNINGS)
|
2021-07-30 13:54:09 +03:00
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
|
|
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") # no asynchronous structured exception handling
|
2019-01-21 21:31:31 +03:00
|
|
|
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
|
2019-05-27 21:18:32 +03:00
|
|
|
|
2020-08-03 14:01:56 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
|
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qdiag-disable:177")
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-07-30 13:54:09 +03:00
|
|
|
# disable some noisy warnings
|
2020-05-13 21:12:22 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
2021-07-30 13:54:09 +03:00
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /wd4275 /wd4267 /wd4819")
|
2019-04-12 18:25:53 +03:00
|
|
|
endif()
|
2018-10-16 13:45:03 +03:00
|
|
|
else()
|
2021-07-26 12:42:05 +03:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
|
|
|
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -diag-disable:177")
|
|
|
|
|
endif()
|
2018-10-16 13:45:03 +03:00
|
|
|
endif()
|
|
|
|
|
|
2020-04-27 21:21:29 +03:00
|
|
|
if(APPLE)
|
|
|
|
|
set(CMAKE_MACOSX_RPATH ON)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-08-06 21:14:44 +03:00
|
|
|
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64.*|aarch64.*|AARCH64.*)")
|
|
|
|
|
set(AARCH64 ON)
|
|
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
|
|
|
|
|
set(ARM ON)
|
|
|
|
|
endif()
|
|
|
|
|
if(ARM AND NOT CMAKE_CROSSCOMPILING)
|
2021-08-04 17:58:20 +03:00
|
|
|
add_compile_options(-march=armv7-a)
|
|
|
|
|
endif()
|
|
|
|
|
|
2020-04-27 21:21:29 +03:00
|
|
|
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
|
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
|
|
|
|
set(CMAKE_C_VISIBILITY_PRESET hidden)
|
|
|
|
|
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
|
|
|
|
|
|
2018-10-16 13:45:03 +03:00
|
|
|
####################################
|
2020-04-13 21:17:23 +03:00
|
|
|
## to use C++11; can overwritten via cmake command line
|
|
|
|
|
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
|
|
|
|
set (CMAKE_CXX_STANDARD 11)
|
|
|
|
|
set (CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
2019-04-12 18:25:53 +03:00
|
|
|
endif()
|
2018-10-16 13:45:03 +03:00
|
|
|
####################################
|
|
|
|
|
|
2022-12-01 23:57:23 +04:00
|
|
|
if(TARGET gflags)
|
|
|
|
|
set(GFLAGS_TARGET gflags)
|
2022-12-02 22:10:02 +04:00
|
|
|
else()
|
2022-12-01 23:57:23 +04:00
|
|
|
if(EXISTS /etc/debian_version)
|
|
|
|
|
set(gflags_component nothreads_static)
|
|
|
|
|
else()
|
|
|
|
|
set(gflags_component shared)
|
|
|
|
|
endif()
|
|
|
|
|
find_package(gflags QUIET OPTIONAL_COMPONENTS ${gflags_component})
|
|
|
|
|
if(gflags_FOUND)
|
|
|
|
|
if(TARGET ${GFLAGS_TARGET})
|
|
|
|
|
# nothing
|
|
|
|
|
elseif(TARGET gflags_nothreads-static)
|
|
|
|
|
# Debian 9: gflag_component is ignored
|
|
|
|
|
set(GFLAGS_TARGET gflags_nothreads-static)
|
|
|
|
|
elseif(TARGET gflags-shared)
|
|
|
|
|
# gflags shared case for CentOS / RHEL / Fedora
|
|
|
|
|
set(GFLAGS_TARGET gflags-shared)
|
2022-11-25 10:57:00 +04:00
|
|
|
else()
|
2022-12-01 23:57:23 +04:00
|
|
|
message(FATAL_ERROR "Internal error: failed to find imported target 'gflags' using '${gflags_component}' component")
|
2022-11-25 10:57:00 +04:00
|
|
|
endif()
|
2022-12-01 23:57:23 +04:00
|
|
|
|
|
|
|
|
message(STATUS "gflags (${gflags_VERSION}) is found at ${gflags_DIR} using '${gflags_component}' component")
|
2022-04-05 22:16:32 +03:00
|
|
|
endif()
|
2022-04-05 04:47:22 +03:00
|
|
|
|
2022-12-01 23:57:23 +04:00
|
|
|
if(NOT gflags_FOUND)
|
|
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gflags")
|
|
|
|
|
add_subdirectory(thirdparty/gflags EXCLUDE_FROM_ALL)
|
|
|
|
|
set(GFLAGS_TARGET gflags_nothreads_static)
|
|
|
|
|
else()
|
|
|
|
|
message(FATAL_ERROR "Failed to find 'gflags' library using '${gflags_component}' component")
|
2022-10-12 12:16:13 +04:00
|
|
|
endif()
|
2022-04-05 04:47:22 +03:00
|
|
|
endif()
|
2020-02-11 22:48:49 +03:00
|
|
|
endif()
|
2019-04-12 18:25:53 +03:00
|
|
|
|
2021-03-26 15:07:59 +03:00
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/common/utils")
|
|
|
|
|
add_subdirectory(common/utils)
|
|
|
|
|
endif()
|
|
|
|
|
|
2021-09-10 15:31:27 +03:00
|
|
|
# format reader must be added after find_package(OpenVINO) to get
|
|
|
|
|
# exactly the same OpenCV_DIR path which was used for the OpenVINO build
|
2020-02-11 22:48:49 +03:00
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/common/format_reader")
|
|
|
|
|
add_subdirectory(common/format_reader)
|
2021-04-26 13:42:12 +03:00
|
|
|
elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/common/opencv_c_wrapper")
|
|
|
|
|
add_subdirectory(common/opencv_c_wrapper)
|
2020-02-11 22:48:49 +03:00
|
|
|
endif()
|
2018-10-16 13:45:03 +03:00
|
|
|
|
2019-04-12 18:25:53 +03:00
|
|
|
# samples build can be switched off during whole IE build
|
2021-06-30 18:15:41 +03:00
|
|
|
if (DEFINED OpenVINO_SOURCE_DIR AND NOT ENABLE_SAMPLES)
|
2019-04-12 18:25:53 +03:00
|
|
|
return()
|
2018-10-16 13:45:03 +03:00
|
|
|
endif()
|
|
|
|
|
|
2019-04-12 18:25:53 +03:00
|
|
|
function(add_samples_to_build)
|
|
|
|
|
# check each passed sample subdirectory
|
|
|
|
|
foreach (dir ${ARGN})
|
|
|
|
|
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
|
|
|
|
|
# check if a subdirectory contains CMakeLists.txt. In this case we can build it.
|
|
|
|
|
file(GLOB is_sample_dir "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt")
|
|
|
|
|
if(is_sample_dir)
|
|
|
|
|
# check if specified sample/demo is found.
|
|
|
|
|
if (BUILD_SAMPLE_NAME)
|
|
|
|
|
list(FIND BUILD_SAMPLE_NAME ${dir} index)
|
|
|
|
|
endif()
|
|
|
|
|
if (index EQUAL -1)
|
|
|
|
|
message(STATUS "${dir} SKIPPED")
|
|
|
|
|
else()
|
|
|
|
|
# Include subdirectory to the project.
|
|
|
|
|
add_subdirectory(${dir})
|
|
|
|
|
endif()
|
2019-01-21 21:31:31 +03:00
|
|
|
endif()
|
|
|
|
|
endif()
|
2019-04-12 18:25:53 +03:00
|
|
|
endforeach()
|
|
|
|
|
endfunction(add_samples_to_build)
|
|
|
|
|
|
2019-08-09 19:02:42 +03:00
|
|
|
include(CMakeParseArguments)
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# ie_add_sample(NAME <target name>
|
|
|
|
|
# SOURCES <source files>
|
|
|
|
|
# [HEADERS <header files>]
|
|
|
|
|
# [INCLUDE_DIRECTORIES <include dir>]
|
|
|
|
|
# [DEPENDENCIES <dependencies>]
|
2021-04-22 14:02:54 +03:00
|
|
|
# [EXCLUDE_CLANG_FORMAT]
|
2019-08-09 19:02:42 +03:00
|
|
|
#
|
|
|
|
|
macro(ie_add_sample)
|
2021-04-22 14:02:54 +03:00
|
|
|
set(options EXCLUDE_CLANG_FORMAT)
|
2019-08-09 19:02:42 +03:00
|
|
|
set(oneValueArgs NAME)
|
2021-11-17 19:47:33 +03:00
|
|
|
set(multiValueArgs SOURCES HEADERS DEPENDENCIES INCLUDE_DIRECTORIES)
|
2019-08-09 19:02:42 +03:00
|
|
|
cmake_parse_arguments(IE_SAMPLE "${options}" "${oneValueArgs}"
|
|
|
|
|
"${multiValueArgs}" ${ARGN} )
|
|
|
|
|
|
|
|
|
|
# Create named folders for the sources within the .vcproj
|
|
|
|
|
# Empty name lists them directly under the .vcproj
|
2021-04-22 14:02:54 +03:00
|
|
|
source_group("src" FILES ${IE_SAMPLE_SOURCES})
|
|
|
|
|
if(IE_SAMPLE_HEADERS)
|
|
|
|
|
source_group("include" FILES ${IE_SAMPLE_HEADERS})
|
2019-08-09 19:02:42 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# Create executable file from sources
|
2021-04-22 14:02:54 +03:00
|
|
|
add_executable(${IE_SAMPLE_NAME} ${IE_SAMPLE_SOURCES} ${IE_SAMPLE_HEADERS})
|
2019-08-09 19:02:42 +03:00
|
|
|
|
2020-04-27 21:21:29 +03:00
|
|
|
set(folder_name cpp_samples)
|
|
|
|
|
if(IE_SAMPLE_NAME MATCHES ".*_c$")
|
2020-09-18 17:13:27 +03:00
|
|
|
set(c_sample ON)
|
2020-04-27 21:21:29 +03:00
|
|
|
set(folder_name c_samples)
|
2019-08-09 19:02:42 +03:00
|
|
|
endif()
|
|
|
|
|
|
2022-08-30 22:23:14 +04:00
|
|
|
# for cross-compilation with gflags
|
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
|
2021-09-10 15:31:27 +03:00
|
|
|
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
|
2021-05-27 16:56:56 +03:00
|
|
|
if(c_sample)
|
2022-08-14 23:51:34 +08:00
|
|
|
set(ov_link_libraries openvino::runtime::c)
|
2021-05-27 16:56:56 +03:00
|
|
|
else()
|
2021-09-10 15:31:27 +03:00
|
|
|
set(ov_link_libraries openvino::runtime)
|
2021-05-27 16:56:56 +03:00
|
|
|
endif()
|
|
|
|
|
|
2020-04-27 21:21:29 +03:00
|
|
|
set_target_properties(${IE_SAMPLE_NAME} PROPERTIES FOLDER ${folder_name}
|
|
|
|
|
COMPILE_PDB_NAME ${IE_SAMPLE_NAME})
|
|
|
|
|
|
2019-08-09 19:02:42 +03:00
|
|
|
if(IE_SAMPLE_INCLUDE_DIRECTORIES)
|
|
|
|
|
target_include_directories(${IE_SAMPLE_NAME} PRIVATE ${IE_SAMPLE_INCLUDE_DIRECTORIES})
|
|
|
|
|
endif()
|
|
|
|
|
target_include_directories(${IE_SAMPLE_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../common")
|
|
|
|
|
|
2022-08-30 22:23:14 +04:00
|
|
|
target_link_libraries(${IE_SAMPLE_NAME} PRIVATE ${ov_link_libraries} Threads::Threads ${IE_SAMPLE_DEPENDENCIES})
|
2020-09-17 13:51:23 +03:00
|
|
|
if(NOT c_sample)
|
2022-10-12 12:16:13 +04:00
|
|
|
target_link_libraries(${IE_SAMPLE_NAME} PRIVATE ${GFLAGS_TARGET})
|
2020-09-17 13:51:23 +03:00
|
|
|
endif()
|
2019-08-09 19:02:42 +03:00
|
|
|
|
2022-04-05 04:47:22 +03:00
|
|
|
install(TARGETS ${IE_SAMPLE_NAME}
|
|
|
|
|
RUNTIME DESTINATION samples_bin/
|
|
|
|
|
COMPONENT samples_bin
|
|
|
|
|
EXCLUDE_FROM_ALL)
|
2021-11-08 14:15:30 +03:00
|
|
|
|
2019-08-09 19:02:42 +03:00
|
|
|
# create global target with all samples / demo apps
|
|
|
|
|
if(NOT TARGET ie_samples)
|
|
|
|
|
add_custom_target(ie_samples ALL)
|
|
|
|
|
endif()
|
|
|
|
|
add_dependencies(ie_samples ${IE_SAMPLE_NAME})
|
|
|
|
|
|
2021-04-22 14:02:54 +03:00
|
|
|
if(COMMAND add_clang_format_target AND NOT IE_SAMPLE_EXCLUDE_CLANG_FORMAT)
|
|
|
|
|
add_clang_format_target(${IE_SAMPLE_NAME}_clang FOR_SOURCES ${IE_SAMPLE_SOURCES} ${IE_SAMPLE_HEADERS})
|
2019-08-09 19:02:42 +03:00
|
|
|
endif()
|
2022-01-19 01:08:07 +03:00
|
|
|
if(COMMAND ov_ncc_naming_style AND NOT c_sample)
|
|
|
|
|
ov_ncc_naming_style(FOR_TARGET "${IE_SAMPLE_NAME}"
|
2022-03-24 22:27:29 +03:00
|
|
|
SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
|
2022-01-19 01:08:07 +03:00
|
|
|
endif()
|
2019-08-09 19:02:42 +03:00
|
|
|
endmacro()
|
|
|
|
|
|
2019-04-12 18:25:53 +03:00
|
|
|
# collect all samples subdirectories
|
|
|
|
|
file(GLOB samples_dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *)
|
|
|
|
|
# skip building of unnecessary subdirectories
|
2020-02-11 22:48:49 +03:00
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty")
|
|
|
|
|
list(REMOVE_ITEM samples_dirs common thirdparty)
|
|
|
|
|
endif()
|
2019-04-12 18:25:53 +03:00
|
|
|
add_samples_to_build(${samples_dirs})
|