Skip to content

Commit

Permalink
Allow to find protobuf via MODULE (#18395)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov authored Jul 6, 2023
1 parent d864d89 commit 14292b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cmake/templates/OpenVINOConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,11 @@ endmacro()

macro(_ov_find_protobuf_frontend_dependency)
set(_OV_ENABLE_SYSTEM_PROTOBUF "@ENABLE_SYSTEM_PROTOBUF@")
set(_OV_PROTOBUF_PACKAGE_CONFIG "@protobuf_config@")
if(_OV_ENABLE_SYSTEM_PROTOBUF)
_ov_find_dependency(Protobuf @Protobuf_VERSION@ EXACT NAMES Protobuf protobuf)
_ov_find_dependency(Protobuf @Protobuf_VERSION@ EXACT ${_OV_PROTOBUF_PACKAGE_CONFIG})
endif()
unset(_OV_PROTOBUF_PACKAGE_CONFIG)
unset(_OV_ENABLE_SYSTEM_PROTOBUF)
endmacro()

Expand Down
18 changes: 12 additions & 6 deletions thirdparty/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# SPDX-License-Identifier: Apache-2.0
#

if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg" OR DEFINED VCPKG_VERBOSE)
set(OV_VCPKG_BUILD ON)
elseif(CMAKE_TOOLCHAIN_FILE MATCHES "conan_toolchain" OR DEFINED CONAN_EXPORTED)
set(OV_CONAN_BUILD)
endif()

set(_old_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(_old_CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE})

Expand Down Expand Up @@ -363,8 +369,7 @@ endif()
#

if(ENABLE_SAMPLES OR ENABLE_TESTS)
if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg " OR DEFINED VCPKG_VERBOSE OR
CMAKE_TOOLCHAIN_FILE MATCHES "conan_toolchain" OR DEFINED CONAN_EXPORTED)
if(OV_VCPKG_BUILD OR OV_CONAN_BUILD)
# vcpkg contains only libs compiled with threads
# conan case
find_package(gflags QUIET)
Expand Down Expand Up @@ -446,15 +451,16 @@ if(ENABLE_OV_PADDLE_FRONTEND OR ENABLE_OV_ONNX_FRONTEND OR ENABLE_OV_TF_FRONTEND
if(CMAKE_VERBOSE_MAKEFILE)
set(Protobuf_DEBUG ON)
endif()
# Note: we also specify 'protobuf' in NAMES because of vcpkg
set(find_package_protobuf_names Protobuf protobuf)
if(OV_VCPKG_BUILD)
set(protobuf_config CONFIG)
endif()
# try to find newer version first (major is changed)
# see https://protobuf.dev/support/version-support/ and
# https://github.com/protocolbuffers/protobuf/commit/d61f75ff6db36b4f9c0765f131f8edc2f86310fa
find_package(Protobuf 4.22.0 QUIET NAMES ${find_package_protobuf_names})
find_package(Protobuf 4.22.0 QUIET ${protobuf_config})
if(NOT Protobuf_FOUND)
# otherwise, fallback to existing default
find_package(Protobuf 3.20.3 REQUIRED NAMES ${find_package_protobuf_names})
find_package(Protobuf 3.20.3 REQUIRED ${protobuf_config})
endif()
set(PROTOC_EXECUTABLE protobuf::protoc)
else()
Expand Down

0 comments on commit 14292b8

Please sign in to comment.