diff options
| author | ruki <[email protected]> | 2018-10-04 00:46:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-10-03 22:41:37 +0800 |
| commit | 922a1f5d89ddd79f9413bd4fa4c98903cfc2bdde (patch) | |
| tree | 11faff854b885f848eff888bc135cdb0c82ac2e8 | |
| parent | 9b4d2611b05065bfc0c9ac8a7b3c1e80cedb7e82 (diff) | |
improve
| -rw-r--r-- | xmake/core/package/package.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_package.lua | 29 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/pkg_config.lua | 25 |
3 files changed, 32 insertions, 24 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 5215154ef..43c7971df 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -236,7 +236,7 @@ end -- get the prefix info file function _instance:prefixfile() - return path.join(self:prefixdir(".info"), self:name() .. "-" .. (self:version_str() or "") .. ".txt") + return path.join(self:installdir(), "prefixinfo.txt") end -- get prefix variables 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 9f458a808..57d57d6d1 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -138,13 +138,18 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) -- get prefix directories local prefixdirs = table.wrap(opt.prefixdirs) + local platsubdirs = path.join(config.get("plat") or os.host(), config.get("arch") or os.arch(), "release") if #prefixdirs == 0 then - table.insert(prefixdirs, path.join(config.directory(), "prefix", config.get("plat") or os.host(), config.get("arch") or os.arch(), "release")) - table.insert(prefixdirs, path.join(global.directory(), "prefix", config.get("plat") or os.host(), config.get("arch") or os.arch(), "release")) + table.insert(prefixdirs, path.join(config.directory(), "prefix", platsubdirs)) + table.insert(prefixdirs, path.join(global.directory(), "prefix", platsubdirs)) end - -- find the package list file, .e.g zlib-1.2.11.txt - local prefixfile = find_file(name .. "-*.txt", prefixdirs, {suffixes = ".info"}) + -- find the prefix info file of package, .e.g z/zlib/1.2.11/prefixinfo.txt + local packagedirs = {} + local packagepath = path.join(name:sub(1, 1), name, "*") + table.insert(packagedirs, path.join(config.directory(), "installed", platsubdirs, packagepath)) + table.insert(packagedirs, path.join(global.directory(), "installed", platsubdirs, packagepath)) + local prefixfile = find_file("prefixinfo.txt", packagedirs) -- get the include and link directories local links = {} @@ -153,10 +158,6 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) local prefixinfo = {} if prefixfile then - -- get prefix root directory - local prefixdir = path.directory(path.directory(prefixfile)) - - -- add given include and link directories prefixinfo = io.load(prefixfile) or {} for _, includedir in ipairs(table.wrap(prefixinfo.includedirs)) do table.insert(includedirs, path.join(prefixdir, includedir)) @@ -199,13 +200,14 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) end end end + end - -- add root include and link directories - table.insert(linkdirs, path.join(prefixdir, "lib")) - table.insert(includedirs, path.join(prefixdir, "include")) - else - for _, prefixdir in ipairs(prefixdirs) do + -- add root include and link directories + for _, prefixdir in ipairs(prefixdirs) do + if #linkdirs == 0 then table.insert(linkdirs, path.join(prefixdir, "lib")) + end + if #includedirs == 0 then table.insert(includedirs, path.join(prefixdir, "include")) end end @@ -219,7 +221,6 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) local find_library = import("lib.detect.find_library") -- find library - local result = nil for _, link in ipairs(links) do local libinfo = find_library(link, linkdirs) if libinfo then diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkg_config.lua index 965879f4c..3b3a6658b 100644 --- a/xmake/modules/lib/detect/pkg_config.lua +++ b/xmake/modules/lib/detect/pkg_config.lua @@ -23,7 +23,9 @@ -- -- imports +import("core.base.global") import("core.project.target") +import("core.project.config") import("lib.detect.find_file") import("lib.detect.find_library") import("detect.tools.find_brew") @@ -60,28 +62,33 @@ function info(name, opt) return result and result or nil end + -- add PKG_CONFIG_PATH + local configdirs_old = os.getenv("PKG_CONFIG_PATH") + local configdirs = opt.configdirs or {} + if #configdirs > 0 then + os.addenv("PKG_CONFIG_PATH", unpack(configdirs)) + end + -- attempt to find package without `brew --prefix` first local flags = try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end } -- attempt to get pkg-config path from `brew --prefix` if no flags local brewprefix = nil - local configdirs = opt.configdirs or {} if not flags then + + -- find the config directories from the prefix directories of xmake + local platsubdirs = path.join(config.get("plat") or os.host(), config.get("arch") or os.arch(), "release") + os.addenv("PKG_CONFIG_PATH", path.join(config.directory(), "prefix", platsubdirs, "lib", "pkgconfig")) + os.addenv("PKG_CONFIG_PATH", path.join(global.directory(), "prefix", platsubdirs, "lib", "pkgconfig")) + -- find the prefix directory of brew directly, because `brew --prefix name` is too slow! local pcfile = find_file("*.pc", "/usr/local/Cellar/" .. name .. "/*/lib/pkgconfig") if pcfile then brewprefix = path.directory(path.directory(path.directory(pcfile))) - table.insert(configdirs, path.directory(pcfile)) + os.addenv("PKG_CONFIG_PATH", path.directory(pcfile)) end end - -- add PKG_CONFIG_PATH - local configdirs_old = nil - if #configdirs > 0 then - configdirs_old = os.getenv("PKG_CONFIG_PATH") - os.addenv("PKG_CONFIG_PATH", unpack(configdirs)) - end - -- get libs and cflags flags = flags or try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end } if flags then |
