Skip to content

Commit 0b85adc

Browse files
committed
Convert TORCH_LIBRARIES into abacus::torch target
1 parent e0b8dad commit 0b85adc

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

source/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ add_library(abacus::feature_libs ALIAS abacus_feature_libs)
136136
add_library(abacus_link_libs INTERFACE)
137137
add_library(abacus::link_libs ALIAS abacus_link_libs)
138138

139+
if(ENABLE_MLALGO OR DEFINED Torch_DIR)
140+
# TorchConfig.cmake exposes its complete link closure through
141+
# TORCH_LIBRARIES rather than a stable namespaced target. Keep that
142+
# provider-specific representation behind an imported adapter so the
143+
# installed ABACUS package can recreate it after find_dependency(Torch).
144+
add_library(abacus::torch INTERFACE IMPORTED GLOBAL)
145+
target_link_libraries(abacus::torch INTERFACE ${TORCH_LIBRARIES})
146+
target_include_directories(abacus::torch INTERFACE ${TORCH_INCLUDE_DIRS})
147+
target_compile_options(abacus::torch INTERFACE ${ABACUS_TORCH_CXX_FLAGS})
148+
endif()
149+
139150
target_link_libraries(abacus_link_libs INTERFACE
140151
abacus::feature_libs
141152
abacus::linalg_libs)
@@ -263,8 +274,7 @@ if(ENABLE_MLALGO)
263274
endif()
264275

265276
if(ENABLE_MLALGO OR DEFINED Torch_DIR)
266-
list(APPEND _abacus_feature_include_dirs ${TORCH_INCLUDE_DIRS})
267-
list(APPEND _abacus_feature_compile_options ${ABACUS_TORCH_CXX_FLAGS})
277+
list(APPEND _abacus_feature_libs abacus::torch)
268278
endif()
269279

270280
if(ENABLE_CNPY)
@@ -372,6 +382,7 @@ foreach(_abacus_feature_target IN ITEMS
372382
DeePMD::deepmd_cc
373383
NEP::nep
374384
TensorFlow::tensorflow_cc
385+
abacus::torch
375386
ZLIB::ZLIB
376387
PEXSI::PEXSI
377388
NCCL::NCCL

0 commit comments

Comments
 (0)