diff options
| author | ruki <[email protected]> | 2019-01-24 21:00:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-24 00:00:22 +0800 |
| commit | dd9e1bb88ec464edd6fa76a4ee63ad7a3a334314 (patch) | |
| tree | fe19e75cffe3d09f1bf33274412852aa8a84cd00 | |
| parent | b56c72c24a91c98cc11b83564b37bcea0c93cb79 (diff) | |
improve find_package
| -rw-r--r-- | xmake/modules/detect/packages/find_mbedtls.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/package/manager/brew/find_package.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/package/manager/system/find_package.lua | 62 |
3 files changed, 55 insertions, 39 deletions
diff --git a/xmake/modules/detect/packages/find_mbedtls.lua b/xmake/modules/detect/packages/find_mbedtls.lua index 98679cbfe..bd15c2b86 100644 --- a/xmake/modules/detect/packages/find_mbedtls.lua +++ b/xmake/modules/detect/packages/find_mbedtls.lua @@ -23,7 +23,7 @@ -- -- imports -import("lib.detect.pkg_config") +import("package.manager.find_package") -- find mbedtls -- @@ -32,9 +32,6 @@ import("lib.detect.pkg_config") -- @return see the return value of find_package() -- function main(opt) - - -- find package from the current host platform - if opt.plat == os.host() and opt.arch == os.arch() then - return pkg_config.find("mbedtls", {links = {"mbedtls", "mbedcrypto", "mbedx509"}}) - end + opt.links = {"mbedtls", "mbedcrypto", "mbedx509"} + return opt.find_package("mbedtls", opt) end diff --git a/xmake/modules/package/manager/brew/find_package.lua b/xmake/modules/package/manager/brew/find_package.lua index 988c162fa..7a77a7617 100644 --- a/xmake/modules/package/manager/brew/find_package.lua +++ b/xmake/modules/package/manager/brew/find_package.lua @@ -25,7 +25,7 @@ -- imports import("lib.detect.find_tool") import("lib.detect.find_file") -import("lib.detect.pkg_config") +import("package.manager.find_package") -- find package from the brew package manager -- @@ -47,12 +47,23 @@ function main(name, opt) -- find the prefix directory of brew local brew_pkg_root = try { function () return os.iorunv(brew.program, {"--prefix"}) end } or "/usr/local" brew_pkg_root = path.join(brew_pkg_root:trim(), opt.plat == "macosx" and "Cellar" or "opt") + + -- find package from pkg-config/*.pc + local result = nil local pcfile = find_file(pcname .. ".pc", path.join(brew_pkg_root, nameinfo[1], "*/lib/pkgconfig")) - if not pcfile then - return + if pcfile then + opt.configdirs = path.directory(pcfile) + result = find_package("pkg_config::" .. pcname, opt) end - -- do find - opt.configdirs = path.directory(pcfile) - return pkg_config.find(pcname, opt) + -- find package from xxx/lib, xxx/include + if not result then + local libfile = find_file("*.a", path.join(brew_pkg_root, nameinfo[1], "*", "lib")) + if libfile then + opt.linkdirs = path.directory(libfile) + opt.includedirs = path.join(path.directory(opt.linkdirs), "include") + result = find_package("system::" .. name, opt) + end + end + return result end diff --git a/xmake/modules/package/manager/system/find_package.lua b/xmake/modules/package/manager/system/find_package.lua index d03e2f4cb..480deae40 100644 --- a/xmake/modules/package/manager/system/find_package.lua +++ b/xmake/modules/package/manager/system/find_package.lua @@ -41,25 +41,29 @@ function main(name, opt) -- add default search includedirs on pc host local includedirs = table.wrap(opt.includedirs) - if opt.plat == "linux" or opt.plat == "macosx" then - table.insert(includedirs, "/usr/local/include") - table.insert(includedirs, "/usr/include") - table.insert(includedirs, "/opt/local/include") - table.insert(includedirs, "/opt/include") + if #includedirs == 0 then + if opt.plat == "linux" or opt.plat == "macosx" then + table.insert(includedirs, "/usr/local/include") + table.insert(includedirs, "/usr/include") + table.insert(includedirs, "/opt/local/include") + table.insert(includedirs, "/opt/include") + end end -- add default search linkdirs on pc host local linkdirs = table.wrap(opt.linkdirs) - if opt.plat == "linux" or opt.plat == "macosx" then - table.insert(linkdirs, "/usr/local/lib") - table.insert(linkdirs, "/usr/lib") - table.insert(linkdirs, "/opt/local/lib") - table.insert(linkdirs, "/opt/lib") - if opt.plat == "linux" and opt.arch == "x86_64" then - table.insert(linkdirs, "/usr/local/lib/x86_64-linux-gnu") - table.insert(linkdirs, "/usr/lib/x86_64-linux-gnu") - table.insert(linkdirs, "/usr/lib64") - table.insert(linkdirs, "/opt/lib64") + if #linkdirs == 0 then + if opt.plat == "linux" or opt.plat == "macosx" then + table.insert(linkdirs, "/usr/local/lib") + table.insert(linkdirs, "/usr/lib") + table.insert(linkdirs, "/opt/local/lib") + table.insert(linkdirs, "/opt/lib") + if opt.plat == "linux" and opt.arch == "x86_64" then + table.insert(linkdirs, "/usr/local/lib/x86_64-linux-gnu") + table.insert(linkdirs, "/usr/lib/x86_64-linux-gnu") + table.insert(linkdirs, "/usr/lib64") + table.insert(linkdirs, "/opt/lib64") + end end end @@ -92,20 +96,24 @@ function main(name, opt) end -- find includes - for _, include in ipairs(table.wrap(opt.includes)) do - local includedir = find_path(include, includedirs) - if includedir then - result = result or {} - result.includedirs = table.join(result.includedirs or {}, includedir) + if opt.includes then + for _, include in ipairs(opt.includes) do + local includedir = find_path(include, includedirs) + if includedir then + result = result or {} + result.includedirs = table.join(result.includedirs or {}, includedir) + end end - end - for _, include in ipairs({name .. "/" .. name .. ".h", name .. ".h"}) do - local includedir = find_path(include, includedirs) - if includedir then - result = result or {} - result.includedirs = table.join(result.includedirs or {}, includedir) - break + for _, include in ipairs({name .. "/" .. name .. ".h", name .. ".h"}) do + local includedir = find_path(include, includedirs) + if includedir then + result = result or {} + result.includedirs = table.join(result.includedirs or {}, includedir) + break + end end + elseif result and result.links and opt.includedirs then + result.includedirs = opt.includedirs end -- not found? only add links |
