xmake.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_configs("backend", {description = "Select crypto backend.", default = (is_plat("windows") and "wincng" or "openssl"), type = "string", values = {"openssl", "wincng", "mbedtls", "libgcrypt"}})
  10. add_deps("zlib")
  11. if is_plat("windows") then
  12. add_deps("cmake")
  13. add_syslinks("bcrypt", "crypt32", "ws2_32")
  14. end
  15. on_load(function (package)
  16. if package:gitref() then
  17. package:add("deps", "automake", "autoconf")
  18. end
  19. local backend = package:config("backend")
  20. if backend ~= "wincng" then
  21. package:add("deps", backend)
  22. end
  23. end)
  24. on_install("windows", function (package)
  25. local configs = {"-DBUILD_TESTING=OFF",
  26. "-DBUILD_EXAMPLES=OFF",
  27. "-DENABLE_ZLIB_COMPRESSION=ON"}
  28. local backend_name = {wincng = "WinCNG",
  29. openssl = "OpenSSL",
  30. mbedtls = "mbedTLS",
  31. libgcrypt = "Libgcrypt"}
  32. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  33. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  34. table.insert(configs, "-DCRYPTO_BACKEND=" .. backend_name[package:config("backend")])
  35. import("package.tools.cmake").install(package, configs)
  36. end)
  37. on_install("macosx", "linux", function (package)
  38. local configs = {"--disable-silent-rules",
  39. "--disable-examples-build",
  40. "--with-libz"}
  41. local lib_prefix = {openssl = "libssl",
  42. mbedtls = "libmbedcrypto",
  43. libgcrypt = "libgcrypt"}
  44. local backend = package:config("backend")
  45. table.insert(configs, "--with-crypto=" .. backend)
  46. local dep = package:dep(backend)
  47. if dep and not dep:is_system() then
  48. table.insert(configs, "--with-" .. lib_prefix[backend] .. "-prefix=" .. dep:installdir())
  49. end
  50. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  51. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  52. if package:is_plat("linux") and package:config("pic") ~= false then
  53. table.insert(configs, "--with-pic")
  54. end
  55. if package:gitref() then
  56. os.vrunv("sh", {"./buildconf"})
  57. end
  58. import("package.tools.autoconf").install(package, configs)
  59. end)
  60. on_test(function (package)
  61. assert(package:has_cfuncs("libssh2_exit", {includes = "libssh2.h"}))
  62. end)