xmake.lua 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.11.1", "d9ec76cbe34db98eec3539fe2c899d26b0c837cb3eb466a56b0f109cabf658f7")
  9. add_versions("1.11.0", "3736161e41e2693324deb38c26cfdc3efe6209d634ba4258db1cecff6a5ad461")
  10. add_versions("1.10.0", "2d64e90f3ded394b91d3a2e774ca203a4179f69aebee03003e5a6fa621e41d51")
  11. add_configs("backend", {description = "Select crypto backend.", default = (is_plat("windows") and "wincng" or "openssl"), type = "string", values = {"openssl", "openssl3", "wincng", "mbedtls", "libgcrypt", "wolfssl"}})
  12. if is_plat("windows", "mingw") then
  13. add_syslinks("bcrypt", "crypt32", "ws2_32")
  14. end
  15. add_deps("cmake")
  16. add_deps("zlib")
  17. on_load(function (package)
  18. local backend = package:config("backend")
  19. if backend ~= "wincng" then
  20. package:add("deps", backend)
  21. end
  22. if package:is_plat("windows") and package:config("shared") then
  23. package:add("defines", "LIBSSH2_API=__declspec(dllimport)")
  24. end
  25. end)
  26. on_install("!wasm and !iphoneos", function (package)
  27. local configs = {
  28. "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW",
  29. "-DBUILD_TESTING=OFF",
  30. "-DBUILD_EXAMPLES=OFF",
  31. "-DENABLE_ZLIB_COMPRESSION=ON",
  32. }
  33. local backend_name = {
  34. wincng = "WinCNG",
  35. openssl = "OpenSSL",
  36. openssl3 = "OpenSSL",
  37. mbedtls = "mbedTLS",
  38. libgcrypt = "Libgcrypt",
  39. wolfssl = "wolfSSL",
  40. }
  41. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  42. table.insert(configs, "-DENABLE_DEBUG_LOGGING=" .. (package:is_debug() and "ON" or "OFF"))
  43. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  44. table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
  45. local backend = package:config("backend")
  46. table.insert(configs, "-DCRYPTO_BACKEND=" .. backend_name[backend])
  47. if backend == "openssl" or backend == "openssl3" then
  48. local openssl = package:dep(backend)
  49. if not openssl:is_system() then
  50. table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
  51. end
  52. end
  53. local opt = {}
  54. if package:is_plat("windows") then
  55. if backend == "mbedtls" then
  56. opt.packagedeps = backend
  57. end
  58. local version = package:version()
  59. if version and version:le("1.10.0") and package:config("shared") then
  60. opt.cxflags = "-D_WINDLL"
  61. end
  62. end
  63. import("package.tools.cmake").install(package, configs, opt)
  64. end)
  65. on_test(function (package)
  66. assert(package:has_cfuncs("libssh2_exit", {includes = "libssh2.h"}))
  67. end)