2
0

xmake.lua 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package("libssh2")
  2. set_homepage("https://www.libssh2.org/")
  3. set_description("C library implementing the SSH2 protocol")
  4. set_license("BSD-3-Clause")
  5. set_urls("https://github.com/libssh2/libssh2/releases/download/libssh2-$(version)/libssh2-$(version).tar.gz",
  6. "https://www.libssh2.org/download/libssh2-$(version).tar.gz",
  7. "https://github.com/libssh2/libssh2.git")
  8. add_versions("1.10.0", "2d64e90f3ded394b91d3a2e774ca203a4179f69aebee03003e5a6fa621e41d51")
  9. add_versions("1.11.0", "3736161e41e2693324deb38c26cfdc3efe6209d634ba4258db1cecff6a5ad461")
  10. add_configs("backend", {description = "Select crypto backend.", default = (is_plat("windows") and "wincng" or "openssl"), type = "string", values = {"openssl", "wincng", "mbedtls", "libgcrypt"}})
  11. add_deps("zlib")
  12. if is_plat("windows") then
  13. add_deps("cmake")
  14. add_syslinks("bcrypt", "crypt32", "ws2_32")
  15. end
  16. on_load(function (package)
  17. if package:gitref() then
  18. package:add("deps", "automake", "autoconf")
  19. end
  20. local backend = package:config("backend")
  21. if backend ~= "wincng" then
  22. package:add("deps", backend)
  23. end
  24. end)
  25. on_install("windows", function (package)
  26. local configs = {"-DBUILD_TESTING=OFF",
  27. "-DBUILD_EXAMPLES=OFF",
  28. "-DENABLE_ZLIB_COMPRESSION=ON"}
  29. local backend_name = {wincng = "WinCNG",
  30. openssl = "OpenSSL",
  31. mbedtls = "mbedTLS",
  32. libgcrypt = "Libgcrypt"}
  33. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  34. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  35. table.insert(configs, "-DCRYPTO_BACKEND=" .. backend_name[package:config("backend")])
  36. import("package.tools.cmake").install(package, configs)
  37. end)
  38. on_install("macosx", "linux", function (package)
  39. local configs = {"--disable-silent-rules",
  40. "--disable-examples-build",
  41. "--with-libz"}
  42. local lib_prefix = {openssl = "libssl",
  43. mbedtls = "libmbedcrypto",
  44. libgcrypt = "libgcrypt"}
  45. local backend = package:config("backend")
  46. table.insert(configs, "--with-crypto=" .. backend)
  47. local dep = package:dep(backend)
  48. if dep and not dep:is_system() then
  49. table.insert(configs, "--with-" .. lib_prefix[backend] .. "-prefix=" .. dep:installdir())
  50. end
  51. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  52. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  53. if package:is_plat("linux") and package:config("pic") ~= false then
  54. table.insert(configs, "--with-pic")
  55. end
  56. if package:gitref() then
  57. os.vrunv("sh", {"./buildconf"})
  58. end
  59. import("package.tools.autoconf").install(package, configs)
  60. end)
  61. on_test(function (package)
  62. assert(package:has_cfuncs("libssh2_exit", {includes = "libssh2.h"}))
  63. end)