77 lines
2.4 KiB
CMake
77 lines
2.4 KiB
CMake
# Copyright (C) 2018-2023 Intel Corporation
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
#------------------------------------------------------------------------------
|
|
# Configure and install libonnx ...
|
|
#------------------------------------------------------------------------------
|
|
|
|
set(OV_ONNX_NAMESPACE openvino_onnx)
|
|
|
|
if(NOT DEFINED ONNX_USE_MSVC_STATIC_RUNTIME)
|
|
set(ONNX_USE_MSVC_STATIC_RUNTIME OFF)
|
|
endif()
|
|
|
|
if(FORCE_FRONTENDS_USE_PROTOBUF)
|
|
set(ONNX_USE_LITE_PROTO_DEFAULT OFF)
|
|
else()
|
|
set(ONNX_USE_LITE_PROTO_DEFAULT ON)
|
|
endif()
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
# 4244 conversion from 'XXX' to 'YYY', possible loss of data
|
|
ie_add_compiler_flags(/wd4244)
|
|
endif()
|
|
|
|
set(ONNX_USE_PROTOBUF_SHARED_LIBS OFF CACHE BOOL "Use dynamic protobuf by ONNX library" FORCE)
|
|
set(ONNX_NAMESPACE ${OV_ONNX_NAMESPACE})
|
|
set(ONNX_USE_LITE_PROTO ${ONNX_USE_LITE_PROTO_DEFAULT} CACHE BOOL "Use protobuf lite for ONNX library" FORCE)
|
|
set(ONNX_ML ON CACHE BOOL "Use ONNX ML" FORCE)
|
|
set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${PROTOC_EXECUTABLE})
|
|
|
|
# clear Python_ADDITIONAL_VERSIONS to find only python library matching PYTHON_EXECUTABLE
|
|
unset(Python_ADDITIONAL_VERSIONS CACHE)
|
|
|
|
# build targets
|
|
|
|
function(ov_onnx_build_static)
|
|
set(BUILD_SHARED_LIBS OFF)
|
|
add_subdirectory(onnx EXCLUDE_FROM_ALL)
|
|
endfunction()
|
|
|
|
ov_onnx_build_static()
|
|
|
|
foreach(_onnx_target onnx onnx_proto)
|
|
target_include_directories(${_onnx_target} SYSTEM PRIVATE
|
|
$<TARGET_PROPERTY:protobuf::libprotobuf,INTERFACE_INCLUDE_DIRECTORIES>)
|
|
endforeach()
|
|
|
|
if(WIN32)
|
|
# from onnx==1.13.1 it requires C++17 when compiling on Windows
|
|
target_compile_features(onnx PRIVATE cxx_std_17)
|
|
# OPTIONAL is a reserved word for mingw at least
|
|
if(MINGW)
|
|
target_compile_definitions(onnx PRIVATE OPTIONAL=OPTIONAL_PLACEHOLDER)
|
|
endif()
|
|
endif()
|
|
|
|
ov_disable_all_warnings(onnx onnx_proto)
|
|
|
|
# install
|
|
|
|
ov_install_static_lib(onnx ${OV_CPACK_COMP_CORE})
|
|
ov_install_static_lib(onnx_proto ${OV_CPACK_COMP_CORE})
|
|
|
|
# WA for ONNX: protobuf must be in the same export set of ONNX targets
|
|
# in case of protobuf::libprotobuf-lite / protobuf::libprotobuf are imported targets
|
|
if(NOT ENABLE_SYSTEM_PROTOBUF)
|
|
if(ONNX_USE_LITE_PROTO)
|
|
set(protobuf_target_name libprotobuf-lite)
|
|
else()
|
|
set(protobuf_target_name libprotobuf)
|
|
endif()
|
|
|
|
install(TARGETS ${protobuf_target_name} EXPORT ONNXTargets
|
|
ARCHIVE DESTINATION ${OV_CPACK_ARCHIVEDIR} COMPONENT ${OV_CPACK_COMP_CORE})
|
|
endif()
|