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 /xmake | |
| parent | 3c2de8ed5b50203ebed47f774c51792ee8c4ae80 (diff) | |
match version for find_package()
Diffstat (limited to 'xmake')
| -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 |
2 files changed, 31 insertions, 18 deletions
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 |
