summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-08-02 09:11:34 +0800
committerruki <[email protected]>2017-08-02 09:11:34 +0800
commitac57c89fa7eaee01b8b92d0c6020ba8ff789458b (patch)
treeb9793b75e09effb4e1022d5242117ba361c8cae1
parent3e475513ba214e80ef524df95d5c315418f2a798 (diff)
improve find_package
-rw-r--r--docs/manual.md2
-rw-r--r--docs/zh/manual.md2
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_library.lua5
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_package.lua66
4 files changed, 56 insertions, 19 deletions
diff --git a/docs/manual.md b/docs/manual.md
index d9b1daa6d..625b6d6ec 100644
--- a/docs/manual.md
+++ b/docs/manual.md
@@ -6138,7 +6138,7 @@ local package = find_package("openssl", {version = "1.0.1"})
如果系统的库目录以及`pkg-config`都不能满足需求,找不到包,那么可以自己手动设置搜索路径:
```lua
-local package = find_package("openssl", {pathes = {"/usr/lib", "/usr/local/lib", "/usr/local/include"}})
+local package = find_package("openssl", {linkdirs = {"/usr/lib", "/usr/local/lib"}, includedirs = "/usr/local/include"})
```
也可以同时指定需要搜索的链接名,头文件名:
diff --git a/docs/zh/manual.md b/docs/zh/manual.md
index a35280d3c..c1737aa62 100644
--- a/docs/zh/manual.md
+++ b/docs/zh/manual.md
@@ -6157,7 +6157,7 @@ local package = find_package("openssl", {version = "1.0.1"})
如果系统的库目录以及`pkg-config`都不能满足需求,找不到包,那么可以自己手动设置搜索路径:
```lua
-local package = find_package("openssl", {pathes = {"/usr/lib", "/usr/local/lib", "/usr/local/include"}})
+local package = find_package("openssl", {linkdirs = {"/usr/lib", "/usr/local/lib"}, includedirs = "/usr/local/include"})
```
也可以同时指定需要搜索的链接名,头文件名:
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 76d4e857e..af4086599 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_library.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua
@@ -67,6 +67,11 @@ end
--
function sandbox_lib_detect_find_library.main(names, pathes, opt)
+ -- no pathes?
+ if not pathes or #pathes == 0 then
+ return
+ end
+
-- init options
opt = opt or {}
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 b30a337af..cc8eaf429 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua
@@ -160,36 +160,51 @@ function sandbox_lib_detect_find_package._find_from_systemdirs(name, opt)
return
end
- -- add default search pathes on pc host
- local pathes = {}
+ -- add default search includedirs on pc host
+ local includedirs = table.wrap(opt.includedirs)
if opt.plat == "linux" or opt.plat == "macosx" then
- table.insert(pathes, "/usr/local/lib")
- table.insert(pathes, "/usr/lib")
- table.insert(pathes, "/opt/local/lib")
- table.insert(pathes, "/opt/lib")
+ table.insert(includedirs, "/usr/local/include")
+ table.insert(includedirs, "/usr/include")
+ table.insert(includedirs, "/opt/local/include")
+ table.insert(includedirs, "/opt/include")
+ 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(pathes, "/usr/local/lib/x86_64-linux-gnu")
- table.insert(pathes, "/usr/lib/x86_64-linux-gnu")
+ table.insert(linkdirs, "/usr/local/lib/x86_64-linux-gnu")
+ table.insert(linkdirs, "/usr/lib/x86_64-linux-gnu")
end
end
-- attempt to get links from pkg-config
local pkginfo = nil
- local links = opt.links
- if not links then
+ local links = table.wrap(opt.links)
+ if #links == 0 then
pkginfo = import("lib.detect.pkg_config").info(name)
if pkginfo then
- links = pkginfo.links
+ links = table.wrap(pkginfo.links)
end
end
- -- import find_library
+ -- uses name as links directly .e.g libname.a
+ if #links == 0 then
+ links = table.wrap(name)
+ end
+
+ -- import find_path and find_library
+ local find_path = import("lib.detect.find_path")
local find_library = import("lib.detect.find_library")
-- find library
local result = nil
- for _, link in ipairs(table.wrap(links)) do
- local libinfo = find_library(link, pathes)
+ for _, link in ipairs(links) do
+ local libinfo = find_library(link, linkdirs)
if libinfo then
result = result or {}
result.links = table.join(result.links or {}, libinfo.link)
@@ -197,6 +212,23 @@ function sandbox_lib_detect_find_package._find_from_systemdirs(name, opt)
end
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)
+ 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
+ end
+ end
+
-- not found? only add links
if not result and pkginfo and pkginfo.links then
result = {links = pkginfo.links}
@@ -247,7 +279,7 @@ end
-- @param name the package name
-- @param opt the package options.
-- e.g. { verbose = false, force = false, plat = "iphoneos", arch = "arm64", mode = "debug", version = "1.0.1",
--- pathes = {"/usr/lib"}, links = {"ssl"}, includes = {"ssl.h"}
+-- linkdirs = {"/usr/lib"}, includedirs = "/usr/include", links = {"ssl"}, includes = {"ssl.h"}
-- packagedirs = {"/tmp/packages"}}
--
-- @return {links = {"ssl", "crypto", "z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}
@@ -257,8 +289,8 @@ end
-- local package = find_package("openssl")
-- local package = find_package("openssl", {version = "1.0.1"})
-- local package = find_package("openssl", {plat = "iphoneos"})
--- local package = find_package("openssl", {pathes = {"/usr/lib", "/usr/local/lib", "/usr/local/include"}, version = "1.0.1"})
--- local package = find_package("openssl", {pathes = {"/usr/lib", "/usr/local/lib", "/usr/local/include"}, links = {"ssl", "crypto"}, includes = {"ssl.h"}})
+-- local package = find_package("openssl", {linkdirs = {"/usr/lib", "/usr/local/lib"}, includedirs = "/usr/local/include", version = "1.0.1"})
+-- local package = find_package("openssl", {linkdirs = {"/usr/lib", "/usr/local/lib", links = {"ssl", "crypto"}, includes = {"ssl.h"}})
--
-- @endcode
--