conanfile.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from conans import ConanFile, tools
  2. from conans.errors import ConanInvalidConfiguration
  3. from conans.tools import os_info
  4. import os
  5. class ZlibConan(ConanFile):
  6. name = "zlib"
  7. version = "1.2.11"
  8. license = "Zlib"
  9. author = "Shawn Morford <DarkMorford@Gmail.com>"
  10. url = "https://code.darkmorford.net/conan-pkg/zlib"
  11. description = "A Massively Spiffy Yet Delicately Unobtrusive Compression Library"
  12. homepage = "http://zlib.net/"
  13. topics = ("compression", "utility")
  14. exports_sources = ["patches/*"]
  15. settings = "os", "compiler", "build_type", "arch"
  16. options = {"shared": [True, False]}
  17. default_options = {"shared": False}
  18. @property
  19. def subfolder(self):
  20. return os.path.join(self.source_folder, f"zlib-{self.version}")
  21. def configure(self):
  22. del self.settings.compiler.cppstd
  23. del self.settings.compiler.libcxx
  24. def source(self):
  25. tools.get(**self.conan_data["sources"][self.version])
  26. for patch in self.conan_data["patches"][self.version]:
  27. tools.patch(base_path=self.subfolder, **patch)
  28. def _build_nmake(self):
  29. flags = [f"-{self.settings.compiler.runtime}"]
  30. if self.settings.build_type == "Debug":
  31. flags.append("-Od")
  32. else:
  33. flags.append("-O2")
  34. with tools.vcvars(self.settings), tools.chdir(self.subfolder):
  35. makefile = os.path.join("win32", "Makefile.msc")
  36. flags = " ".join(flags)
  37. self.run(f'nmake -f "{makefile}" LOC="{flags}"')
  38. def build(self):
  39. if self.settings.compiler == "Visual Studio" and os_info.is_windows:
  40. self._build_nmake()
  41. else:
  42. raise ConanInvalidConfiguration("This configuration is not yet supported.")
  43. def build_id(self):
  44. if self.settings.compiler == "Visual Studio":
  45. self.info_build.options.shared = "Both"
  46. def package(self):
  47. self.copy("zlib.h", dst="include", src=f"zlib-{self.version}")
  48. self.copy("zconf.h", dst="include", src=f"zlib-{self.version}")
  49. if self.options.shared:
  50. self.copy("*zdll.lib", dst="lib", keep_path=False)
  51. self.copy("*zlib1.dll", dst="bin", keep_path=False)
  52. else:
  53. self.copy("*zlib.lib", dst="lib", keep_path=False)
  54. self.copy("*.so", dst="lib", keep_path=False)
  55. self.copy("*.dylib", dst="lib", keep_path=False)
  56. self.copy("*.a", dst="lib", keep_path=False)
  57. def package_info(self):
  58. if self.settings.os == "Windows":
  59. self.cpp_info.libs = ["zdll"] if self.options.shared else ["zlib"]
  60. else:
  61. self.cpp_info.libs = ["z"]