xmake.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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", "wolfssl"}})
  11. if is_plat("windows", "mingw") then
  12. add_syslinks("bcrypt", "crypt32", "ws2_32")
  13. end
  14. add_deps("cmake")
  15. add_deps("zlib")
  16. on_load(function (package)
  17. local backend = package:config("backend")
  18. if backend ~= "wincng" then
  19. package:add("deps", backend)
  20. end
  21. if package:is_plat("windows") and package:config("shared") then
  22. package:add("defines", "LIBSSH2_EXPORTS")
  23. end
  24. end)
  25. on_install("!wasm and !iphoneos", function (package)
  26. local configs = {
  27. "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW",
  28. "-DBUILD_TESTING=OFF",
  29. "-DBUILD_EXAMPLES=OFF",
  30. "-DENABLE_ZLIB_COMPRESSION=ON",
  31. }
  32. local backend_name = {
  33. wincng = "WinCNG",
  34. openssl = "OpenSSL",
  35. mbedtls = "mbedTLS",
  36. libgcrypt = "Libgcrypt",
  37. wolfssl = "wolfSSL",
  38. }
  39. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  40. table.insert(configs, "-DENABLE_DEBUG_LOGGING=" .. (package:is_debug() and "ON" or "OFF"))
  41. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  42. table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
  43. local backend = package:config("backend")
  44. table.insert(configs, "-DCRYPTO_BACKEND=" .. backend_name[backend])
  45. if backend == "openssl" then
  46. local openssl = package:dep("openssl")
  47. if not openssl:is_system() then
  48. table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
  49. end
  50. end
  51. local opt = {}
  52. if package:is_plat("windows") then
  53. os.mkdir(path.join(package:buildir(), "src/pdb"))
  54. if backend == "mbedtls" then
  55. opt.packagedeps = backend
  56. end
  57. end
  58. import("package.tools.cmake").install(package, configs, opt)
  59. if package:is_plat("windows") and package:is_debug() then
  60. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  61. os.vcp(path.join(package:buildir(), "src/*.pdb"), dir)
  62. end
  63. end)
  64. on_test(function (package)
  65. assert(package:has_cfuncs("libssh2_exit", {includes = "libssh2.h"}))
  66. end)