Files
openvino/cmake/developer_package/add_ie_target.cmake

178 lines
6.3 KiB
CMake
Raw Normal View History

# Copyright (C) 2018-2023 Intel Corporation
2020-02-11 22:48:49 +03:00
# SPDX-License-Identifier: Apache-2.0
#
#[[
function to create CMake target and setup its options in a declarative style.
Example:
addIeTarget(
NAME core_lib
2020-04-13 21:17:23 +03:00
ADD_CPPLINT
DEVELOPER_PACKAGE <component>
TYPE <SHARED / STATIC / EXECUTABLE>
2020-02-11 22:48:49 +03:00
ROOT ${CMAKE_CURRENT_SOURCE_DIR}
2020-04-13 21:17:23 +03:00
ADDITIONAL_SOURCE_DIRS
/some/additional/sources
Tests and docs for registering custom ONNX operators (#2416) * Add tests, examples and documentation changes for custom ONNX operators registration mechanism * Change snippet paths * fix CoreThreadingTests.ReadNetwork - data race in ops_bridge * Make TemplateExtension::Operation externally visible * changes after review * apply code format * use std::int64_t * forward declare get_attribute_value specializations * introduce unregister_operator in onnx_importer * onnx_custom_op - lock mem first then take a buffer * func tests - create template_extension via make_so_pointer * fix build with NGRAPH_ONNX_IMPORT_ENABLE=OFF * remove exports from Operation and Extension * Move multithreaded AddExtension test to different directory to it can be excluded when NGRAPH_ONNX_IMPORT_ENABLE=OFF * Dont include Extension tests if ENABLE_MKL_DNN=OFF * fix excluding onnx_reader tests * include extension tests only if mkl is enabled * add comment on empty blob * use register_operator conditionally in template_extension * fix docs after review * create static library from onnx_custom_op * add additional test for unregister_operator * move model example after register step * revert changes to unit tests * update ngraphConfig.cmake.in header * add headers to onnx_custom_op * changes to docs CMakeLists * remove redundant onnx_importer dependency * remove extension directory from func tests * make onnx_importer a component of ngraph package * docs fixes * update header of ngraph/cmake/share/ngraphConfig.cmake.in with ngraph_onnx_importer_FOUND
2020-10-12 06:36:19 +02:00
EXCLUDED_SOURCE_PATHS
2020-04-13 21:17:23 +03:00
${CMAKE_CURRENT_SOURCE_DIR}/unnecessary_sources/
2020-02-11 22:48:49 +03:00
INCLUDES
${SDL_INCLUDES}
/some/specific/path
LINK_LIBRARIES
link_dependencies
2020-04-13 21:17:23 +03:00
DEPENDENCIES
dependencies
ie::important_plugin
2020-04-13 21:17:23 +03:00
OBJECT_FILES
object libraries
2020-02-11 22:48:49 +03:00
)
#]]
function(addIeTarget)
set(options
2020-04-13 21:17:23 +03:00
ADD_CPPLINT # Enables code style checks for the target
ADD_CLANG_FORMAT # Enables code style checks for the target
2020-02-11 22:48:49 +03:00
)
set(oneValueRequiredArgs
2020-04-13 21:17:23 +03:00
TYPE # type of target, SHARED|STATIC|EXECUTABLE. SHARED and STATIC correspond to add_library, EXECUTABLE to add_executable
2020-02-11 22:48:49 +03:00
NAME # name of target
2020-04-13 21:17:23 +03:00
ROOT # root directory to be used for recursive search of source files
2020-02-11 22:48:49 +03:00
)
set(oneValueOptionalArgs
DEVELOPER_PACKAGE # Enables exporting of the target through the developer package
2020-02-11 22:48:49 +03:00
)
set(multiValueArgs
2020-04-13 21:17:23 +03:00
INCLUDES # Extra include directories
LINK_LIBRARIES # Link libraries (in form of target name or file name)
DEPENDENCIES # compile order dependencies (no link implied)
DEFINES # extra preprocessor definitions
ADDITIONAL_SOURCE_DIRS # list of directories which will be used to recursive search of source files in addition to ROOT
OBJECT_FILES # list of object files to be additionally built into the target
Tests and docs for registering custom ONNX operators (#2416) * Add tests, examples and documentation changes for custom ONNX operators registration mechanism * Change snippet paths * fix CoreThreadingTests.ReadNetwork - data race in ops_bridge * Make TemplateExtension::Operation externally visible * changes after review * apply code format * use std::int64_t * forward declare get_attribute_value specializations * introduce unregister_operator in onnx_importer * onnx_custom_op - lock mem first then take a buffer * func tests - create template_extension via make_so_pointer * fix build with NGRAPH_ONNX_IMPORT_ENABLE=OFF * remove exports from Operation and Extension * Move multithreaded AddExtension test to different directory to it can be excluded when NGRAPH_ONNX_IMPORT_ENABLE=OFF * Dont include Extension tests if ENABLE_MKL_DNN=OFF * fix excluding onnx_reader tests * include extension tests only if mkl is enabled * add comment on empty blob * use register_operator conditionally in template_extension * fix docs after review * create static library from onnx_custom_op * add additional test for unregister_operator * move model example after register step * revert changes to unit tests * update ngraphConfig.cmake.in header * add headers to onnx_custom_op * changes to docs CMakeLists * remove redundant onnx_importer dependency * remove extension directory from func tests * make onnx_importer a component of ngraph package * docs fixes * update header of ngraph/cmake/share/ngraphConfig.cmake.in with ngraph_onnx_importer_FOUND
2020-10-12 06:36:19 +02:00
EXCLUDED_SOURCE_PATHS # list of paths excluded from the global recursive search of source files
2020-04-13 21:17:23 +03:00
LINK_LIBRARIES_WHOLE_ARCHIVE # list of static libraries to link, each object file should be used and not discarded
LINK_FLAGS # list of extra commands to linker
2020-02-11 22:48:49 +03:00
)
cmake_parse_arguments(ARG "${options}" "${oneValueRequiredArgs};${oneValueOptionalArgs}" "${multiValueArgs}" ${ARGN} )
# sanity checks
foreach(argName ${oneValueRequiredArgs})
if (NOT ARG_${argName})
message(SEND_ERROR "Argument '${argName}' is required.")
endif()
endforeach()
if (ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Unexpected parameters have passed to function: ${ARG_UNPARSED_ARGUMENTS}")
endif()
# adding files to target
set(includeSearch)
set(sourceSearch)
foreach(directory ${ARG_ROOT} ${ARG_ADDITIONAL_SOURCE_DIRS})
list(APPEND includeSearch ${directory}/*.h ${directory}/*.hpp)
list(APPEND sourceSearch ${directory}/*.cpp)
endforeach()
file(GLOB_RECURSE includes ${includeSearch})
file(GLOB_RECURSE sources ${sourceSearch})
2020-04-13 21:17:23 +03:00
# remove unnecessary directories
Tests and docs for registering custom ONNX operators (#2416) * Add tests, examples and documentation changes for custom ONNX operators registration mechanism * Change snippet paths * fix CoreThreadingTests.ReadNetwork - data race in ops_bridge * Make TemplateExtension::Operation externally visible * changes after review * apply code format * use std::int64_t * forward declare get_attribute_value specializations * introduce unregister_operator in onnx_importer * onnx_custom_op - lock mem first then take a buffer * func tests - create template_extension via make_so_pointer * fix build with NGRAPH_ONNX_IMPORT_ENABLE=OFF * remove exports from Operation and Extension * Move multithreaded AddExtension test to different directory to it can be excluded when NGRAPH_ONNX_IMPORT_ENABLE=OFF * Dont include Extension tests if ENABLE_MKL_DNN=OFF * fix excluding onnx_reader tests * include extension tests only if mkl is enabled * add comment on empty blob * use register_operator conditionally in template_extension * fix docs after review * create static library from onnx_custom_op * add additional test for unregister_operator * move model example after register step * revert changes to unit tests * update ngraphConfig.cmake.in header * add headers to onnx_custom_op * changes to docs CMakeLists * remove redundant onnx_importer dependency * remove extension directory from func tests * make onnx_importer a component of ngraph package * docs fixes * update header of ngraph/cmake/share/ngraphConfig.cmake.in with ngraph_onnx_importer_FOUND
2020-10-12 06:36:19 +02:00
foreach(excludedDir ${ARG_EXCLUDED_SOURCE_PATHS})
list(FILTER includes EXCLUDE REGEX "${excludedDir}.*")
list(FILTER sources EXCLUDE REGEX "${excludedDir}.*")
Tests and docs for registering custom ONNX operators (#2416) * Add tests, examples and documentation changes for custom ONNX operators registration mechanism * Change snippet paths * fix CoreThreadingTests.ReadNetwork - data race in ops_bridge * Make TemplateExtension::Operation externally visible * changes after review * apply code format * use std::int64_t * forward declare get_attribute_value specializations * introduce unregister_operator in onnx_importer * onnx_custom_op - lock mem first then take a buffer * func tests - create template_extension via make_so_pointer * fix build with NGRAPH_ONNX_IMPORT_ENABLE=OFF * remove exports from Operation and Extension * Move multithreaded AddExtension test to different directory to it can be excluded when NGRAPH_ONNX_IMPORT_ENABLE=OFF * Dont include Extension tests if ENABLE_MKL_DNN=OFF * fix excluding onnx_reader tests * include extension tests only if mkl is enabled * add comment on empty blob * use register_operator conditionally in template_extension * fix docs after review * create static library from onnx_custom_op * add additional test for unregister_operator * move model example after register step * revert changes to unit tests * update ngraphConfig.cmake.in header * add headers to onnx_custom_op * changes to docs CMakeLists * remove redundant onnx_importer dependency * remove extension directory from func tests * make onnx_importer a component of ngraph package * docs fixes * update header of ngraph/cmake/share/ngraphConfig.cmake.in with ngraph_onnx_importer_FOUND
2020-10-12 06:36:19 +02:00
endforeach()
2020-04-13 21:17:23 +03:00
2020-02-11 22:48:49 +03:00
source_group("include" FILES ${includes})
source_group("src" FILES ${sources})
2020-04-13 21:17:23 +03:00
set(all_sources)
list(APPEND all_sources ${sources} ${includes} ${ARG_OBJECT_FILES})
2020-02-11 22:48:49 +03:00
# defining a target
2020-04-13 21:17:23 +03:00
if (ARG_TYPE STREQUAL EXECUTABLE)
add_executable(${ARG_NAME} ${all_sources})
elseif(ARG_TYPE STREQUAL STATIC OR ARG_TYPE STREQUAL SHARED)
add_library(${ARG_NAME} ${ARG_TYPE} ${all_sources})
2020-02-11 22:48:49 +03:00
else()
2020-04-13 21:17:23 +03:00
message(SEND_ERROR "Invalid target type ${ARG_TYPE} specified for target name ${ARG_NAME}")
2020-02-11 22:48:49 +03:00
endif()
2020-04-13 21:17:23 +03:00
ieTargetLinkWholeArchive(${ARG_NAME} ${ARG_LINK_LIBRARIES_WHOLE_ARCHIVE})
2020-02-11 22:48:49 +03:00
if (ARG_DEFINES)
target_compile_definitions(${ARG_NAME} PRIVATE ${ARG_DEFINES})
endif()
if (ARG_INCLUDES)
target_include_directories(${ARG_NAME} PRIVATE ${ARG_INCLUDES})
endif()
if (ARG_LINK_LIBRARIES)
target_link_libraries(${ARG_NAME} PRIVATE ${ARG_LINK_LIBRARIES})
endif()
if (ARG_DEPENDENCIES)
add_dependencies(${ARG_NAME} ${ARG_DEPENDENCIES})
endif()
2020-04-13 21:17:23 +03:00
if (ARG_LINK_FLAGS)
get_target_property(oldLinkFlags ${ARG_NAME} LINK_FLAGS)
string(REPLACE ";" " " ARG_LINK_FLAGS "${ARG_LINK_FLAGS}")
set_target_properties(${ARG_NAME} PROPERTIES LINK_FLAGS "${oldLinkFlags} ${ARG_LINK_FLAGS}")
endif()
if (ARG_ADD_CPPLINT)
# code style
add_cpplint_target(${ARG_NAME}_cpplint FOR_TARGETS ${ARG_NAME})
endif()
if (ARG_ADD_CLANG_FORMAT)
# code style
add_clang_format_target(${ARG_NAME}_clang FOR_TARGETS ${ARG_NAME})
endif()
2020-04-13 21:17:23 +03:00
if (ARG_DEVELOPER_PACKAGE)
# developer package
openvino_developer_export_targets(COMPONENT ${ARG_DEVELOPER_PACKAGE}
TARGETS ${ARG_NAME})
2020-04-13 21:17:23 +03:00
endif()
if(WIN32)
# Provide default compile pdb name equal to target name
set_target_properties(${ARG_NAME} PROPERTIES COMPILE_PDB_NAME ${ARG_NAME})
endif()
2020-02-11 22:48:49 +03:00
endfunction()
function(ov_add_target)
addIeTarget(${ARGV})
endfunction()
2020-02-11 22:48:49 +03:00
#[[
Wrapper function over addIeTarget, that also adds a test with the same name.
You could use
addIeTargetTest( ... LABELS labelOne labelTwo )
also to provide labels for that test.
Important: you MUST pass LABELS as last argument, otherwise it will consume any parameters that come after.
#]]
function(addIeTargetTest)
set(options
)
set(oneValueRequiredArgs
NAME
)
set(oneValueOptionalArgs
COMPONENT
2020-02-11 22:48:49 +03:00
)
set(multiValueArgs
LABELS
)
cmake_parse_arguments(ARG "${options}" "${oneValueRequiredArgs};${oneValueOptionalArgs}" "${multiValueArgs}" ${ARGN} )
if (NOT DEFINED ARG_COMPONENT)
set(ARG_COMPONENT tests)
endif()
2020-02-11 22:48:49 +03:00
2020-04-13 21:17:23 +03:00
addIeTarget(TYPE EXECUTABLE NAME ${ARG_NAME} ${ARG_UNPARSED_ARGUMENTS})
2020-02-11 22:48:49 +03:00
add_test(NAME ${ARG_NAME} COMMAND ${ARG_NAME})
set_property(TEST ${ARG_NAME} PROPERTY LABELS ${ARG_LABELS})
install(TARGETS ${ARG_NAME}
RUNTIME DESTINATION tests
COMPONENT ${ARG_COMPONENT}
EXCLUDE_FROM_ALL)
2020-02-11 22:48:49 +03:00
endfunction()
function(ov_add_test_target)
addIeTargetTest(${ARGV})
endfunction()