fetch.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import("lib.detect.find_path")
  2. import("lib.detect.find_file")
  3. import("lib.detect.find_library")
  4. import("core.base.semver")
  5. -- http://www.slproweb.com/products/Win32OpenSSL.html
  6. function _find_package_on_windows(package, opt)
  7. local bits = package:is_plat("x86") and "32" or "64"
  8. local paths = {"$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL %(" .. bits .. "-bit%)_is1;Inno Setup: App Path)",
  9. "$(env PROGRAMFILES)/OpenSSL",
  10. "$(env PROGRAMFILES)/OpenSSL-Win" .. bits,
  11. "C:/OpenSSL",
  12. "C:/OpenSSL-Win" .. bits}
  13. local result = {links = {}, linkdirs = {}}
  14. local suffix = package:config("shared") and "" or "_static"
  15. for _, name in ipairs({"libssl" .. suffix, "libcrypto" .. suffix}) do
  16. local linkinfo = find_library(name, paths, {suffixes = "lib"})
  17. if linkinfo then
  18. table.insert(result.links, linkinfo.link)
  19. table.insert(result.linkdirs, linkinfo.linkdir)
  20. end
  21. end
  22. if #result.links == 0 then
  23. -- find light package
  24. local arch = package:arch()
  25. for _, name in ipairs({"libssl-3-" .. arch, "libcrypto-3-" .. arch}) do
  26. local linkinfo = find_library(name, paths)
  27. if linkinfo then
  28. table.insert(result.links, linkinfo.link)
  29. table.insert(result.linkdirs, linkinfo.linkdir)
  30. end
  31. end
  32. end
  33. if #result.links ~= 2 then
  34. return
  35. end
  36. if result.linkdirs then
  37. result.linkdirs = table.unique(result.linkdirs)
  38. end
  39. local includedir = find_path(path.translate("openssl/ssl.h"), paths, {suffixes = "include"})
  40. if includedir then
  41. result.includedirs = result.includedirs or {}
  42. table.insert(result.includedirs, includedir)
  43. end
  44. local openssl = find_file("openssl.exe", paths, {suffixes = "bin"})
  45. if openssl then
  46. local version = try {function () return os.iorunv(openssl, {"version"}) end}
  47. if version then
  48. version = semver.match(version)
  49. if version then
  50. result.version = version:rawstr()
  51. end
  52. end
  53. end
  54. return result
  55. end
  56. function main(package, opt)
  57. if opt.system and package.find_package then
  58. local result
  59. if package:is_plat("windows", "mingw", "msys") and is_host("windows") then
  60. result = _find_package_on_windows(package, opt)
  61. else
  62. result = package:find_package("openssl", opt)
  63. end
  64. return result or false
  65. end
  66. end