summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-16 00:30:52 +0800
committerruki <[email protected]>2025-12-16 00:30:52 +0800
commit757ad890028fddcdea24159634d83bbfc41073ef (patch)
tree7cb05747782ea1ff814bbb08c2ee8304d5f2af72
parente58fd4cd9145d5a060a00c513cbe76a1011c013f (diff)
improve clang-cl depfiles #7070
-rw-r--r--xmake/modules/core/tools/clang_cl.lua38
1 files changed, 35 insertions, 3 deletions
diff --git a/xmake/modules/core/tools/clang_cl.lua b/xmake/modules/core/tools/clang_cl.lua
index bafbc58a7..fb3333530 100644
--- a/xmake/modules/core/tools/clang_cl.lua
+++ b/xmake/modules/core/tools/clang_cl.lua
@@ -143,6 +143,20 @@ function nf_pcxxheader(self, pcheaderfile, opt)
end
end
+-- has /clang:-MMD -MF depfile?
+function _has_clang_mmd(self)
+ local has_clang_mmd = _g._HAS_CLANG_MMD
+ if has_clang_mmd == nil then
+ local depfile = os.tmpfile()
+ if self:has_flags({"/clang:-MMD", "/clang:-MF", "/clang:" .. depfile}, "cxflags", {flagskey = "clang_mmd"}) then
+ has_clang_mmd = true
+ end
+ os.tryrm(depfile)
+ _g._HAS_CLANG_MMD = has_clang_mmd or false
+ end
+ return has_clang_mmd
+end
+
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
@@ -150,6 +164,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
os.mkdir(path.directory(objectfile))
-- compile it
+ local depfile
+ local depfile_format
local outdata = try
{
function ()
@@ -157,7 +173,14 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- generate includes file
local compflags = flags
if dependinfo then
- compflags = table.join(flags, "-showIncludes")
+ if _has_clang_mmd(self) then
+ depfile = os.tmpfile()
+ compflags = table.join(flags, "/clang:-MMD", "/clang:-MF", "/clang:" .. depfile)
+ depfile_format = "gcc"
+ else
+ compflags = table.join(flags, "-showIncludes")
+ depfile_format = "cl"
+ end
end
-- has color diagnostics? enable it
@@ -176,6 +199,9 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
+ if depfile then
+ os.tryrm(depfile)
+ end
-- parse and strip errors
local lines = errors and tostring(errors):split('\n', {plain = true}) or {}
@@ -217,7 +243,13 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- generate the dependent includes
if dependinfo and outdata then
- dependinfo.depfiles_format = "cl"
- dependinfo.depfiles = outdata
+ if depfile and os.isfile(depfile) then
+ dependinfo.depfiles_format = depfile_format
+ dependinfo.depfiles = io.readfile(depfile)
+ os.tryrm(depfile)
+ elseif depfile_format == "cl" then
+ dependinfo.depfiles_format = "cl"
+ dependinfo.depfiles = outdata
+ end
end
end