diff --git a/setup.py b/setup.py index 5564ad4790..36751a192b 100644 --- a/setup.py +++ b/setup.py @@ -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) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 6a372818b4..2f6a0b2c3a 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -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) diff --git a/source/cmake/Findtensorflow.cmake b/source/cmake/Findtensorflow.cmake index 97d21b8444..cd50ba2863 100644 --- a/source/cmake/Findtensorflow.cmake +++ b/source/cmake/Findtensorflow.cmake @@ -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 @@ -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 @@ -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)