@@ -93,12 +93,12 @@ def get_extensions():
93
93
extra_compile_args = {}
94
94
third_party_search_directories = []
95
95
96
- extra_objects = []
97
- if sys .platform .startswith ('linux' ) or sys .platform .startswith (" darwin" ):
96
+ runtime_library_dirs = None
97
+ if sys .platform .startswith ('linux' ) or sys .platform .startswith (' darwin' ):
98
98
sources = sources + source_image_cpu
99
99
libraries .append ('png' )
100
100
third_party_search_directories .append (os .path .join (cwd , "third_party/libpng" ))
101
- extra_objects = ['third_party/zlib/libz.a' , 'third_party/libpng/libpng.a ' ]
101
+ runtime_library_dirs = ['lib ' ]
102
102
103
103
extension = CppExtension
104
104
@@ -116,6 +116,7 @@ def get_extensions():
116
116
117
117
define_macros = []
118
118
119
+ extra_compile_args = {}
119
120
if (torch .cuda .is_available () and CUDA_HOME is not None ) or os .getenv ('FORCE_CUDA' , '0' ) == '1' :
120
121
extension = CUDAExtension
121
122
sources += source_cuda
@@ -160,7 +161,7 @@ def get_extensions():
160
161
include_dirs = include_dirs + third_party_search_directories ,
161
162
define_macros = define_macros ,
162
163
extra_compile_args = extra_compile_args ,
163
- extra_objects = extra_objects
164
+ runtime_library_dirs = runtime_library_dirs
164
165
)
165
166
]
166
167
if compile_cpp_tests :
@@ -230,11 +231,11 @@ def build_deps():
230
231
231
232
zlib_path = os .path .join (this_dir , "third_party/zlib" )
232
233
if sys .platform .startswith ("linux" ):
233
- libpng_cmake_options = "-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=ON -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.so" .format (zlib_path = zlib_path )
234
+ libpng_cmake_options = "-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=OFF -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.so" .format (zlib_path = zlib_path )
234
235
if sys .platform .startswith ("darwin" ):
235
- libpng_cmake_options = "-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=ON -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.dylib" .format (zlib_path = zlib_path )
236
+ libpng_cmake_options = "-DPNG_BUILD_ZLIB=ON -DPNG_STATIC=OFF -DZLIB_INCLUDE_DIR:PATH={zlib_path} -DZLIB_LIBRARY:FILEPATH={zlib_path}/libz.dylib" .format (zlib_path = zlib_path )
236
237
os .chdir ("third_party/libpng/" )
237
- os .system ('cmake -DCMAKE_C_FLAGS="-fPIC" {} .' .format (libpng_cmake_options ))
238
+ os .system ('cmake {} .' .format (libpng_cmake_options ))
238
239
throw_of_failure ("cmake --build . -- -j {}" .format (cpu_count ))
239
240
os .chdir (this_dir )
240
241
@@ -244,6 +245,22 @@ def build_ext_with_dependencies(self):
244
245
return BuildExtension .with_options (no_python_abi_suffix = True )(self )
245
246
246
247
248
+ data_files = []
249
+ if sys .platform .startswith ('linux' ):
250
+ data_files = [
251
+ ('torchvision/lib' , [
252
+ 'third_party/zlib/libz.so' ,
253
+ 'third_party/libpng/libpng.so' ])
254
+ ]
255
+
256
+ if sys .platform .startswith ('darwin' ):
257
+ data_files = [
258
+ ('torchvision/lib' , [
259
+ 'third_party/zlib/libz.dylib' ,
260
+ 'third_party/libpng/libpng.dylib' ])
261
+ ]
262
+
263
+
247
264
setup (
248
265
# Metadata
249
266
name = package_name ,
@@ -268,4 +285,5 @@ def build_ext_with_dependencies(self):
268
285
'build_ext' : build_ext_with_dependencies ,
269
286
'clean' : clean ,
270
287
},
288
+ data_files = data_files
271
289
)
0 commit comments