Build Plugin Using CMake¶
OpenVINO build infrastructure provides the OpenVINO Developer Package for plugin development.
OpenVINO Developer Package¶
To automatically generate the OpenVINO Developer Package, run the cmake
tool during a OpenVINO build:
$ mkdir openvino-release-build
$ cd openvino-release-build
$ cmake -DCMAKE_BUILD_TYPE=Release ../openvino
Once the commands above are executed, the OpenVINO Developer Package is generated in the openvino-release-build
folder. It consists of several files:
OpenVINODeveloperPackageConfig.cmake
- the main CMake script which imports targets and provides compilation flags and CMake options.OpenVINODeveloperPackageConfig-version.cmake
- a file with a package version.targets_developer.cmake
- an automatically generated file which contains all targets exported from the OpenVINO build tree. This file is included byOpenVINODeveloperPackageConfig.cmake
to import the following targets:Libraries for plugin development:
openvino::ngraph
- shared OpenVINO libraryopenvino::openvino_gapi_preproc
- shared library with OpenVINO preprocessing pluginopenvino::core::dev
- interface library with OpenVINO Core development headersopenvino::runtime::dev
- interface library with OpenVINO Plugin API headersopenvino::pugixml
- static Pugixml libraryopenvino::xbyak
- interface library with Xbyak headersopenvino::itt
- static library with tools for performance measurement using Intel ITT
Libraries for tests development:
IE::gtest
,IE::gtest_main
,IE::gmock
- Google Tests framework librariesIE::commonTestUtils
- static library with common tests utilitiesIE::funcTestUtils
- static library with functional tests utilitiesIE::unitTestUtils
- static library with unit tests utilitiesIE::ngraphFunctions
- static library with the set ofngraph::Function
buildersIE::funcSharedTests
- static library with common functional testsopenvino::gtest
,openvino::gtest_main
,openvino::gmock
- Google Tests framework librariesopenvino::commonTestUtils
- static library with common tests utilitiesopenvino::funcTestUtils
- static library with functional tests utilitiesopenvino::unitTestUtils
- static library with unit tests utilitiesopenvino::ngraphFunctions
- static library with the set ofov::Model
buildersopenvino::funcSharedTests
- static library with common functional tests
Note
it’s enough just to run cmake --build . --target ie_dev_targets
command to build only targets from the OpenVINO Developer package.
Build Plugin using OpenVINO Developer Package¶
To build a plugin source tree using the OpenVINO Developer Package, run the commands below:
$ mkdir template-plugin-release-build
$ cd template-plugin-release-build
$ cmake -DOpenVINODeveloperPackage_DIR=../openvino-release-build ../template-plugin
A common plugin consists of the following components:
Plugin code in the
src
folderCode of tests in the
tests
folder
To build a plugin and its tests, run the following CMake scripts:
Root
CMakeLists.txt
, which finds the OpenVINO Developer Package using thefind_package
CMake command and adds thesrc
andtests
subdirectories with plugin sources and their tests respectively:
cmake_minimum_required(VERSION 3.13)
project(OpenVINOTemplatePlugin)
set(TEMPLATE_PLUGIN_SOURCE_DIR ${OpenVINOTemplatePlugin_SOURCE_DIR})
find_package(OpenVINODeveloperPackage REQUIRED)
if(CMAKE_COMPILER_IS_GNUCXX)
ov_add_compiler_flags(-Wall)
endif()
add_subdirectory(src)
if(ENABLE_TESTS)
include(CTest)
enable_testing()
if(ENABLE_FUNCTIONAL_TESTS)
add_subdirectory(tests/functional)
endif()
endif()
Note
The default values of the ENABLE_TESTS
, ENABLE_FUNCTIONAL_TESTS
options are shared via the OpenVINO Developer Package and they are the same as for the main OpenVINO build tree. You can override them during plugin build using the command below:
$ cmake -DENABLE_FUNCTIONAL_TESTS=OFF -DOpenVINODeveloperPackage_DIR=../openvino-release-build ../template-plugin
src/CMakeLists.txt
to build a plugin shared library from sources:set(TARGET_NAME "openvino_template_plugin") file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/\*.cpp) file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/\*.hpp) if (NOT ENABLE_TEMPLATE_REGISTRATION) # Skip install and registration of template component set(skip_plugin SKIP_INSTALL SKIP_REGISTRATION) endif() # adds a shared library with plugin ov_add_plugin(NAME ${TARGET_NAME} DEVICE_NAME "TEMPLATE" SOURCES ${SOURCES} ${HEADERS} ${skip_plugin} VERSION_DEFINES_FOR template_plugin.cpp ADD_CLANG_FORMAT) # Enable support of CC for the plugin ov_mark_target_as_cc(${TARGET_NAME}) target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${TEMPLATE_PLUGIN_SOURCE_DIR}/include") # link common Inference Engine libraries target_link_libraries(${TARGET_NAME} PRIVATE openvino::interpreter_backend openvino::ngraph_reference) set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO}) if (ENABLE_TEMPLATE_REGISTRATION) # Update the plugins.xml file ov_register_plugins(MAIN_TARGET ${TARGET_NAME}) endif()
Note
openvino::runtime
target is imported from the OpenVINO Developer Package.tests/functional/CMakeLists.txt
to build a set of functional plugin tests:set(TARGET_NAME ov_template_func_tests) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") ie_add_compiler_flags(/wd4305) endif() ov_add_test_target( NAME ${TARGET_NAME} ROOT ${CMAKE_CURRENT_SOURCE_DIR} DEPENDENCIES openvino_template_plugin LINK_LIBRARIES openvino::funcSharedTests openvino::runtime::dev INCLUDES "${TEMPLATE_PLUGIN_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/op_reference" # ADD_CPPLINT LABELS TEMPLATE ) find_package(OpenCV QUIET COMPONENTS core imgproc) if(OpenCV_FOUND) message("-- Reference preprocessing: OpenCV tests are enabled") target_compile_definitions(${TARGET_NAME} PRIVATE OPENCV_TEMPLATE_TESTS) target_link_libraries(${TARGET_NAME} PRIVATE opencv_imgproc opencv_core) else() message("-- Reference preprocessing: OpenCV tests are disabled") endif()
Note
The
openvino::funcSharedTests
static library with common functional OpenVINO Plugin tests is imported via the OpenVINO Developer Package.