diff options
| author | ruki <[email protected]> | 2017-06-13 15:42:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-13 15:42:12 +0800 |
| commit | 48529599248c9bdd43b53def4be7113d226060ef (patch) | |
| tree | 077dd731acedc2dbb61e42f8af665677dd56861a | |
| parent | c0943c86f7ce1ae303e4ba909d29a11f750a9cda (diff) | |
impl find_openssl for windows
6 files changed, 108 insertions, 37 deletions
diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 7e8438b8d..023166f69 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -315,9 +315,6 @@ end -- remove repeat from the given array function table.unique(array) - -- check - assert(array) - -- remove repeat if type(array) == "table" then diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua index ae61faa40..e647f1869 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua @@ -36,7 +36,8 @@ local vformat = require("sandbox/modules/vformat") -- find file -- -- @param name the file name --- @param pathes the program pathes (.e.g dirs, pathes, winreg pathes) +-- @param pathes the search pathes (.e.g dirs, pathes, winreg pathes) +-- @param opt the options, .e.g {suffixes = {"/aa", "/bb"}} -- -- @return the file path -- @@ -49,11 +50,29 @@ local vformat = require("sandbox/modules/vformat") -- -- @endcode -- -function sandbox_lib_detect_find_file.main(name, pathes) +function sandbox_lib_detect_find_file.main(name, pathes, opt) + + -- init options + opt = opt or {} + + -- init pathes + pathes = table.wrap(pathes) + + -- append suffixes to pathes + local suffixes = table.wrap(opt.suffixes) + if #suffixes > 0 then + local pathes_new = {} + for _, parent in ipairs(pathes) do + for _, suffix in ipairs(suffixes) do + table.insert(pathes_new, path.join(parent, suffix)) + end + end + pathes = pathes_new + end -- find file local result = nil - for _, _path in ipairs(table.wrap(pathes)) do + for _, _path in ipairs(pathes) do -- format path for builtin variables if type(_path) == "function" then diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_library.lua b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua index ded3a191d..fbf3cf3c6 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_library.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua @@ -53,30 +53,30 @@ end -- find library -- -- @param names the library names --- @param pathes the library pathes --- @param kinds the library kinds, .e.g {"static", "shared"} +-- @param pathes the search pathes +-- @param opt the options, .e.g {kind = "static/shared", suffixes = {"/aa", "/bb"}} -- -- @return {kind = "static", link = "crypto", linkdir = "/usr/local/lib", filename = "libcrypto.a"} -- -- @code -- --- local library = find_library("crypto") -- local library = find_library({"crypto", "cryp*"}, {"/usr/lib", "/usr/local/lib"}) +-- local library = find_library(crypto, {"/usr/lib", "/usr/local/lib"}, {kind = "static"}) -- -- @endcode -- -function sandbox_lib_detect_find_library.main(names, pathes, kinds) +function sandbox_lib_detect_find_library.main(names, pathes, opt) - -- init pathes - pathes = table.wrap(pathes) + -- init options + opt = opt or {} -- init kinds - kinds = kinds or {"static", "shared"} + kinds = opt.kind or {"static", "shared"} -- find library file from the given pathes for _, name in ipairs(table.wrap(names)) do for _, kind in ipairs(table.wrap(kinds)) do - local filepath = find_file(target.filename(name, kind), pathes) + local filepath = find_file(target.filename(name, kind), pathes, opt) if filepath then local filename = path.filename(filepath) return {kind = kind, filename = filename, linkdir = path.directory(filepath), link = sandbox_lib_detect_find_library._link(filename)} diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua index a5284ec89..98c233392 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -106,11 +106,6 @@ function sandbox_lib_detect_find_package._find_from_systemdirs(name, opt) end end - -- found? - if result and result.links then - result.linkdirs = table.unique(result.linkdirs) - end - -- ok return result end @@ -133,12 +128,22 @@ function sandbox_lib_detect_find_package._find(name, opt) end -- find it + local result = nil for _, find in ipairs(findscripts) do - local package = find(name, opt) - if package then - return package + result = find(name, opt) + if result then + break end end + + -- remove repeat + if result then + result.linkdirs = table.unique(result.linkdirs) + result.includedirs = table.unique(result.includedirs) + end + + -- ok? + return result end -- find package diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua index 2b94b33fc..bb5a7d280 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua @@ -35,24 +35,45 @@ local vformat = require("sandbox/modules/vformat") -- find path -- -- @param name the path name --- @param pathes the program pathes (.e.g dirs, pathes, winreg pathes) +-- @param pathes the search pathes (.e.g dirs, pathes, winreg pathes) +-- @param opt the options, .e.g {suffixes = {"/aa", "/bb"}} -- -- @return the path -- -- @code -- -- local p = find_path("include/test.h", { "/usr", "/usr/local"}) +-- -> /usr/local ("/usr/local/include/test.h") +-- -- local p = find_path("include/*.h", { "/usr", "/usr/local/**"}) -- local p = find_path("lib/xxx", { "$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name)"}) -- local p = find_path("lib/xxx", { "$(env PATH)", function () return val("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name"):match("\"(.-)\"") end}) -- -- @endcode -- -function sandbox_lib_detect_find_path.main(name, pathes) +function sandbox_lib_detect_find_path.main(name, pathes, opt) + + -- init options + opt = opt or {} + + -- init pathes + pathes = table.wrap(pathes) + + -- append suffixes to pathes + local suffixes = table.wrap(opt.suffixes) + if #suffixes > 0 then + local pathes_new = {} + for _, parent in ipairs(pathes) do + for _, suffix in ipairs(suffixes) do + table.insert(pathes_new, path.join(parent, suffix)) + end + end + pathes = pathes_new + end -- find file local result = nil - for _, _path in ipairs(table.wrap(pathes)) do + for _, _path in ipairs(pathes) do -- format path for builtin variables if type(_path) == "function" then @@ -66,17 +87,9 @@ function sandbox_lib_detect_find_path.main(name, pathes) _path = vformat(_path) end - -- get file path - local filepath = nil - if os.isfile(_path) then - filepath = _path - else - filepath = path.join(_path, name) - end - -- path exists? - for _, p in ipairs(os.filedirs(filepath)) do - result = p + for _, p in ipairs(os.filedirs(path.join(_path, name))) do + result = _path break end diff --git a/xmake/modules/detect/package/find_openssl.lua b/xmake/modules/detect/package/find_openssl.lua index fb1af8c6a..7dd344d53 100644 --- a/xmake/modules/detect/package/find_openssl.lua +++ b/xmake/modules/detect/package/find_openssl.lua @@ -23,7 +23,7 @@ -- -- imports -import("lib.detect.find_file") +import("lib.detect.find_path") import("lib.detect.find_library") -- find openssl @@ -33,5 +33,42 @@ import("lib.detect.find_library") -- @return see the return value of find_package() -- function main(opt) - -- TODO + + -- for windows platform + -- + -- http://www.slproweb.com/products/Win32OpenSSL.html + -- + if opt.plat == "windows" then + + -- init bits + local bits = ifelse(opt.arch == "x64", "64", "32") + + -- init search pathes + local pathes = {"$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (" .. bits .. "-bit)_is1;Inno Setup: App Path)", + "$(env PROGRAMFILES)/OpenSSL", + "$(env PROGRAMFILES)/OpenSSL-Win" .. bits, + "C:/OpenSSL", + "C:/OpenSSL-Win" .. bits} + + -- find library + local result = {links = {}, linkdirs = {}, includedirs = {}} + for _, name in ipairs({"libssl", "libcrypto"}) do + local linkinfo = find_library(name, pathes, {suffixes = "lib"}) + if linkinfo then + table.insert(result.links, linkinfo.link) + table.insert(result.linkdirs, linkinfo.linkdir) + end + end + + -- not found? + if #result.links ~= 2 then + return + end + + -- find include + table.insert(result.includedirs, find_path("openssl/ssl.h", pathes, {suffixes = "include"})) + + -- ok + return result + end end |
