summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-11 00:32:13 +0800
committerruki <[email protected]>2021-11-11 00:32:13 +0800
commitf75426a0b6317900298bfdda15a88b546b0d7564 (patch)
treef390d0431c720847025d357834f227420262ed87
parente99fa03712fb749bd1e689b3df63b98daa1210cc (diff)
improve has_flags for msvc
-rw-r--r--xmake/core/tool/builder.lua4
-rw-r--r--xmake/core/tool/tool.lua4
-rw-r--r--xmake/modules/detect/tools/cl/has_flags.lua8
-rw-r--r--xmake/modules/detect/tools/gcc/has_flags.lua12
-rw-r--r--xmake/rules/c++/modules/build_modules/msvc.lua18
5 files changed, 27 insertions, 19 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 33733eaab..91bb707f8 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -420,8 +420,8 @@ function builder:get(name)
end
-- has flags?
-function builder:has_flags(flags, flagkind)
- return self:_tool():has_flags(flags, flagkind)
+function builder:has_flags(flags, flagkind, opt)
+ return self:_tool():has_flags(flags, flagkind, opt)
end
-- map flags from name and values, e.g. linkdirs, links, defines
diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua
index c118179d6..af62c7f8e 100644
--- a/xmake/core/tool/tool.lua
+++ b/xmake/core/tool/tool.lua
@@ -140,8 +140,8 @@ function _instance:has_flags(flags, flagkind, opt)
-- get system flags
opt.sysflags = opt.sysflags or self:get(self:kind() .. 'flags')
- if not opt.sysflags and flagkind then
- opt.sysflags = self:get(flagkind)
+ if not opt.sysflags and opt.flagkind then
+ opt.sysflags = self:get(opt.flagkind)
end
-- import has_flags()
diff --git a/xmake/modules/detect/tools/cl/has_flags.lua b/xmake/modules/detect/tools/cl/has_flags.lua
index a1cb9ace7..1c7f65325 100644
--- a/xmake/modules/detect/tools/cl/has_flags.lua
+++ b/xmake/modules/detect/tools/cl/has_flags.lua
@@ -20,6 +20,7 @@
-- imports
import("core.cache.detectcache")
+import("core.language.language")
-- attempt to check it from the argument list
function _check_from_arglist(flags, opt)
@@ -55,12 +56,17 @@ function _check_from_arglist(flags, opt)
return allflags[flags[1]:gsub("/", "-")]
end
+-- get extension
+function _get_extension(opt)
+ return opt.flagkind == "cxxflags" and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c")
+end
+
-- try running to check flags
function _check_try_running(flags, opt)
-- make an stub source file
local tmpdir = path.join(os.tmpdir(), "detect")
- local sourcefile = path.join(tmpdir, "cl_has_flags.c")
+ local sourcefile = path.join(tmpdir, "cl_has_flags" .. _get_extension(opt))
if not os.isfile(sourcefile) then
io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
end
diff --git a/xmake/modules/detect/tools/gcc/has_flags.lua b/xmake/modules/detect/tools/gcc/has_flags.lua
index 391ff2bfb..7b4a40fd2 100644
--- a/xmake/modules/detect/tools/gcc/has_flags.lua
+++ b/xmake/modules/detect/tools/gcc/has_flags.lua
@@ -76,15 +76,17 @@ function _check_from_arglist(flags, opt, islinker)
return allflags[flags[1]]
end
+-- get extension
+function _get_extension(opt)
+ -- @note we need detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
+ return (opt.program:endswith("++") or opt.flagkind == "cxxflags") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c")
+end
+
-- try running to check flags
function _check_try_running(flags, opt, islinker)
- -- get extension
- -- @note we need detect extension for ndk/clang++.exe: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
- local extension = opt.program:endswith("++") and ".cpp" or (table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c")
-
-- make an stub source file
- local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flags" .. extension)
+ local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flags" .. _get_extension(opt))
if not os.isfile(sourcefile) then
io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}")
end
diff --git a/xmake/rules/c++/modules/build_modules/msvc.lua b/xmake/rules/c++/modules/build_modules/msvc.lua
index 8b28d68f6..4606edb7e 100644
--- a/xmake/rules/c++/modules/build_modules/msvc.lua
+++ b/xmake/rules/c++/modules/build_modules/msvc.lua
@@ -29,7 +29,7 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt)
-- get modules flag
local modulesflag
local compinst = compiler.load("cxx", {target = target})
- if compinst:has_flags("/experimental:module") then
+ if compinst:has_flags("/experimental:module", "cxxflags") then
modulesflag = "/experimental:module"
end
assert(modulesflag, "compiler(msvc): does not support c++ module!")
@@ -38,41 +38,41 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt)
local cachedir
local outputflag
local hasifc = false
- if compinst:has_flags("/ifcOutput") then
+ if compinst:has_flags("/ifcOutput", "cxxflags") then
hasifc = true
outputflag = "/ifcOutput"
cachedir = path.join(target:autogendir(), "rules", "modules", "cache")
if not os.isdir(cachedir) then
os.mkdir(cachedir)
end
- elseif compinst:has_flags("/module:output") then
+ elseif compinst:has_flags("/module:output", "cxxflags") then
outputflag = "/module:output"
end
assert(outputflag, "compiler(msvc): does not support c++ module!")
-- get interface flag
local interfaceflag
- if compinst:has_flags("/interface") then
+ if compinst:has_flags("/interface", "cxxflags") then
interfaceflag = "/interface"
- elseif compinst:has_flags("/module:interface") then
+ elseif compinst:has_flags("/module:interface", "cxxflags") then
interfaceflag = "/module:interface"
end
assert(interfaceflag, "compiler(msvc): does not support c++ module!")
-- get reference flag
local referenceflag
- if compinst:has_flags("/reference") then
+ if compinst:has_flags("/reference", "cxxflags") then
referenceflag = "/reference"
- elseif compinst:has_flags("/module:interface") then
+ elseif compinst:has_flags("/module:interface", "cxxflags") then
referenceflag = "/module:reference"
end
assert(referenceflag, "compiler(msvc): does not support c++ module!")
-- get stdifcdir flag
local stdifcdirflag
- if compinst:has_flags("/stdIfcDir") then
+ if compinst:has_flags("/stdIfcDir", "cxxflags") then
stdifcdirflag = "/stdIfcDir"
- elseif compinst:has_flags("/module:stdIfcDir") then
+ elseif compinst:has_flags("/module:stdIfcDir", "cxxflags") then
stdifcdirflag = "/module:stdIfcDir"
end
assert(stdifcdirflag, "compiler(msvc): does not support c++ module!")