summaryrefslogtreecommitdiff
path: root/xmake/modules
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 /xmake/modules
parente99fa03712fb749bd1e689b3df63b98daa1210cc (diff)
improve has_flags for msvc
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/detect/tools/cl/has_flags.lua8
-rw-r--r--xmake/modules/detect/tools/gcc/has_flags.lua12
2 files changed, 14 insertions, 6 deletions
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