diff options
| author | ruki <[email protected]> | 2017-06-13 10:35:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-13 10:35:12 +0800 |
| commit | a1304d43b58dcd7f0ee3a822781af8f67def640f (patch) | |
| tree | 04b7d6a1f4a1f427f46c6719310b5e5b6293705c | |
| parent | 3c2de8ed5b50203ebed47f774c51792ee8c4ae80 (diff) | |
match version for find_package()
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_package.lua | 36 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/pkg_config.lua | 13 |
3 files changed, 33 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c14cc6d6..46e94d2ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * [#83](https://github.com/tboox/xmake/issues/83): Add `add_csnippet` and `add_cxxsnippet` into `option` for detecting some compiler features. * [#83](https://github.com/tboox/xmake/issues/83): Add user extension modules to detect program, libraries and files. -* Add `find_program`, `find_file` and `find_library` module interfaces. +* Add `find_program`, `find_file`, `find_library` and `find_package` module interfaces. * Add `net.*` and `devel.*` extension modules * Add `val()` api to get the value of builtin-variable, .e.g `val("host")`, `val("env PATH")`, `val("shell echo hello")` and `val("reg HKEY_LOCAL_MACHINE\\XX;Value")` * Support to compile the microsoft resource file (.rc) @@ -304,7 +304,7 @@ * [#83](https://github.com/tboox/xmake/issues/83): 添加 `add_csnippet`,`add_cxxsnippet`到`option`来检测一些编译器特性 * [#83](https://github.com/tboox/xmake/issues/83): 添加用户扩展模块去探测程序,库文件以及其他主机环境 -* 添加`find_program`, `find_file` 和 `find_library` 等模块接口 +* 添加`find_program`, `find_file`, `find_library`和`find_package` 等模块接口 * 添加`net.*`和`devel.*`扩展模块 * 添加`val()`接口去获取内置变量,例如:`val("host")`, `val("env PATH")`, `val("shell echo hello")` and `val("reg HKEY_LOCAL_MACHINE\\XX;Value")` * 增加对微软.rc资源文件的编译支持,当在windows上编译时,可以增加资源文件了 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 a77601b50..2a54a1d36 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -66,21 +66,20 @@ end -- find package from pkg-config function sandbox_lib_detect_find_package._find_from_pkg_config(name, opt) - return pkg_config.find(name, {version = true}) + return pkg_config.find(name, opt) end -- find package from system directories function sandbox_lib_detect_find_package._find_from_systemdirs(name, opt) - -- get current platform - local plat = config.get("plat") or os.host() - - -- get current architecture - local arch = config.get("arch") or os.arch() + -- cannot get the version of package + if opt.version then + return + end -- add default search pathes on pc host local pathes = {} - if plat == "macosx" or (plat == "linux" and arch == os.arch()) then + 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") @@ -125,12 +124,20 @@ function sandbox_lib_detect_find_package._find(name, opt) sandbox_lib_detect_find_package._find_from_project_packagedirs , sandbox_lib_detect_find_package._find_from_repositories , sandbox_lib_detect_find_package._find_from_modules - , sandbox_lib_detect_find_package._find_from_pkg_config - , sandbox_lib_detect_find_package._find_from_systemdirs } - -- find it, TODO match version + -- init options opt = opt or {} + opt.plat = opt.plat or config.get("plat") or os.host() + opt.arch = opt.arch or config.get("arch") or os.arch() + + -- find package from the current host platform + if opt.plat == os.host() and opt.arch == os.arch() then + table.insert(findscripts, sandbox_lib_detect_find_package._find_from_pkg_config) + table.insert(findscripts, sandbox_lib_detect_find_package._find_from_systemdirs) + end + + -- find it for _, find in ipairs(findscripts) do local package = find(name, opt) if package then @@ -142,15 +149,16 @@ end -- find package -- -- @param name the package name --- @param opt the package options. e.g. {version = ">1.0.1", pathes = {"/usr/lib"}, links = {"ssl"}, includes = {"ssl.h"}} +-- @param opt the package options. e.g. {plat = "iphoneos", arch = "arm64", version = "1.0.1", pathes = {"/usr/lib"}, links = {"ssl"}, includes = {"ssl.h"}} -- --- @return {links = {"ssl", "crypto", "z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}, version = "1.0.2"} +-- @return {links = {"ssl", "crypto", "z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} -- -- @code -- -- local package = find_package("openssl") --- local package = find_package("openssl", {version = ">1.0.1"}) --- local package = find_package("openssl", {pathes = {"/usr/lib", "/usr/local/lib", "/usr/local/include"}, version = ">1.0.1"}) +-- 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"}}) -- -- @endcode diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkg_config.lua index 15cb2a391..5b595b50d 100644 --- a/xmake/modules/lib/detect/pkg_config.lua +++ b/xmake/modules/lib/detect/pkg_config.lua @@ -118,7 +118,7 @@ function info(name, opt) local version = try { function() return os.iorunv(pkg_config, {"--modversion", name}) end } if version then result = result or {} - result.version = version + result.version = version:trim() end end @@ -137,9 +137,9 @@ end -- find package -- -- @param name the package name --- @param opt the argument options, {version = true} +-- @param opt the argument options, {plat = "", arch = "", version = "1.0.1"} -- --- @return {links = {"ssl", "crypto", "z"}, linkdirs = {""}, includedirs = {""}, version = ""} +-- @return {links = {"ssl", "crypto", "z"}, linkdirs = {""}, includedirs = {""}} -- -- @code -- @@ -154,6 +154,12 @@ function find(name, opt) if not pkginfo then return end + + -- match version? + opt = opt or {} + if opt.version and pkginfo.version ~= opt.version then + return + end -- find library local result = nil @@ -168,7 +174,6 @@ function find(name, opt) -- found? if result and result.links then - result.version = pkginfo.version result.linkdirs = table.unique(result.linkdirs) result.includedirs = table.join(result.includedirs or {}, pkginfo.includedirs) end |
