conanfile.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import os
  2. from conans import ConanFile, CMake, tools
  3. class CbloscConan(ConanFile):
  4. name = "c-blosc"
  5. description = "An extremely fast, multi-threaded, meta-compressor library"
  6. license = "BSD"
  7. url = "https://github.com/Blosc/c-blosc"
  8. settings = "os", "compiler", "build_type", "arch"
  9. options = {"shared": [True, False]}
  10. default_options = "shared=False"
  11. generators = "cmake"
  12. exports_sources = "*", "!test_package/*", "!appveyor*", "!.*.yml", "!*.py", "!.*"
  13. @property
  14. def run_tests(self):
  15. return "CONAN_RUN_TESTS" in os.environ
  16. def build(self):
  17. os.mkdir("build")
  18. tools.replace_in_file("CMakeLists.txt", "project(blosc)", '''project(blosc)
  19. include(${CMAKE_BINARY_DIR}/../conanbuildinfo.cmake)
  20. conan_basic_setup(NO_OUTPUT_DIRS)''')
  21. cmake = CMake(self)
  22. cmake.definitions["BUILD_TESTS"] = "ON" if self.run_tests else "OFF"
  23. cmake.definitions["BUILD_BENCHMARKS"] = "ON" if self.run_tests else "OFF"
  24. cmake.definitions["BUILD_SHARED"] = "ON" if (self.options.shared or self.run_tests) else "OFF"
  25. cmake.definitions["BUILD_STATIC"] = "OFF" if self.options.shared else "ON"
  26. cmake.configure(build_folder="build")
  27. cmake.build()
  28. if self.run_tests:
  29. self.output.warn("Running tests!!")
  30. self.launch_tests()
  31. def launch_tests(self):
  32. """Conan will remove rpaths from shared libs to be able to reuse the shared libs, we need
  33. to tell the tests where to find the shared libs"""
  34. test_args = "-VV" if tools.os_info.is_windows else ""
  35. with tools.chdir("build"):
  36. outdir = os.path.join(self.build_folder, "build", "blosc")
  37. if tools.os_info.is_macos:
  38. prefix = "DYLD_LIBRARY_PATH=%s" % outdir
  39. elif tools.os_info.is_windows:
  40. prefix = "PATH=%s;%%PATH%%" % outdir
  41. elif tools.os_info.is_linux:
  42. prefix = "LD_LIBRARY_PATH=%s" % outdir
  43. else:
  44. return
  45. self.run("%s ctest %s" % (prefix, test_args))
  46. def package(self):
  47. self.copy("blosc.h", dst="include", src="blosc")
  48. self.copy("blosc-export.h", dst="include", src="blosc")
  49. self.copy("*libblosc.a", dst="lib", keep_path=False)
  50. if self.options.shared:
  51. self.copy("*/blosc.lib", dst="lib", keep_path=False)
  52. self.copy("*blosc.dll", dst="bin", keep_path=False)
  53. self.copy("*blosc.*dylib*", dst="lib", keep_path=False, symlinks=True)
  54. self.copy("*blosc.so*", dst="lib", keep_path=False, symlinks=True)
  55. self.copy("*libblosc.dll.a", dst="lib", keep_path=False) # Mingw
  56. else:
  57. self.copy("*libblosc.lib", dst="lib", src="", keep_path=False)
  58. def package_info(self):
  59. if self.settings.compiler == "Visual Studio" and not self.options.shared:
  60. self.cpp_info.libs = ["libblosc"]
  61. else:
  62. self.cpp_info.libs = ["blosc"]
  63. if self.settings.os == "Linux":
  64. self.cpp_info.libs.append("pthread")