@@ -48,20 +48,44 @@ target_include_directories(
48
48
set (BRIDGE_OBJECT_FILES $<TARGET_OBJECTS:bridge>)
49
49
50
50
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} " )
51
+
52
+
53
+ file (GLOB LIBTORCH_ALL_LIB_FILES "${LIBTORCH_DIR} /lib/*.a" "${LIBTORCH_DIR} /lib/*.dylib" "${LIBTORCH_DIR} /lib/*.so" )
54
+
55
+ set (LIBTORCH_ALL_LIBS "" )
56
+ foreach (lib_path IN LISTS LIBTORCH_ALL_LIB_FILES)
57
+ get_filename_component (lib_name "${lib_path} " NAME_WE )
58
+ list (APPEND LIBTORCH_ALL_LIBS "${lib_name} " )
59
+ endforeach ()
60
+
61
+
62
+ set (REQUIRED_LIBS
63
+ "libtorch"
64
+ "libtorch_cpu"
65
+ "libc10"
66
+ "libtorch_global_deps"
67
+ )
68
+
69
+ set (DISALLOWED_LIBS
70
+ "libtorch_python"
71
+ )
72
+
73
+
74
+ set (LIBTORCH_LIBS_LINKER_ARGS "" ) # Will hold the list of "-l..." flags.
75
+ foreach (lib_name IN LISTS LIBTORCH_ALL_LIBS)
76
+ if (lib_name IN_LIST DISALLOWED_LIBS)
77
+ if (lib_name IN_LIST REQUIRED_LIBS)
78
+ message (FATAL_ERROR "Required lib ${lib_name} is disallowed." )
79
+ else ()
80
+ message (STATUS "Skipping disallowed lib: ${lib_name} " )
81
+ continue ()
82
+ endif ()
83
+ endif ()
84
+ string (REGEX REPLACE "^lib" "" lib_name_short "${lib_name} " )
85
+ list (APPEND LIBTORCH_LIBS_LINKER_ARGS "-l${lib_name_short} " )
61
86
endforeach ()
62
87
63
- # cmake_print_variables(PYTORCH_LIBS)
64
- # cmake_print_variables(PYTORCH_LIBS_LINKER_ARGS)
88
+ cmake_print_variables(LIBTORCH_LIBS_LINKER_ARGS)
65
89
66
90
add_executable (TorchBridge ${BRIDGE_DIR} /lib/Bridge.chpl)
67
91
add_dependencies (TorchBridge bridge)
@@ -70,10 +94,11 @@ target_link_options(TorchBridge
70
94
${BRIDGE_DIR} /include /bridge.h
71
95
${BRIDGE_OBJECT_FILES}
72
96
-L ${LIBTORCH_DIR} /lib
73
- "-ltorch"
74
- "-ltorch_cpu"
75
- "-lc10"
76
- # ${PYTORCH_LIBS_LINKER_ARGS}
97
+ # "-ltorch"
98
+ # "-ltorch_cpu"
99
+ # "-lc10"
100
+ # "-ltorch_global_deps"
101
+ ${LIBTORCH_LIBS_LINKER_ARGS}
77
102
--ldflags "-Wl,-rpath,${LIBTORCH_DIR} /lib"
78
103
)
79
104
# install(TARGETS TorchBridge DESTINATION ".")
0 commit comments