summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-01-23 22:55:41 +0800
committerruki <[email protected]>2020-01-23 11:34:10 +0800
commit07b241522ae9712167f1f218e08e651717b7fd55 (patch)
treee76e15d1e84722cb8c538db25e0d63c6f4444fad
parentd989ec1a9903dde07d08bf58386a45dd53651f6c (diff)
fix tests
-rw-r--r--xmake/core/tool/compiler.lua18
-rw-r--r--xmake/modules/core/tools/cl.lua28
-rw-r--r--xmake/modules/core/tools/gcc.lua28
3 files changed, 55 insertions, 19 deletions
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index 354480a81..0c0a1375a 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -259,6 +259,22 @@ function compiler:compcmd(sourcefiles, objectfile, opt)
return os.args(table.join(self:compargv(sourcefiles, objectfile, opt)))
end
+-- add flags from the sourcefile config
+function builder:_add_flags_from_fileconfig(flags, target, sourcefile, fileconfig)
+
+ -- add flags from the current compiler
+ local add_sourceflags = self:_tool().add_sourceflags
+ if add_sourceflags then
+ local flag = add_sourceflags(self:_tool(), sourcefile, fileconfig, target, self:_targetkind())
+ if flag and flag ~= "" then
+ table.join2(flags, flag)
+ end
+ end
+
+ -- add flags from the common argument option
+ self:_add_flags_from_argument(flags, target, fileconfig)
+end
+
-- get the compling flags
--
-- @param opt the argument options (contain all the compiler attributes of target),
@@ -292,7 +308,7 @@ function compiler:compflags(opt)
if opt.sourcefile and target and target.fileconfig then
local fileconfig = target:fileconfig(opt.sourcefile)
if fileconfig then
- self:_add_flags_from_argument(flags, target, fileconfig)
+ self:_add_flags_from_fileconfig(flags, target, opt.sourcefile, fileconfig)
end
end
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index 5ce63f6c7..3f4857f6a 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -30,15 +30,6 @@ function init(self)
-- init cxflags
self:set("cxflags", "-nologo")
- -- set language type explicitly
- --
- -- because compiler maybe compile `.c` as c++.
- -- e.g.
- -- add_files("*.c", {sourcekind = "cxx"})
- --
- self:add("cflags", "-TC")
- self:add("cxxflags", "-TP")
-
-- init flags map
self:set("mapflags",
{
@@ -280,6 +271,25 @@ function nf_pcxxheader(self, pcheaderfile, target)
end
end
+-- add the special flags for the given source file of target
+--
+-- @note only it called when fileconfig is set
+--
+function add_sourceflags(self, sourcefile, fileconfig, target, targetkind)
+
+ -- add language type flags explicitly if the sourcekind is changed.
+ --
+ -- because compiler maybe compile `.c` as c++.
+ -- e.g.
+ -- add_files("*.c", {sourcekind = "cxx"})
+ --
+ local sourcekind = fileconfig.sourcekind
+ if sourcekind and sourcekind ~= language.sourcekind_of(sourcefile) then
+ local maps = {cc = "-TC", cxx = "-TP"}
+ return maps[sourcekind]
+ end
+end
+
-- contain: "Note: including file: "?
--
-- @note we cannot get better solution to distinguish between `includes` and `error infos`
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 6daeb2fd6..2872c88da 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -46,15 +46,6 @@ function init(self)
self:add("shared.cxflags", "-fPIC")
end
- -- set language type explicitly
- --
- -- because compiler maybe compile `.c` as c++.
- -- e.g.
- -- add_files("*.c", {sourcekind = "cxx"})
- --
- self:add("cflags", "-x c")
- self:add("cxxflags", "-x c++")
-
-- init flags map
self:set("mapflags",
{
@@ -304,6 +295,25 @@ function nf_pcxxheader(self, pcheaderfile, target)
end
end
+-- add the special flags for the given source file of target
+--
+-- @note only it called when fileconfig is set
+--
+function add_sourceflags(self, sourcefile, fileconfig, target, targetkind)
+
+ -- add language type flags explicitly if the sourcekind is changed.
+ --
+ -- because compiler maybe compile `.c` as c++.
+ -- e.g.
+ -- add_files("*.c", {sourcekind = "cxx"})
+ --
+ local sourcekind = fileconfig.sourcekind
+ if sourcekind and sourcekind ~= language.sourcekind_of(sourcefile) then
+ local maps = {cc = "-x c", cxx = "-x c++"}
+ return maps[sourcekind]
+ end
+end
+
-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)