xmake.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package("snappy")
  2. set_homepage("https://github.com/google/snappy")
  3. set_description("A fast compressor/decompressor")
  4. set_urls("https://github.com/google/snappy/archive/$(version).tar.gz",
  5. "https://github.com/google/snappy.git")
  6. add_versions("1.1.8", "16b677f07832a612b0836178db7f374e414f94657c138e6993cbfc5dcc58651f")
  7. add_versions("1.1.9", "75c1fbb3d618dd3a0483bff0e26d0a92b495bbe5059c8b4f1c962b478b6e06e7")
  8. add_versions("1.1.10", "49d831bffcc5f3d01482340fe5af59852ca2fe76c3e05df0e67203ebbe0f1d90")
  9. add_patches("1.1.9", path.join(os.scriptdir(), "patches", "1.1.9", "inline.patch"), "ed6b247d19486ab3f08f268269133193d7cdadd779523c5e69b5e653f82d535b")
  10. add_deps("cmake")
  11. add_configs("avx", {description = "Use the AVX instruction set", default = false, type = "boolean"})
  12. add_configs("avx2", {description = "Use the AVX2 instruction set", default = false, type = "boolean"})
  13. add_configs("bmi2", {description = "Use the BMI2 instruction set", default = false, type = "boolean"})
  14. on_load(function (package)
  15. if package:version():eq("1.1.10") and package:is_plat("android") then
  16. raise("snappy 1.1.10 not support android.")
  17. end
  18. end)
  19. on_install("windows", "linux", "macosx", "mingw", "android", function (package)
  20. if package:version():eq("1.1.10") then
  21. io.replace("snappy.cc", "(op + deferred_length) < op_limit_min_slop);", "static_cast<ptrdiff_t>(op + deferred_length) < op_limit_min_slop);", {plain = true})
  22. end
  23. local configs = {"-DSNAPPY_BUILD_TESTS=OFF", "-DSNAPPY_BUILD_BENCHMARKS=OFF"}
  24. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  25. table.insert(configs, "-DSNAPPY_REQUIRE_AVX=" .. (package:config("avx") and "ON" or "OFF"))
  26. table.insert(configs, "-DSNAPPY_REQUIRE_AVX2=" .. (package:config("avx2") and "ON" or "OFF"))
  27. table.insert(configs, "-DSNAPPY_HAVE_BMI2=" .. (package:config("bmi2") and "ON" or "OFF"))
  28. if package:config("pic") ~= false then
  29. table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
  30. end
  31. import("package.tools.cmake").install(package, configs)
  32. end)
  33. on_test(function (package)
  34. assert(package:check_cxxsnippets({test = [[
  35. void test(int args, char** argv) {
  36. snappy::Compress(nullptr, nullptr);
  37. }
  38. ]]}, {configs = {languages = "c++11"}, includes = "snappy.h"}))
  39. end)