Skip to content

Commit f00e90a

Browse files
committed
Compiling with all pytorch shared libs works for mac.
1 parent 418a2c7 commit f00e90a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Diff for: CMakeLists.txt

+17-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ target_include_directories(
4848
set(BRIDGE_OBJECT_FILES $<TARGET_OBJECTS:bridge>)
4949

5050

51+
file(GLOB PYTORCH_LIBS "${LIBTORCH_DIR}/lib/*.a" "${LIBTORCH_DIR}/lib/*.dylib" "${LIBTORCH_DIR}/lib/*.so")
52+
53+
set(PYTORCH_LIBS_LINKER_ARGS "-ltorch") # Will hold the list of "-l..." flags.
54+
foreach(lib_path IN LISTS PYTORCH_LIBS)
55+
# Get just the filename without the directory or extension
56+
get_filename_component(lib_name "${lib_path}" NAME_WE)
57+
# If it starts with "lib", strip that off
58+
string(REGEX REPLACE "^lib" "" lib_name "${lib_name}")
59+
# Now prepend "-l" to the actual library name
60+
list(APPEND PYTORCH_LIBS_LINKER_ARGS "-l${lib_name}")
61+
endforeach()
62+
63+
# cmake_print_variables(PYTORCH_LIBS)
64+
cmake_print_variables(PYTORCH_LIBS_LINKER_ARGS)
65+
5166
add_executable(TorchBridge ${BRIDGE_DIR}/lib/Bridge.chpl)
5267
add_dependencies(TorchBridge bridge)
5368
target_link_options(TorchBridge
@@ -58,6 +73,7 @@ target_link_options(TorchBridge
5873
"-ltorch"
5974
"-ltorch_cpu"
6075
"-lc10"
76+
${PYTORCH_LIBS_LINKER_ARGS}
6177
--ldflags "-Wl,-rpath,${LIBTORCH_DIR}/lib"
6278
)
63-
install(TARGETS TorchBridge DESTINATION ".")
79+
# install(TARGETS TorchBridge DESTINATION ".")

0 commit comments

Comments
 (0)