fetch.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import("lib.detect.find_path")
  2. import("lib.detect.find_library")
  3. -- http://www.slproweb.com/products/Win32OpenSSL.html
  4. function _find_package_on_windows(package, opt)
  5. local bits = package:is_arch("x86") and "32" or "64"
  6. local paths = {"$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL %(" .. bits .. "-bit%)_is1;Inno Setup: App Path)",
  7. "$(env PROGRAMFILES)/OpenSSL-Win" .. bits,
  8. "C:/OpenSSL-Win" .. bits}
  9. if os.arch() == package:arch() then
  10. table.insert(paths, "$(env PROGRAMFILES)/OpenSSL")
  11. table.insert(paths, "C:/OpenSSL")
  12. end
  13. local result = {links = {}, linkdirs = {}, includedirs = {}}
  14. for _, name in ipairs({"libssl", "libcrypto"}) do
  15. local linkinfo = find_library(name, paths, {suffixes = "lib"})
  16. if linkinfo then
  17. table.insert(result.links, linkinfo.link)
  18. table.insert(result.linkdirs, linkinfo.linkdir)
  19. end
  20. end
  21. if #result.links ~= 2 then
  22. return
  23. end
  24. table.insert(result.includedirs, find_path(path.translate("openssl/ssl.h"), paths, {suffixes = "include"}))
  25. return result
  26. end
  27. function main(package, opt)
  28. if opt.system and package.find_package then
  29. local result
  30. if package:is_plat("windows", "mingw", "msys") and is_host("windows") then
  31. result = _find_package_on_windows(package, opt)
  32. else
  33. result = package:find_package("openssl", opt)
  34. end
  35. return result or false
  36. end
  37. end