summaryrefslogtreecommitdiff
path: root/xmake/modules/lib
diff options
context:
space:
mode:
authorÂngelo Andrade Cirino <[email protected]>2022-01-10 10:23:17 -0300
committerÂngelo Andrade Cirino <[email protected]>2022-01-10 10:23:17 -0300
commited0c0c5e0249aa966ea7061b30710abdd0b09d87 (patch)
tree2a51c869a3aea1a093ed569e749bdf0465634a6c /xmake/modules/lib
parent885d00da8caf74aeed758d030b9a1b50d9078e1f (diff)
parent2431dd7e6142ff98b55741cfd4de4d2e69f4f8b5 (diff)
Merged from upstream/master
Diffstat (limited to 'xmake/modules/lib')
-rw-r--r--xmake/modules/lib/detect/check_cxsnippets.lua59
-rw-r--r--xmake/modules/lib/detect/features.lua5
-rw-r--r--xmake/modules/lib/detect/find_package.lua29
-rw-r--r--xmake/modules/lib/detect/pkgconfig.lua20
4 files changed, 86 insertions, 27 deletions
diff --git a/xmake/modules/lib/detect/check_cxsnippets.lua b/xmake/modules/lib/detect/check_cxsnippets.lua
index aa728e27b..ea0e941d3 100644
--- a/xmake/modules/lib/detect/check_cxsnippets.lua
+++ b/xmake/modules/lib/detect/check_cxsnippets.lua
@@ -77,7 +77,11 @@ function _sourcecode(snippets, opt)
-- add includes
local sourcecode = ""
- for _, include in ipairs(opt.includes) do
+ local includes = table.wrap(opt.includes)
+ if opt.tryrun and opt.output then
+ table.insert(includes, "stdio.h")
+ end
+ for _, include in ipairs(includes) do
sourcecode = format("%s\n#include <%s>", sourcecode, include)
end
sourcecode = sourcecode .. "\n"
@@ -88,11 +92,13 @@ function _sourcecode(snippets, opt)
end
sourcecode = sourcecode .. "\n"
- -- add snippets
- for _, snippet in pairs(snippets) do
- sourcecode = sourcecode .. "\n" .. snippet
+ -- add snippets (build only)
+ if not opt.tryrun then
+ for _, snippet in pairs(snippets) do
+ sourcecode = sourcecode .. "\n" .. snippet
+ end
+ sourcecode = sourcecode .. "\n"
end
- sourcecode = sourcecode .. "\n"
-- enter main function
sourcecode = sourcecode .. "int main(int argc, char** argv)\n{\n"
@@ -102,10 +108,19 @@ function _sourcecode(snippets, opt)
sourcecode = format("%s\n %s;", sourcecode, _funccode(funcinfo))
end
- -- leave main function
- sourcecode = sourcecode .. "\n return 0;\n}\n"
-
- -- done
+ -- add snippets (tryrun)
+ if opt.tryrun then
+ for _, snippet in pairs(snippets) do
+ sourcecode = sourcecode .. "\n" .. snippet
+ end
+ if opt.output then
+ sourcecode = sourcecode .. "\nfflush(stdout);\n"
+ end
+ sourcecode = sourcecode .. "\n}\n" -- we need return exit code in snippet
+ else
+ -- leave main function
+ sourcecode = sourcecode .. "\n return 0;\n}\n"
+ end
return sourcecode
end
@@ -116,7 +131,8 @@ end
-- e.g.
-- { verbose = false, target = [target|option], sourcekind = "[cc|cxx]"
-- , types = {"wchar_t", "char*"}, includes = "stdio.h", funcs = {"sigsetjmp", "sigsetjmp((void*)0, 0)"}
--- , configs = {defines = "xx", cxflags = ""}}
+-- , configs = {defines = "xx", cxflags = ""}
+-- , tryrun = true, output = true}
--
-- funcs:
-- sigsetjmp
@@ -127,9 +143,9 @@ end
-- @return true or false
--
-- @code
--- local ok = check_cxsnippets("void test() {}")
--- local ok = check_cxsnippets({"void test(){}", "#define TEST 1"}, {types = "wchar_t", includes = "stdio.h"})
--- local ok = check_cxsnippets({snippet_name = "void test(){}", "#define TEST 1"}, {types = "wchar_t", includes = "stdio.h"})
+-- local ok, output_or_errors = check_cxsnippets("void test() {}")
+-- local ok, output_or_errors = check_cxsnippets({"void test(){}", "#define TEST 1"}, {types = "wchar_t", includes = "stdio.h"})
+-- local ok, output_or_errors = check_cxsnippets({snippet_name = "void test(){}", "#define TEST 1"}, {types = "wchar_t", includes = "stdio.h"})
-- @endcode
--
function main(snippets, opt)
@@ -189,19 +205,30 @@ function main(snippets, opt)
-- @note cannot cache result, all conditions will be changed
-- attempt to compile it
local errors = nil
- local ok = try
+ local ok, output = try
{
function ()
if option.get("diagnosis") then
cprint("${dim}> %s", compiler.compcmd(sourcefile, objectfile, opt))
end
compiler.compile(sourcefile, objectfile, opt)
- if #links > 0 then
+ if #links > 0 or opt.tryrun then
if option.get("diagnosis") then
cprint("${dim}> %s", linker.linkcmd("binary", {"cc", "cxx"}, objectfile, binaryfile, opt))
end
linker.link("binary", {"cc", "cxx"}, objectfile, binaryfile, opt)
end
+ if opt.tryrun then
+ if opt.output then
+ local output = os.iorun(binaryfile)
+ if output then
+ output = output:trim()
+ end
+ return true, output
+ else
+ os.vrun(binaryfile)
+ end
+ end
return true
end,
catch { function (errs) errors = errs end }
@@ -238,6 +265,6 @@ function main(snippets, opt)
if errors and option.get("diagnosis") and #tostring(errors) > 0 then
cprint("${color.warning}checkinfo:${clear dim} %s", errors)
end
- return ok
+ return ok, ok and output or errors
end
diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua
index 614d8c592..8b9bde45b 100644
--- a/xmake/modules/lib/detect/features.lua
+++ b/xmake/modules/lib/detect/features.lua
@@ -79,12 +79,7 @@ function main(name, opt)
end
_g._checking = nil
- -- no features?
result = result or {}
-
- -- save result to cache
results[key] = result
-
- -- ok?
return result
end
diff --git a/xmake/modules/lib/detect/find_package.lua b/xmake/modules/lib/detect/find_package.lua
index 7b7ba7032..d3c9e57d1 100644
--- a/xmake/modules/lib/detect/find_package.lua
+++ b/xmake/modules/lib/detect/find_package.lua
@@ -24,6 +24,30 @@ import("core.project.config")
import("core.cache.detectcache")
import("package.manager.find_package")
+-- concat packages
+function _concat_packages(a, b)
+ local result = table.copy(a)
+ for k, v in pairs(b) do
+ local o = result[k]
+ if o ~= nil then
+ v = table.join(o, v)
+ end
+ result[k] = v
+ end
+ for k, v in pairs(result) do
+ if k == "links" then
+ if type(v) == "table" and #v > 1 then
+ -- we need ensure link orders when removing repeat values
+ v = table.reverse_unique(v)
+ end
+ else
+ v = table.unique(v)
+ end
+ result[k] = v
+ end
+ return result
+end
+
-- find package using the package manager
--
-- @param name the package name
@@ -113,5 +137,10 @@ function main(name, opt)
if not opt.version and result then
result.version = nil
end
+
+ -- register concat
+ if result and type(result) == "table" then
+ debug.setmetatable(result, {__concat = _concat_packages})
+ end
return result and result or nil
end
diff --git a/xmake/modules/lib/detect/pkgconfig.lua b/xmake/modules/lib/detect/pkgconfig.lua
index 9cd07a1e7..cf6b6d97d 100644
--- a/xmake/modules/lib/detect/pkgconfig.lua
+++ b/xmake/modules/lib/detect/pkgconfig.lua
@@ -24,7 +24,15 @@ import("core.project.target")
import("core.project.config")
import("lib.detect.find_file")
import("lib.detect.find_library")
-import("detect.tools.find_pkg_config")
+import("lib.detect.find_tool")
+
+-- get pkgconfig
+function _get_pkgconfig()
+ local pkgconfig = find_tool("pkg-config") or find_tool("pkgconf")
+ if pkgconfig then
+ return pkgconfig.program
+ end
+end
-- get version
--
@@ -34,7 +42,7 @@ import("detect.tools.find_pkg_config")
function version(name, opt)
-- attempt to add search paths from pkg-config
- local pkgconfig = find_pkg_config()
+ local pkgconfig = _get_pkgconfig()
if not pkgconfig then
return
end
@@ -46,7 +54,7 @@ function version(name, opt)
local configdirs_old = os.getenv("PKG_CONFIG_PATH")
local configdirs = table.wrap(opt.configdirs)
if #configdirs > 0 then
- os.setenv("PKG_CONFIG_PATH", unpack(configdirs))
+ os.setenv("PKG_CONFIG_PATH", table.unpack(configdirs))
end
-- get version
@@ -73,7 +81,7 @@ end
function variables(name, variables, opt)
-- attempt to add search paths from pkg-config
- local pkgconfig = find_pkg_config()
+ local pkgconfig = _get_pkgconfig()
if not pkgconfig then
return
end
@@ -85,7 +93,7 @@ function variables(name, variables, opt)
local configdirs_old = os.getenv("PKG_CONFIG_PATH")
local configdirs = table.wrap(opt.configdirs)
if #configdirs > 0 then
- os.setenv("PKG_CONFIG_PATH", unpack(configdirs))
+ os.setenv("PKG_CONFIG_PATH", table.unpack(configdirs))
end
-- get variable value
@@ -125,7 +133,7 @@ end
function libinfo(name, opt)
-- attempt to add search paths from pkg-config
- local pkgconfig = find_pkg_config()
+ local pkgconfig = _get_pkgconfig()
if not pkgconfig then
return
end