From 32a86ac1e1a538ee71f7a95d8de68487f043247a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 3 Mar 2024 21:14:57 -0500 Subject: [PATCH] pt: Fix compilation with libtorch (#3405) Backported from https://github.com/conda-forge/deepmd-kit-feedstock/pull/71. 1. The rpath of libdeepmd_cc should contain the libtorch directory if it differs from the path of libdeepmd_cc. Setting `INSTALL_RPATH_USE_LINK_PATH` to `true` resolves the problem. 2. `${TORCH_CXX_FLAGS}` is empty in macOS, so the variable with quotes, i.e. `"${TORCH_CXX_FLAGS}"`, should be used. --------- Signed-off-by: Jinzhe Zeng --- source/CMakeLists.txt | 2 +- source/api_cc/CMakeLists.txt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 41e596f85e..931013016d 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -155,7 +155,7 @@ endif() if(ENABLE_PYTORCH AND NOT DEEPMD_C_ROOT) find_package(Torch REQUIRED) string(REGEX MATCH "_GLIBCXX_USE_CXX11_ABI=([0-9]+)" CXXABI_PT_MATCH - ${TORCH_CXX_FLAGS}) + "${TORCH_CXX_FLAGS}") if(CXXABI_PT_MATCH) message(STATUS "PyTorch CXX11 ABI: ${CMAKE_MATCH_1}") if(DEFINED OP_CXX_ABI) diff --git a/source/api_cc/CMakeLists.txt b/source/api_cc/CMakeLists.txt index cd42594f1e..2802498b4e 100644 --- a/source/api_cc/CMakeLists.txt +++ b/source/api_cc/CMakeLists.txt @@ -33,8 +33,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;${TensorFlow_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)