summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2023-01-07 00:18:44 +0100
committerArthur LAURENT <[email protected]>2023-01-14 15:44:42 +0100
commit020786b7f39a682ef6486e0a342d2c02f8c42308 (patch)
tree2a5b3cfdf89cbf4bdcf5f4447a13d525facb7eb4
parentfc027f1d28ea7a97f3523faa46196f906a56f337 (diff)
add support of clang-scan-deps
-rw-r--r--xmake/rules/c++/modules/modules_support/clang.lua52
1 files changed, 39 insertions, 13 deletions
diff --git a/xmake/rules/c++/modules/modules_support/clang.lua b/xmake/rules/c++/modules/modules_support/clang.lua
index 17509f2e5..bc07c28cf 100644
--- a/xmake/rules/c++/modules/modules_support/clang.lua
+++ b/xmake/rules/c++/modules/modules_support/clang.lua
@@ -21,10 +21,12 @@
-- imports
import("core.base.option")
import("core.base.json")
+import("core.base.semver")
import("core.tool.compiler")
import("core.project.project")
import("core.project.depend")
import("core.project.config")
+import("lib.detect.find_tool")
import("utils.progress")
import("private.action.build.object", {alias = "objectbuilder"})
import("common")
@@ -249,23 +251,35 @@ function generate_dependencies(target, sourcebatch, opt)
os.mkdir(outputdir)
end
- -- no support of p1689 atm
local jsonfile = path.translate(path.join(outputdir, path.filename(sourcefile) .. ".json"))
- common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file)
+ if has_clangscandepssupport(target) then
+ local clangscandeps = find_tool("clang-scan-deps")
local compinst = target:compiler("cxx")
local compflags = compinst:compflags({sourcefile = file, target = target})
- local flags = {}
- for _, flag in ipairs(compflags) do
- if flag:startswith("-stdlib") or (flag:startswith("-f") and not flag:startswith("-fmodules")) or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") then
- table.insert(flags, flag)
+ local flags = table.join({"--format=p1689", "--", compinst:program(), "-x", "c++", "-c", sourcefile, "-o", target:objectfile(sourcefile)}, compflags)
+
+ vprint(table.concat(table.join(clangscandeps.program, flags), " "))
+ local outdata, errdata = os.iorunv(clangscandeps.program, flags)
+ assert(errdata, errdata)
+
+ io.writefile(jsonfile, outdata)
+ else
+ common.fallback_generate_dependencies(target, jsonfile, sourcefile, function(file)
+ local compinst = target:compiler("cxx")
+ local compflags = compinst:compflags({sourcefile = file, target = target})
+ local flags = {}
+ for _, flag in pairs(compflags) do
+ if flag:startswith("-stdlib") or (flag:startswith("-f") and not flag:startswith("-fmodules")) or flag:startswith("-D") or flag:startswith("-U") or flag:startswith("-I") or flag:startswith("-isystem") then
+ table.insert(flags, flag)
+ end
end
- end
- local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i"))
- os.vrunv(compinst:program(), table.join(flags, {"-E", "-x", "c++", file, "-o", ifile}))
- local content = io.readfile(ifile)
- os.rm(ifile)
- return content
- end)
+ local ifile = path.translate(path.join(outputdir, path.filename(file) .. ".i"))
+ os.vrunv(compinst:program(), table.join(flags, {"-E", "-x", "c++", file, "-o", ifile}))
+ local content = io.readfile(ifile)
+ os.rm(ifile)
+ return content
+ end)
+ end
changed = true
local rawdependinfo = io.readfile(jsonfile)
@@ -777,6 +791,18 @@ function has_headerunitsupport(target)
return support_headerunits or nil
end
+function has_clangscandepssupport(target)
+ local support_clangscandeps = _g.support_clangscandeps
+ if support_clangscandeps == nil then
+ local clangscandeps = find_tool("clang-scan-deps", {version = true})
+ if clangscandeps and clangscandeps.version and semver.compare(clangscandeps.version, "16.0") >= 0 then
+ support_clangscandeps = true
+ end
+ _g.support_clangscandeps = support_clangscandeps or false
+ end
+ return support_clangscandeps or nil
+end
+
function get_requiresflags(target, requires)
local flags = {}
-- add deps required module flags