diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index f7bef0b2d9..cbc73735fe 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -145,6 +145,8 @@ endif(USE_TF_PYTHON_LIBS) # find tensorflow, I need tf abi info if(NOT DEEPMD_C_ROOT) find_package(tensorflow REQUIRED) + list(APPEND BACKEND_LIBRARY_PATH ${TensorFlow_LIBRARY_PATH}) + list(APPEND BACKEND_INCLUDE_DIRS ${TENSORFLOW_INCLUDE_DIRS}) endif() # find threads @@ -233,7 +235,9 @@ if(DEEPMD_C_ROOT) # use variable for TF path to set deepmd_c path set(TENSORFLOW_ROOT "${DEEPMD_C_ROOT}") set(TensorFlow_LIBRARY_PATH "${DEEPMD_C_ROOT}/lib") + set(BACKEND_LIBRARY_PATH "${DEEPMD_C_ROOT}/lib") set(TENSORFLOW_INCLUDE_DIRS "${DEEPMD_C_ROOT}/include") + set(BACKEND_INCLUDE_DIRS "${DEEPMD_C_ROOT}/include") endif() if(NOT DEEPMD_C_ROOT) diff --git a/source/api_c/CMakeLists.txt b/source/api_c/CMakeLists.txt index f6e741105a..f0b36a62d7 100644 --- a/source/api_c/CMakeLists.txt +++ b/source/api_c/CMakeLists.txt @@ -12,8 +12,8 @@ target_include_directories( ${libname} PUBLIC $ $) -set_target_properties( - ${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}") +set_target_properties(${libname} PROPERTIES INSTALL_RPATH + "$ORIGIN;${BACKEND_LIBRARY_PATH}") if(CMAKE_TESTING_ENABLED) target_link_libraries(${libname} PRIVATE coverage_config) endif() diff --git a/source/api_c/tests/CMakeLists.txt b/source/api_c/tests/CMakeLists.txt index d4233a83e8..1b035b1a6c 100644 --- a/source/api_c/tests/CMakeLists.txt +++ b/source/api_c/tests/CMakeLists.txt @@ -4,7 +4,7 @@ project(deepmd_api_c_test) file(GLOB TEST_SRC test_*.cc) set_target_properties( - ${LIB_DEEPMD_C} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}") + ${LIB_DEEPMD_C} PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}") add_executable(runUnitTests_c ${TEST_SRC}) target_link_libraries(runUnitTests_c PRIVATE GTest::gtest_main ${LIB_DEEPMD_C} diff --git a/source/api_cc/CMakeLists.txt b/source/api_cc/CMakeLists.txt index 2f296e3dfd..15d3844b36 100644 --- a/source/api_cc/CMakeLists.txt +++ b/source/api_cc/CMakeLists.txt @@ -25,8 +25,10 @@ if(Protobuf_LIBRARY) endif() set_target_properties( - ${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}" - BUILD_RPATH "$ORIGIN/../op") + ${libname} + PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}" + INSTALL_RPATH_USE_LINK_PATH TRUE + BUILD_RPATH "$ORIGIN/../op") target_compile_definitions(${libname} PRIVATE TF_PRIVATE) if(CMAKE_TESTING_ENABLED) target_link_libraries(${libname} PRIVATE coverage_config) diff --git a/source/gmx/CMakeLists.txt b/source/gmx/CMakeLists.txt index d445479d39..8fde1e6ab8 100644 --- a/source/gmx/CMakeLists.txt +++ b/source/gmx/CMakeLists.txt @@ -26,7 +26,7 @@ target_include_directories(${libgmxname} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/) set_target_properties( - ${libgmxname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}") + ${libgmxname} PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}") install( FILES dp_gmx_patch diff --git a/source/ipi/CMakeLists.txt b/source/ipi/CMakeLists.txt index 158f98aea5..2b23a63c76 100644 --- a/source/ipi/CMakeLists.txt +++ b/source/ipi/CMakeLists.txt @@ -44,13 +44,13 @@ if(APPLE) ${ipiname} PROPERTIES LINK_FLAGS "${extra_link_flags}" INSTALL_RPATH - "@loader_path/../${LIB_DIR}:${TensorFlow_LIBRARY_PATH}") + "@loader_path/../${LIB_DIR};${BACKEND_LIBRARY_PATH}") else() set_target_properties( ${ipiname} PROPERTIES LINK_FLAGS "-Wl,-rpath,'$ORIGIN'/../${LIB_DIR} ${extra_link_flags}" - INSTALL_RPATH "$ORIGIN/../${LIB_DIR}:${TensorFlow_LIBRARY_PATH}") + INSTALL_RPATH "$ORIGIN/../${LIB_DIR};${BACKEND_LIBRARY_PATH}") endif() if(CMAKE_TESTING_ENABLED) diff --git a/source/lmp/env.sh.in b/source/lmp/env.sh.in index 8c3a7aedc1..55b90be886 100644 --- a/source/lmp/env.sh.in +++ b/source/lmp/env.sh.in @@ -1,6 +1,6 @@ DEEPMD_ROOT=@CMAKE_INSTALL_PREFIX@ -TENSORFLOW_INCLUDE_DIRS="@TensorFlow_INCLUDE_DIRS@" -TENSORFLOW_LIBRARY_PATH="@TensorFlow_LIBRARY_PATH@" +TENSORFLOW_INCLUDE_DIRS="@BACKEND_INCLUDE_DIRS@" +TENSORFLOW_LIBRARY_PATH="@BACKEND_LIBRARY_PATH@" TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"` TF_LIBRARY_PATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -L/g"` diff --git a/source/lmp/env_c.sh.in b/source/lmp/env_c.sh.in index 67f6a63a1c..af010497ba 100644 --- a/source/lmp/env_c.sh.in +++ b/source/lmp/env_c.sh.in @@ -1,6 +1,6 @@ DEEPMD_ROOT=@CMAKE_INSTALL_PREFIX@ -TENSORFLOW_INCLUDE_DIRS="@TensorFlow_INCLUDE_DIRS@" -TENSORFLOW_LIBRARY_PATH="@TensorFlow_LIBRARY_PATH@" +TENSORFLOW_INCLUDE_DIRS="@BACKEND_INCLUDE_DIRS@" +TENSORFLOW_LIBRARY_PATH="@BACKEND_LIBRARY_PATH@" TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"` TF_LIBRARY_PATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -L/g"` diff --git a/source/lmp/env_py.sh.in b/source/lmp/env_py.sh.in index e6fc217c26..be48191f33 100644 --- a/source/lmp/env_py.sh.in +++ b/source/lmp/env_py.sh.in @@ -1,6 +1,6 @@ DEEPMD_ROOT=@CMAKE_INSTALL_PREFIX@ -TENSORFLOW_INCLUDE_DIRS="@TensorFlow_INCLUDE_DIRS@" -TENSORFLOW_LIBRARY_PATH="@TensorFlow_LIBRARY_PATH@" +TENSORFLOW_INCLUDE_DIRS="@BACKEND_INCLUDE_DIRS@" +TENSORFLOW_LIBRARY_PATH="@BACKEND_LIBRARY_PATH@" PYTHON_LIBRARY_PATH="@Python_LIBRARY_DIRS@" TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"` diff --git a/source/lmp/env_py_c.sh.in b/source/lmp/env_py_c.sh.in index b8affd7ff5..34874cc24c 100644 --- a/source/lmp/env_py_c.sh.in +++ b/source/lmp/env_py_c.sh.in @@ -1,6 +1,6 @@ DEEPMD_ROOT=@CMAKE_INSTALL_PREFIX@ -TENSORFLOW_INCLUDE_DIRS="@TensorFlow_INCLUDE_DIRS@" -TENSORFLOW_LIBRARY_PATH="@TensorFlow_LIBRARY_PATH@" +TENSORFLOW_INCLUDE_DIRS="@BACKEND_INCLUDE_DIRS@" +TENSORFLOW_LIBRARY_PATH="@BACKEND_LIBRARY_PATH@" PYTHON_LIBRARY_PATH="@Python_LIBRARY_DIRS@" TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"` diff --git a/source/lmp/plugin/CMakeLists.txt b/source/lmp/plugin/CMakeLists.txt index 4fdae7ac5b..f912059261 100644 --- a/source/lmp/plugin/CMakeLists.txt +++ b/source/lmp/plugin/CMakeLists.txt @@ -99,7 +99,7 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION) "-Wl,-undefined,dynamic_lookup") else() set_target_properties( - ${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}" + ${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}" LINK_FLAGS "-rdynamic") endif() target_compile_definitions( diff --git a/source/op/CMakeLists.txt b/source/op/CMakeLists.txt index 7a92e259e0..6fc6422c6e 100644 --- a/source/op/CMakeLists.txt +++ b/source/op/CMakeLists.txt @@ -62,11 +62,10 @@ endif() if(APPLE) set_target_properties( ${LIB_DEEPMD_OP} PROPERTIES INSTALL_RPATH - "@loader_path;${TensorFlow_LIBRARY_PATH}") + "@loader_path;${BACKEND_LIBRARY_PATH}") else() set_target_properties( - ${LIB_DEEPMD_OP} PROPERTIES INSTALL_RPATH - "$ORIGIN;${TensorFlow_LIBRARY_PATH}") + ${LIB_DEEPMD_OP} PROPERTIES INSTALL_RPATH "$ORIGIN;${BACKEND_LIBRARY_PATH}") endif() if(CMAKE_TESTING_ENABLED) target_link_libraries(${LIB_DEEPMD_OP} PRIVATE coverage_config)