summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-18 00:34:51 +0800
committerruki <[email protected]>2022-05-18 00:34:51 +0800
commit91d8197cef25c656b9de6aa95076c2d37f0206c2 (patch)
treeb71f3178159be319b1fd40896b0883868becdea7
parent053c31a5582c15fea9fc674ec3a14cccd9057b7e (diff)
fix preprocessor flags
-rw-r--r--xmake/core/sandbox/modules/ipairs.lua5
-rw-r--r--xmake/core/sandbox/modules/pairs.lua5
-rw-r--r--xmake/core/tool/builder.lua5
-rw-r--r--xmake/core/tool/compiler.lua4
-rw-r--r--xmake/core/tool/linker.lua4
-rw-r--r--xmake/modules/core/tools/cl.lua10
6 files changed, 30 insertions, 3 deletions
diff --git a/xmake/core/sandbox/modules/ipairs.lua b/xmake/core/sandbox/modules/ipairs.lua
index b123d6e0b..14616cea3 100644
--- a/xmake/core/sandbox/modules/ipairs.lua
+++ b/xmake/core/sandbox/modules/ipairs.lua
@@ -30,13 +30,16 @@ function sandbox_ipairs(t)
end
-- wrap table and return iterator
+ if t == nil then
+ t = {}
+ end
return function (t, i)
i = i + 1
local v = t[i]
if v ~= nil then
return i, v
end
- end, table.wrap(t), 0
+ end, t, 0
end
-- load module
diff --git a/xmake/core/sandbox/modules/pairs.lua b/xmake/core/sandbox/modules/pairs.lua
index 2c82731e2..a1a5a5588 100644
--- a/xmake/core/sandbox/modules/pairs.lua
+++ b/xmake/core/sandbox/modules/pairs.lua
@@ -30,9 +30,12 @@ function sandbox_pairs(t)
end
-- wrap table and return iterator
+ if t == nil then
+ t = {}
+ end
return function (t, i)
return next(t, i)
- end, table.wrap(t), nil
+ end, t, nil
end
-- load module
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index b7ef1fdc0..e21b2bf3b 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -392,6 +392,11 @@ function builder:_preprocess_flags(flags)
return results
end
+-- get the target
+function builder:target()
+ return self._TARGET
+end
+
-- get tool name
function builder:name()
return self:_tool():name()
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index f2146233f..9bb51e001 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -141,6 +141,9 @@ function compiler.load(sourcekind, target)
end
instance._LANGUAGE = result
+ -- init target (optional)
+ instance._TARGET = target
+
-- init target kind
instance._TARGETKIND = "object"
@@ -253,6 +256,7 @@ function compiler:compile(sourcefiles, objectfile, opt)
end
-- compile it
+ opt.target = self:target()
return sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, opt.dependinfo, compflags, opt)
end
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 25276bdce..fc6bfc185 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -172,6 +172,9 @@ function linker.load(targetkind, sourcekinds, target)
end
instance._NAMEFLAGS = nameflags
+ -- init target (optional)
+ instance._TARGET = target
+
-- init target kind
instance._TARGETKIND = targetkind
@@ -202,6 +205,7 @@ end
-- link the target file
function linker:link(objectfiles, targetfile, opt)
opt = opt or {}
+ opt.target = self:target()
return sandbox.load(self:_tool().link, self:_tool(), table.wrap(objectfiles), self:_targetkind(), targetfile, opt.linkflags or self:linkflags(opt), opt)
end
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index b5da3d0d1..268fe2472 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -410,6 +410,14 @@ function _preprocess(program, argv, opt)
end
-- get preprocessor flags
+ -- TODO fix precompiled header bug for /P + /FI
+ local target = opt.target
+ if target and (flag:startswith("-FI") or flag:startswith("/FI")) then
+ local pcheaderfile = target:get("pcheader") or target:get("pcxxheader")
+ if pcheaderfile then
+ flag = "-FI" .. path.absolute(pcheaderfile)
+ end
+ end
table.insert(cppflags, flag)
-- get compiler flags
@@ -499,7 +507,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- use vstool to compile and enable vs_unicode_output @see https://github.com/xmake-io/xmake/issues/528
local program, argv = compargv(self, sourcefile, objectfile, compflags, opt)
if distcc_build_client.is_distccjob() and distcc_build_client.singleton():has_freejobs() then
- return distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(), preprocess = _preprocess, tool = self})
+ return distcc_build_client.singleton():compile(program, argv, {envs = self:runenvs(), preprocess = _preprocess, tool = self, target = opt.target})
else
return vstool.iorunv(program, argv, {envs = self:runenvs()})
end