Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@
# setuptools will re-find tensorflow after installing setup_requires
tf_install_dir = None

# add cmake as a build requirement if cmake>3.12 is not installed
# add cmake as a build requirement if cmake>=3.16 is not installed
try:
cmake_version = get_cmake_version()
except SKBuildError:
setup_requires.append("cmake")
else:
if cmake_version in SpecifierSet("<3.12"):
if cmake_version in SpecifierSet("<3.16"):
setup_requires.append("cmake")

Path("deepmd").mkdir(exist_ok=True)
Expand Down
3 changes: 2 additions & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.12)
# new in 3.16: GET_RUNTIME_DEPENDENCIES
cmake_minimum_required(VERSION 3.16)
project(DeePMD)

option(BUILD_TESTING "Enable converage" OFF)
Expand Down
46 changes: 37 additions & 9 deletions source/cmake/Findtensorflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ if(BUILD_PY_IF)
# here TENSORFLOW_ROOT is path to site-packages/tensorflow
# for conda libraries, append extra paths
list(APPEND TensorFlow_search_PATHS "${TENSORFLOW_ROOT}/../tensorflow_core")
list(APPEND TensorFlow_search_PATHS "${TENSORFLOW_ROOT}/../../../..")
endif()

# includes
Expand All @@ -71,14 +70,6 @@ find_path(TensorFlow_INCLUDE_DIRS
PATH_SUFFIXES "/include"
NO_DEFAULT_PATH
)
find_path(TensorFlow_INCLUDE_DIRS_GOOGLE
NAMES
google/protobuf/type.pb.h
PATHS ${TensorFlow_search_PATHS}
PATH_SUFFIXES "/include"
NO_DEFAULT_PATH
)
list(APPEND TensorFlow_INCLUDE_DIRS ${TensorFlow_INCLUDE_DIRS_GOOGLE})

if (NOT TensorFlow_INCLUDE_DIRS AND tensorflow_FIND_REQUIRED)
message(FATAL_ERROR
Expand Down Expand Up @@ -150,6 +141,43 @@ foreach (module ${TensorFlowFramework_FIND_COMPONENTS})
endif ()
endforeach ()

# find protobuf header
find_path(TensorFlow_INCLUDE_DIRS_GOOGLE
NAMES
google/protobuf/type.pb.h
PATHS ${TensorFlow_search_PATHS}
PATH_SUFFIXES "/include"
NO_DEFAULT_PATH
)
message(STATUS proto ${TensorFlow_INCLUDE_DIRS_GOOGLE})
if (NOT TensorFlow_INCLUDE_DIRS_GOOGLE)
message(STATUS "Protobuf headers are not found in the directory of TensorFlow, assuming external protobuf was used to build TensorFlow")
# try to find from ldd list of TF library
# a warning is threw here, just ignore it
file(GET_RUNTIME_DEPENDENCIES
RESOLVED_DEPENDENCIES_VAR TensorFlow_LINKED_LIBRARIES
LIBRARIES ${TensorFlowFramework_LIBRARY}
POST_INCLUDE_REGEXES "^.+protobuf\..+$"
)
# search protobuf from linked libraries
foreach(_lib ${TensorFlow_LINKED_LIBRARIES})
string(REGEX MATCH "^.+protobuf\..+$" _protobuf_lib ${_lib})
if (_protobuf_lib)
set(Protobuf_LIBRARY ${_protobuf_lib})
break()
endif()
endforeach()
if (NOT Protobuf_LIBRARY)
message(FATAL_ERROR "TensorFlow is not linked to protobuf")
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)
set(TensorFlow_INCLUDE_DIRS_GOOGLE ${Protobuf_INCLUDE_DIRS})
endif()
list(APPEND TensorFlow_INCLUDE_DIRS ${TensorFlow_INCLUDE_DIRS_GOOGLE})

if (BUILD_CPP_IF)
# define the output variable
if (TensorFlow_INCLUDE_DIRS AND TensorFlow_LIBRARY AND TensorFlowFramework_LIBRARY)
Expand Down