summaryrefslogtreecommitdiff
path: root/xmake/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-07 23:06:57 +0800
committerruki <[email protected]>2023-11-07 23:06:57 +0800
commit5e6d94f24963e246d8c231c8ecb49ad86c370d4d (patch)
tree697a985fcd4d9854775fdcb61825ab919928c262 /xmake/modules
parentfa4e975e916415a1a82c7aff16f891e761bd17e1 (diff)
improve clang_cl language
Diffstat (limited to 'xmake/modules')
-rw-r--r--xmake/modules/core/tools/clang_cl.lua70
-rw-r--r--xmake/modules/detect/tools/clang_cl/has_flags.lua2
2 files changed, 71 insertions, 1 deletions
diff --git a/xmake/modules/core/tools/clang_cl.lua b/xmake/modules/core/tools/clang_cl.lua
index 69459ad3e..62bbb7f4d 100644
--- a/xmake/modules/core/tools/clang_cl.lua
+++ b/xmake/modules/core/tools/clang_cl.lua
@@ -69,6 +69,76 @@ function init(self)
})
end
+-- make the language flag
+-- @see https://github.com/xmake-io/xmake/issues/2211#issuecomment-1083322178
+-- https://github.com/xmake-io/xmake/issues/4353
+function nf_language(self, stdname)
+
+ -- the stdc maps
+ if _g.cmaps == nil then
+ _g.cmaps =
+ {
+ -- stdc
+ ansi = "-Xclang -ansi"
+ , c89 = "-Xclang -std=c89"
+ , gnu89 = "-Xclang -std=gnu89"
+ , c99 = "-Xclang -std=c99"
+ , gnu99 = "-Xclang -std=gnu99"
+ , c11 = "-Xclang -std=c11"
+ , gnu11 = "-Xclang -std=gnu11"
+ , c17 = "-Xclang -std=c17"
+ , gnu17 = "-Xclang -std=gnu17"
+ , clatest = "-Xclang -std=c17"
+ , gnulatest = "-Xclang -std=gnu17"
+ }
+ end
+
+ -- the stdc++ maps
+ if _g.cxxmaps == nil then
+ _g.cxxmaps =
+ {
+ cxx98 = "-Xclang -std=c++98"
+ , gnuxx98 = "-Xclang -std=gnu++98"
+ , cxx11 = "-Xclang -std=c++11"
+ , gnuxx11 = "-Xclang -std=gnu++11"
+ , cxx14 = "-Xclang -std=c++14"
+ , gnuxx14 = "-Xclang -std=gnu++14"
+ , cxx17 = "-Xclang -std=c++17"
+ , gnuxx17 = "-Xclang -std=gnu++17"
+ , cxx1z = "-Xclang -std=c++1z"
+ , gnuxx1z = "-Xclang -std=gnu++1z"
+ , cxx20 = "-Xclang -std=c++20"
+ , gnuxx20 = "-Xclang -std=gnu++20"
+ , cxx2a = "-Xclang -std=c++2a"
+ , gnuxx2a = "-Xclang -std=gnu++2a"
+ , cxxlatest = "-Xclang -std=c++latest"
+ , gnuxxlatest = "-Xclang -std=gnu++latest"
+ }
+ local cxxmaps2 = {}
+ for k, v in pairs(_g.cxxmaps) do
+ cxxmaps2[k:gsub("xx", "++")] = v
+ end
+ table.join2(_g.cxxmaps, cxxmaps2)
+ end
+
+ -- select maps
+ local maps = _g.cmaps
+ if self:kind() == "cxx" or self:kind() == "mxx" then
+ maps = _g.cxxmaps
+ end
+
+ -- we select it from msvc/flags first, then select -Xclang flags
+ local flags = _super.nf_language(self, stdname)
+ if flags then
+ flags = table.wrap(flags)
+ local clang_flag = maps[stdname]
+ if clang_flag then
+ table.insert(flags, 2, clang_flag)
+ end
+ end
+ return flags
+end
+
-- has color diagnostics?
function _has_color_diagnostics(self)
local colors_diagnostics = _g._HAS_COLOR_DIAGNOSTICS
diff --git a/xmake/modules/detect/tools/clang_cl/has_flags.lua b/xmake/modules/detect/tools/clang_cl/has_flags.lua
index c919ed4b0..704a30f1a 100644
--- a/xmake/modules/detect/tools/clang_cl/has_flags.lua
+++ b/xmake/modules/detect/tools/clang_cl/has_flags.lua
@@ -79,7 +79,7 @@ function _check_try_running(flags, opt)
-- check flags for compiler
-- @note we cannot use os.nuldev() as the output file, maybe run failed for some flags, e.g. --coverage
- return _try_running(opt.program, table.join("-Werror,-Wunused-command-line-argument", flags, "-c", "-o", os.tmpfile(), sourcefile))
+ return _try_running(opt.program, table.join("-Werror=unused-command-line-argument", flags, "-c", "-o", os.tmpfile(), sourcefile))
end
-- has_flags(flags)?