Skip to content

Commit

Permalink
Revert "Statically linking zlib and libpng"
Browse files Browse the repository at this point in the history
This reverts commit f7bc8a4.
  • Loading branch information
r-zenine committed Mar 4, 2020
1 parent 0033a3a commit e736e78
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ def get_extensions():
extra_compile_args = {}
third_party_search_directories = []

extra_objects = []
if sys.platform.startswith('linux') or sys.platform.startswith("darwin"):
runtime_library_dirs = None
if sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
sources = sources + source_image_cpu
libraries.append('png')
third_party_search_directories.append(os.path.join(cwd, "third_party/libpng"))
extra_objects = ['third_party/zlib/libz.a', 'third_party/libpng/libpng.a']
runtime_library_dirs = ['lib']

extension = CppExtension

Expand All @@ -116,6 +116,7 @@ def get_extensions():

define_macros = []

extra_compile_args = {}
if (torch.cuda.is_available() and CUDA_HOME is not None) or os.getenv('FORCE_CUDA', '0') == '1':
extension = CUDAExtension
sources += source_cuda
Expand Down Expand Up @@ -160,7 +161,7 @@ def get_extensions():
include_dirs=include_dirs + third_party_search_directories,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_objects=extra_objects
runtime_library_dirs=runtime_library_dirs
)
]
if compile_cpp_tests:
Expand Down Expand Up @@ -230,11 +231,11 @@ def build_deps():

zlib_path = os.path.join(this_dir, "third_party/zlib")
if sys.platform.startswith("linux"):
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)
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)
if sys.platform.startswith("darwin"):
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)
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)
os.chdir("third_party/libpng/")
os.system('cmake -DCMAKE_C_FLAGS="-fPIC" {} .'.format(libpng_cmake_options))
os.system('cmake {} .'.format(libpng_cmake_options))
throw_of_failure("cmake --build . -- -j {}".format(cpu_count))
os.chdir(this_dir)

Expand All @@ -244,6 +245,22 @@ def build_ext_with_dependencies(self):
return BuildExtension.with_options(no_python_abi_suffix=True)(self)


data_files = []
if sys.platform.startswith('linux'):
data_files = [
('torchvision/lib', [
'third_party/zlib/libz.so',
'third_party/libpng/libpng.so'])
]

if sys.platform.startswith('darwin'):
data_files = [
('torchvision/lib', [
'third_party/zlib/libz.dylib',
'third_party/libpng/libpng.dylib'])
]


setup(
# Metadata
name=package_name,
Expand All @@ -268,4 +285,5 @@ def build_ext_with_dependencies(self):
'build_ext': build_ext_with_dependencies,
'clean': clean,
},
data_files=data_files
)

0 comments on commit e736e78

Please sign in to comment.