xmake.lua 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package("libssh")
  2. set_homepage("https://www.libssh2.org/")
  3. set_description("C library implementing the SSH2 protocol")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://git.libssh.org/projects/libssh.git",
  6. "https://gitlab.com/libssh/libssh-mirror.git")
  7. add_urls("https://gitlab.com/libssh/libssh-mirror/-/archive/libssh-$(version)/libssh-mirror-libssh-$(version).tar.bz2", {alias = "gitlab"})
  8. add_urls("https://www.libssh.org/files/$(version).tar.xz", {
  9. alias = "home",
  10. version = function (version)
  11. return format("%d.%d/libssh-%s", version:major(), version:minor(), version)
  12. end
  13. })
  14. add_versions("home:0.11.1", "14b7dcc72e91e08151c58b981a7b570ab2663f630e7d2837645d5a9c612c1b79")
  15. add_versions("gitlab:0.11.1", "7d0d064b7d44420036f410d4dd3f05ad6ada61d21314d1e9d424a2e9970d1b68")
  16. add_configs("zlib", {description = "Build with zlib", default = false, type = "boolean"})
  17. add_configs("backend", {description = "Select crypto backend.", default = (is_plat("wasm", "iphoneos") and "mbedtls" or "openssl"), type = "string", values = {"openssl", "mbedtls", "libgcrypt"}})
  18. if is_plat("windows", "mingw") then
  19. add_syslinks("iphlpapi", "shell32")
  20. elseif is_plat("linux", "bsd") then
  21. add_syslinks("pthread")
  22. end
  23. add_deps("cmake")
  24. on_load(function (package)
  25. if package:config("zlib") then
  26. package:add("deps", "zlib")
  27. end
  28. package:add("deps", package:config("backend"))
  29. if package:is_plat("windows", "mingw") and not package:config("shared") then
  30. package:add("defines", "LIBSSH_STATIC")
  31. end
  32. end)
  33. on_install("!android", function (package)
  34. io.replace("src/CMakeLists.txt", "iphlpapi", "iphlpapi\ncrypt32", {plain = true})
  35. local configs = {
  36. "-DWITH_EXAMPLES=OFF",
  37. "-DWITH_GSSAPI=OFF",
  38. "-DWITH_NACL=OFF",
  39. }
  40. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  41. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  42. local backend = package:config("backend")
  43. table.insert(configs, "-DWITH_ZLIB=" .. (package:config("zlib") and "ON" or "OFF"))
  44. table.insert(configs, "-DWITH_MBEDTLS=" .. (backend == "mbedtls" and "ON" or "OFF"))
  45. table.insert(configs, "-DWITH_GCRYPT=" .. (backend == "libgcrypt" and "ON" or "OFF"))
  46. local openssl = package:dep("openssl")
  47. if openssl then
  48. if not openssl:is_system() then
  49. table.insert(configs, "-DOPENSSL_ROOT_DIR=" .. openssl:installdir())
  50. end
  51. end
  52. if package:is_plat("windows") then
  53. os.mkdir(path.join(package:buildir(), "src/pdb"))
  54. end
  55. import("package.tools.cmake").install(package, configs)
  56. if package:is_plat("windows") and package:is_debug() then
  57. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  58. os.vcp(path.join(package:buildir(), "src/*.pdb"), dir)
  59. end
  60. end)
  61. on_test(function (package)
  62. assert(package:has_cfuncs("ssh_init", {includes = "libssh/libssh.h"}))
  63. end)