Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions source/cmake/Findtensorflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,47 @@ if(NOT TensorFlow_INCLUDE_DIRS_GOOGLE)
STATUS
"Protobuf headers are not found in the directory of TensorFlow, assuming external protobuf was used to build TensorFlow"
)
if(NOT Protobuf_LIBRARY)
message(FATAL_ERROR "TensorFlow is not linked to protobuf")
# TensorFlow 2.21 packages may not record protobuf as a direct runtime
# dependency. If the runtime scan found protobuf, preserve that exact library
# and use its installation prefix to guide the header search. Check both flat
# <prefix>/lib and multiarch <prefix>/lib/<triplet> layouts before trusting
# the inferred prefix. Otherwise, allow FindProtobuf to locate the external
# protobuf package normally.
if(Protobuf_LIBRARY)
set(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED FALSE)
if(DEFINED Protobuf_ROOT)
set(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED TRUE)
set(_TensorFlow_SAVED_PROTOBUF_ROOT "${Protobuf_ROOT}")
endif()
get_filename_component(_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY
"${Protobuf_LIBRARY}" DIRECTORY)
get_filename_component(
_TensorFlow_PROTOBUF_PREFIX "${_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY}"
DIRECTORY)
if(NOT EXISTS
"${_TensorFlow_PROTOBUF_PREFIX}/include/google/protobuf/service.h")
get_filename_component(_TensorFlow_PROTOBUF_PREFIX
"${_TensorFlow_PROTOBUF_PREFIX}" DIRECTORY)
endif()
if(EXISTS
"${_TensorFlow_PROTOBUF_PREFIX}/include/google/protobuf/service.h")
set(Protobuf_ROOT "${_TensorFlow_PROTOBUF_PREFIX}")
endif()
endif()
get_filename_component(Protobuf_LIBRARY_DIRECTORY ${Protobuf_LIBRARY}
DIRECTORY)
# assume the include directory is ../include
set(Protobuf_INCLUDE_DIR ${Protobuf_LIBRARY_DIRECTORY}/../include)
find_package(Protobuf REQUIRED)
if(DEFINED _TensorFlow_PROTOBUF_ROOT_WAS_DEFINED)
if(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED)
set(Protobuf_ROOT "${_TensorFlow_SAVED_PROTOBUF_ROOT}")
else()
unset(Protobuf_ROOT)
endif()
unset(_TensorFlow_PROTOBUF_ROOT_WAS_DEFINED)
unset(_TensorFlow_SAVED_PROTOBUF_ROOT)
unset(_TensorFlow_PROTOBUF_LIBRARY_DIRECTORY)
unset(_TensorFlow_PROTOBUF_PREFIX)
endif()
set(TensorFlow_INCLUDE_DIRS_GOOGLE ${Protobuf_INCLUDE_DIRS})
set(Protobuf_LIBRARY ${Protobuf_LIBRARIES})
endif()
list(APPEND TensorFlow_INCLUDE_DIRS ${TensorFlow_INCLUDE_DIRS_GOOGLE})

Expand Down
Loading