Skip to content

Commit

Permalink
Trying to re-use OpenVINOConfig.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Sep 10, 2021
1 parent a952540 commit 3bc76c5
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 197 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ message (STATUS "CMAKE_C_COMPILER_ID ................... " ${CMAKE_C_COMPILER_ID
message (STATUS "CMAKE_BUILD_TYPE ...................... " ${CMAKE_BUILD_TYPE})

# remove file with exported developer targets to force its regeneration
file(REMOVE "${CMAKE_BINARY_DIR}/ngraph/ngraphTargets.cmake")
file(REMOVE "${CMAKE_BINARY_DIR}/InferenceEngineTargets.cmake")
file(REMOVE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake")
foreach(component IN LISTS openvino_export_components)
Expand Down
116 changes: 17 additions & 99 deletions cmake/templates/InferenceEngineConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,111 +25,29 @@

@PACKAGE_INIT@

#
# Common functions
#

if(NOT DEFINED CMAKE_FIND_PACKAGE_NAME)
set(CMAKE_FIND_PACKAGE_NAME InferenceEngine)
set(_need_package_name_reset ON)
set(_ie_need_package_name_reset ON)
endif()

# we have to use our own version of find_dependency because of support cmake 3.7
macro(_ie_find_dependency dep)
set(cmake_fd_quiet_arg)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
set(cmake_fd_quiet_arg QUIET)
endif()
set(cmake_fd_required_arg)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
set(cmake_fd_required_arg REQUIRED)
endif()

get_property(cmake_fd_alreadyTransitive GLOBAL PROPERTY
_CMAKE_${dep}_TRANSITIVE_DEPENDENCY)

find_package(${dep} ${ARGN}
${cmake_fd_quiet_arg}
${cmake_fd_required_arg})
include(CMakeFindDependencyMacro)

if(NOT DEFINED cmake_fd_alreadyTransitive OR cmake_fd_alreadyTransitive)
set_property(GLOBAL PROPERTY _CMAKE_${dep}_TRANSITIVE_DEPENDENCY TRUE)
endif()

if(NOT ${dep}_FOUND)
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "${CMAKE_FIND_PACKAGE_NAME} could not be found because dependency ${dep} could not be found.")
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
return()
endif()

set(cmake_fd_required_arg)
set(cmake_fd_quiet_arg)
endmacro()

function(_ie_target_no_deprecation_error)
if(NOT MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(flags "-diag-warning=1786")
else()
set(flags "-Wno-error=deprecated-declarations")
endif()
if(CMAKE_CROSSCOMPILING)
set_target_properties(${ARGV} PROPERTIES
INTERFACE_LINK_OPTIONS "-Wl,--allow-shlib-undefined")
endif()
find_dependency(OpenVINO
PATHS "${CMAKE_CURRENT_LIST_DIR}"
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)

set_target_properties(${ARGV} PROPERTIES INTERFACE_COMPILE_OPTIONS ${flags})
endif()
endfunction()

#
# Inference Engine config
#

# need to store current PACKAGE_PREFIX_DIR, because it's overwritten by ngraph one
set(IE_PACKAGE_PREFIX_DIR "${PACKAGE_PREFIX_DIR}")

set(THREADING "@THREADING@")
if(THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO" AND NOT TBB_FOUND)
set_and_check(_tbb_dir "@PACKAGE_IE_TBB_DIR@")
_ie_find_dependency(TBB
COMPONENTS tbb tbbmalloc
CONFIG
PATHS ${TBBROOT}/cmake
${_tbb_dir}
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)
# create targets with old names for compatibility
if(TARGET openvino::runtime AND NOT TARGET IE::inference_engine)
add_library(IE::inference_engine INTERFACE IMPORTED)
set_target_properties(IE::inference_engine PROPERTIES
INTERFACE_LINK_LIBRARIES openvino::runtime)
endif()

set_and_check(_ngraph_dir "@PACKAGE_IE_NGRAPH_DIR@")
_ie_find_dependency(ngraph
CONFIG
PATHS ${_ngraph_dir}
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)

if(NOT TARGET inference_engine)
set(_ie_as_external_package ON)
include("${CMAKE_CURRENT_LIST_DIR}/InferenceEngineTargets.cmake")

# create targets with old names for compatibility
if(TARGET IE::runtime AND NOT TARGET IE::inference_engine)
add_library(IE::inference_engine INTERFACE IMPORTED)
set_target_properties(IE::inference_engine PROPERTIES
INTERFACE_LINK_LIBRARIES IE::runtime)
endif()

if(TARGET IE::core AND NOT TARGET ngraph::ngraph)
add_library(IE::ngraph INTERFACE IMPORTED)
set_target_properties(IE::ngraph PROPERTIES
INTERFACE_LINK_LIBRARIES IE::core)
endif()

if(TARGET IE::runtime::c AND NOT TARGET IE::inference_engine_c_api)
add_library(IE::inference_engine_c_api INTERFACE IMPORTED)
set_target_properties(IE::inference_engine_c_api PROPERTIES
INTERFACE_LINK_LIBRARIES IE::runtime::c)
endif()
if(TARGET openvino::runtime::c AND NOT TARGET IE::inference_engine_c_api)
add_library(IE::inference_engine_c_api INTERFACE IMPORTED)
set_target_properties(IE::inference_engine_c_api PROPERTIES
INTERFACE_LINK_LIBRARIES openvino::runtime::c)
endif()

# mark components as available
Expand Down Expand Up @@ -167,7 +85,7 @@ set_and_check(InferenceEngine_INCLUDE_DIRS "@PACKAGE_IE_INCLUDE_DIR@")

check_required_components(${CMAKE_FIND_PACKAGE_NAME})

if(_need_package_name_reset)
if(_ie_need_package_name_reset)
unset(CMAKE_FIND_PACKAGE_NAME)
unset(_need_package_name_reset)
unset(_ie_need_package_name_reset)
endif()
16 changes: 12 additions & 4 deletions cmake/templates/InferenceEngineDeveloperPackageConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ find_dependency(InferenceEngine
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)

find_dependency(OpenVINO
PATHS "${CMAKE_CURRENT_LIST_DIR}"
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)
# create targets with old names for compatibility
if(TARGET openvino::core AND NOT TARGET IE::core)
add_library(IE::core INTERFACE IMPORTED)
set_target_properties(IE::core PROPERTIES
INTERFACE_LINK_LIBRARIES openvino::core)
endif()

if(TARGET openvino::runtime AND NOT TARGET IE::runtime)
add_library(IE::runtime INTERFACE IMPORTED)
set_target_properties(IE::runtime PROPERTIES
INTERFACE_LINK_LIBRARIES openvino::runtime)
endif()

# WA for cmake: it exports ngraph as IE::ngraph in the IE export list
# while we already have ngraph export in its own export list as ngraph::ngraph
Expand Down
56 changes: 30 additions & 26 deletions cmake/templates/ngraphConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,45 @@

@PACKAGE_INIT@

if(NOT TARGET ngraph)
include("${CMAKE_CURRENT_LIST_DIR}/ngraphTargets.cmake")
include(CMakeFindDependencyMacro)

# create targets with old names for compatibility
if(TARGET ngraph::core AND NOT TARGET ngraph::ngraph)
add_library(ngraph::ngraph INTERFACE IMPORTED)
set_target_properties(ngraph::ngraph PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::core)
endif()
find_dependency(OpenVINO
PATHS "${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_CURRENT_LIST_DIR}/ngraph"
NO_CMAKE_FIND_ROOT_PATH
NO_DEFAULT_PATH)

if(TARGET ngraph::frontend::manager AND NOT TARGET ngraph::frontend_manager)
add_library(ngraph::frontend_manager INTERFACE IMPORTED)
set_target_properties(ngraph::frontend_manager PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::frontend::manager)
endif()
# create targets with old names for compatibility
if(TARGET openvino::core AND NOT TARGET ngraph::ngraph)
add_library(ngraph::ngraph INTERFACE IMPORTED)
set_target_properties(ngraph::ngraph PROPERTIES
INTERFACE_LINK_LIBRARIES openvino::core)
endif()

if(TARGET ngraph::frontend::onnx AND NOT TARGET ngraph::onnx_ngraph_frontend)
add_library(ngraph::onnx_ngraph_frontend INTERFACE IMPORTED)
set_target_properties(ngraph::onnx_ngraph_frontend PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::frontend::onnx)
endif()
if(TARGET openvino::frontend::manager AND NOT TARGET ngraph::frontend_manager)
add_library(ngraph::frontend_manager INTERFACE IMPORTED)
set_target_properties(ngraph::frontend_manager PROPERTIES
INTERFACE_LINK_LIBRARIES openvino::frontend::manager)
endif()

if(TARGET ngraph::frontend::paddlepaddle AND NOT TARGET ngraph::paddlepaddle_ngraph_frontend)
add_library(ngraph::paddlepaddle_ngraph_frontend INTERFACE IMPORTED)
set_target_properties(ngraph::paddlepaddle_ngraph_frontend PROPERTIES
INTERFACE_LINK_LIBRARIES ngraph::frontend::paddlepaddle)
endif()
if(TARGET openvino::frontend::onnx AND NOT TARGET ngraph::onnx_ngraph_frontend)
add_library(ngraph::onnx_ngraph_frontend INTERFACE IMPORTED)
set_target_properties(ngraph::onnx_ngraph_frontend PROPERTIES
INTERFACE_LINK_LIBRARIES openvino::frontend::onnx)
endif()

if(TARGET openvino::frontend::paddlepaddle AND NOT TARGET ngraph::paddlepaddle_ngraph_frontend)
add_library(ngraph::paddlepaddle_ngraph_frontend INTERFACE IMPORTED)
set_target_properties(ngraph::paddlepaddle_ngraph_frontend PROPERTIES
INTERFACE_LINK_LIBRARIES openvino::frontend::paddlepaddle)
endif()

set(ngraph_ngraph_FOUND ON)
set(NGRAPH_LIBRARIES ngraph::ngraph)

set(ngraph_onnx_ngraph_frontend_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@)
set(ngraph_onnx_ngraph_frontend_FOUND ${OpenVINO_Frontend_ONNX_FOUND})
set(ngraph_onnx_importer_FOUND ${OpenVINO_Frontend_ONNX_FOUND})

set(ngraph_onnx_importer_FOUND @NGRAPH_ONNX_FRONTEND_ENABLE@)
if(ngraph_onnx_importer_FOUND)
set(ONNX_IMPORTER_LIBRARIES ngraph::onnx_ngraph_frontend)
# ngraph::onnx_importer target and variables are deprecated
Expand All @@ -83,6 +87,6 @@ if(ngraph_onnx_importer_FOUND)
endif()
endif()

set(ngraph_paddlepaddle_frontend_FOUND @NGRAPH_PDPD_FRONTEND_ENABLE@)
set(ngraph_paddlepaddle_frontend_FOUND ${OpenVINO_Frontend_PaddlePaddle_FOUND})

check_required_components(ngraph)
9 changes: 0 additions & 9 deletions inference-engine/ie_bridges/c/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ ie_add_vs_version_file(NAME ${TARGET_NAME}

# export

export(TARGETS ${TARGET_NAME} NAMESPACE IE::
APPEND FILE "${CMAKE_BINARY_DIR}/InferenceEngineTargets.cmake")

set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME runtime::c)
export(TARGETS ${TARGET_NAME} NAMESPACE openvino::
APPEND FILE "${CMAKE_BINARY_DIR}/OpenVINOTargets.cmake")
Expand All @@ -38,12 +35,6 @@ export(TARGETS ${TARGET_NAME} NAMESPACE openvino::
ie_cpack_add_component(core_c DEPENDS core)
ie_cpack_add_component(core_c_dev DEPENDS core_c)

install(TARGETS ${TARGET_NAME} EXPORT InferenceEngineTargets
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT core_c
ARCHIVE DESTINATION ${IE_CPACK_ARCHIVE_PATH} COMPONENT core_c
LIBRARY DESTINATION ${IE_CPACK_LIBRARY_PATH} COMPONENT core_c
INCLUDES DESTINATION ${IE_CPACK_IE_DIR}/include/ie)

install(TARGETS ${TARGET_NAME} EXPORT OpenVINOTargets
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT core_c
ARCHIVE DESTINATION ${IE_CPACK_ARCHIVE_PATH} COMPONENT core_c
Expand Down
12 changes: 0 additions & 12 deletions inference-engine/src/inference_engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,6 @@ ie_cpack_add_component(core_dev REQUIRED core ngraph_dev)
install(DIRECTORY "${PUBLIC_HEADERS_DIR}" DESTINATION ${IE_CPACK_IE_DIR}
COMPONENT core_dev)

install(TARGETS ${TARGET_NAME} EXPORT InferenceEngineTargets
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT core
ARCHIVE DESTINATION ${IE_CPACK_ARCHIVE_PATH} COMPONENT core
LIBRARY DESTINATION ${IE_CPACK_LIBRARY_PATH} COMPONENT core
INCLUDES DESTINATION ${IE_CPACK_IE_DIR}/include/ie)

set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME runtime)
install(TARGETS ${TARGET_NAME} EXPORT OpenVINOTargets
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT core
Expand All @@ -311,12 +305,6 @@ endif()

# Install cmake scripts

install(EXPORT InferenceEngineTargets
FILE InferenceEngineTargets.cmake
NAMESPACE IE::
DESTINATION ${IE_CPACK_IE_DIR}/share
COMPONENT core_dev)

install(EXPORT OpenVINOTargets
FILE OpenVINOTargets.cmake
NAMESPACE openvino::
Expand Down
12 changes: 0 additions & 12 deletions inference-engine/src/transformations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,7 @@ openvino_developer_export_targets(COMPONENT inference_engine TARGETS ${TARGET_NA

# install

install(TARGETS ${TARGET_NAME} EXPORT InferenceEngineTargets
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT core
ARCHIVE DESTINATION ${IE_CPACK_ARCHIVE_PATH} COMPONENT core
LIBRARY DESTINATION ${IE_CPACK_LIBRARY_PATH} COMPONENT core)

install(TARGETS ${TARGET_NAME} EXPORT OpenVINOTargets
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT core
ARCHIVE DESTINATION ${IE_CPACK_ARCHIVE_PATH} COMPONENT core
LIBRARY DESTINATION ${IE_CPACK_LIBRARY_PATH} COMPONENT core)

# because inference_engine_transformations is exported in multiple export list
# it needs to be exported in each list it's used
install(TARGETS ${TARGET_NAME} EXPORT ngraphTargets
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT core
ARCHIVE DESTINATION ${IE_CPACK_ARCHIVE_PATH} COMPONENT core
LIBRARY DESTINATION ${IE_CPACK_LIBRARY_PATH} COMPONENT core)
20 changes: 0 additions & 20 deletions ngraph/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,6 @@ export(TARGETS ngraph NAMESPACE openvino::
# Installation logic...
#-----------------------------------------------------------------------------------------------

install(TARGETS ngraph EXPORT ngraphTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
INCLUDES DESTINATION ${NGRAPH_INSTALL_INCLUDE})

# because ngraph is exported in multiple export list
# it needs to be exported in each list it's used
install(TARGETS ngraph EXPORT InferenceEngineTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
INCLUDES DESTINATION ${NGRAPH_INSTALL_INCLUDE})

install(TARGETS ngraph EXPORT OpenVINOTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
Expand All @@ -130,12 +116,6 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/ngraph/version.hpp
DESTINATION ${NGRAPH_INSTALL_INCLUDE}/ngraph
COMPONENT ngraph_dev)

install(EXPORT ngraphTargets
FILE ngraphTargets.cmake
NAMESPACE ngraph::
DESTINATION "deployment_tools/ngraph/cmake"
COMPONENT ngraph_dev)

configure_package_config_file(${OpenVINO_SOURCE_DIR}/cmake/templates/ngraphConfig.cmake.in
${ngraph_BINARY_DIR}/ngraphConfig.cmake
INSTALL_DESTINATION cmake)
Expand Down
5 changes: 0 additions & 5 deletions ngraph/frontend/frontend_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ endif()

# Installation rules for shared version only

install(TARGETS ${TARGET_NAME} EXPORT ngraphTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph)

set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME frontend::manager)
install(TARGETS ${TARGET_NAME} EXPORT OpenVINOTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
Expand Down
5 changes: 0 additions & 5 deletions ngraph/frontend/onnx/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ if(NGRAPH_USE_PROTOBUF_LITE)
target_compile_definitions(${TARGET_NAME} PRIVATE NGRAPH_USE_PROTOBUF_LITE)
endif()

install(TARGETS ${TARGET_NAME} EXPORT ngraphTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph)

set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME frontend::onnx)
install(TARGETS ${TARGET_NAME} EXPORT OpenVINOTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
Expand Down
5 changes: 0 additions & 5 deletions ngraph/frontend/paddlepaddle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ target_link_libraries(${TARGET_NAME} PRIVATE frontend_manager::static
add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME}
EXCLUDE_PATTERNS ${PROTO_SRCS} ${PROTO_HDRS})

install(TARGETS ${TARGET_NAME} EXPORT ngraphTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
ARCHIVE DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
LIBRARY DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph)

set_target_properties(${TARGET_NAME} PROPERTIES EXPORT_NAME frontend::paddlepaddle)
install(TARGETS ${TARGET_NAME} EXPORT OpenVINOTargets
RUNTIME DESTINATION ${NGRAPH_INSTALL_LIB} COMPONENT ngraph
Expand Down

0 comments on commit 3bc76c5

Please sign in to comment.