1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- from conans import ConanFile, tools
- from conans.errors import ConanInvalidConfiguration
- from conans.tools import os_info
- import os
- class ZlibConan(ConanFile):
- name = "zlib"
- version = "1.2.11"
- license = "Zlib"
- author = "Shawn Morford <DarkMorford@Gmail.com>"
- url = "https://code.darkmorford.net/conan-pkg/zlib"
- description = "A Massively Spiffy Yet Delicately Unobtrusive Compression Library"
- homepage = "http://zlib.net/"
- topics = ("compression", "utility")
- exports_sources = ["patches/*"]
- settings = "os", "compiler", "build_type", "arch"
- options = {"shared": [True, False]}
- default_options = {"shared": False}
- @property
- def subfolder(self):
- return os.path.join(self.source_folder, f"zlib-{self.version}")
- def configure(self):
- del self.settings.compiler.cppstd
- del self.settings.compiler.libcxx
- def source(self):
- tools.get(**self.conan_data["sources"][self.version])
- for patch in self.conan_data["patches"][self.version]:
- tools.patch(base_path=self.subfolder, **patch)
- def _build_nmake(self):
- flags = [f"-{self.settings.compiler.runtime}"]
- if self.settings.build_type == "Debug":
- flags.append("-Od")
- else:
- flags.append("-O2")
- with tools.vcvars(self.settings), tools.chdir(self.subfolder):
- makefile = os.path.join("win32", "Makefile.msc")
- flags = " ".join(flags)
- self.run(f'nmake -f "{makefile}" LOC="{flags}"')
- def build(self):
- if self.settings.compiler == "Visual Studio" and os_info.is_windows:
- self._build_nmake()
- else:
- raise ConanInvalidConfiguration("This configuration is not yet supported.")
- def build_id(self):
- if self.settings.compiler == "Visual Studio":
- self.info_build.options.shared = "Both"
- def package(self):
- self.copy("zlib.h", dst="include", src=f"zlib-{self.version}")
- self.copy("zconf.h", dst="include", src=f"zlib-{self.version}")
- if self.options.shared:
- self.copy("*zdll.lib", dst="lib", keep_path=False)
- self.copy("*zlib1.dll", dst="bin", keep_path=False)
- else:
- self.copy("*zlib.lib", dst="lib", keep_path=False)
- self.copy("*.so", dst="lib", keep_path=False)
- self.copy("*.dylib", dst="lib", keep_path=False)
- self.copy("*.a", dst="lib", keep_path=False)
- def package_info(self):
- if self.settings.os == "Windows":
- self.cpp_info.libs = ["zdll"] if self.options.shared else ["zlib"]
- else:
- self.cpp_info.libs = ["z"]
|