summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-15 22:55:21 +0800
committerGitHub <[email protected]>2025-12-15 22:55:21 +0800
commitd3acb6ca0d74d506d4a7da0fb7c055344591cb7a (patch)
tree1fde16b0bc7533a4ca7885a020e326a8a445e459
parentbab1a618ff5ef169f93d561eb91e42da3fe722ec (diff)
parentba89fa5f31026ef3cd95fb32257d4b26491682e3 (diff)
Merge pull request #7136 from xmake-io/clangcl
improve clang-cl depfiles #7070
-rw-r--r--xmake/modules/core/tools/clang_cl.lua41
1 files changed, 38 insertions, 3 deletions
diff --git a/xmake/modules/core/tools/clang_cl.lua b/xmake/modules/core/tools/clang_cl.lua
index bafbc58a7..53f98843b 100644
--- a/xmake/modules/core/tools/clang_cl.lua
+++ b/xmake/modules/core/tools/clang_cl.lua
@@ -143,6 +143,21 @@ 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
+ has_clang_mmd = has_clang_mmd or false
+ _g._HAS_CLANG_MMD = has_clang_mmd
+ os.tryrm(depfile)
+ end
+ return has_clang_mmd
+end
+
-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
@@ -150,6 +165,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 +174,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 +200,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 +244,15 @@ 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 then
+ if os.isfile(depfile) then
+ dependinfo.depfiles_format = depfile_format
+ dependinfo.depfiles = io.readfile(depfile)
+ os.tryrm(depfile)
+ end
+ elseif depfile_format == "cl" then
+ dependinfo.depfiles_format = "cl"
+ dependinfo.depfiles = outdata
+ end
end
end