summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-26 00:49:50 +0800
committerruki <[email protected]>2026-03-26 00:49:50 +0800
commit61c20bbce2d4a50cb21095369246c0d13bd2c2e3 (patch)
tree6a2ed54e737171a89707bb6609b7098284e81cfd
parentf623b0100b7270dcd4b923c929e8cb4629677b7b (diff)
improve check knownargs
-rw-r--r--xmake/modules/core/tools/cl/check_knownargs.lua62
-rw-r--r--xmake/modules/core/tools/cl/has_flags.lua45
-rw-r--r--xmake/modules/core/tools/clang_cl/has_flags.lua43
3 files changed, 66 insertions, 84 deletions
diff --git a/xmake/modules/core/tools/cl/check_knownargs.lua b/xmake/modules/core/tools/cl/check_knownargs.lua
new file mode 100644
index 000000000..b42fe5e22
--- /dev/null
+++ b/xmake/modules/core/tools/cl/check_knownargs.lua
@@ -0,0 +1,62 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file check_knownargs.lua
+--
+
+-- imports
+import("core.base.hashset")
+
+function main(flags)
+ local flag = flags[1]:gsub("/", "-")
+ local known_flags = _g.known_flags
+ if known_flags == nil then
+ known_flags = hashset.from({
+ "-Ox", "-O1", "-O2", "-Od",
+ "-MT", "-MD", "-MTd", "-MDd",
+ "-EHsc", "-EHa", "-EHs",
+ "-W0", "-W1", "-W2", "-W3", "-W4", "-Wall", "-WX",
+ "-Z7", "-Zi", "-ZI",
+ "-c", "-nologo", "-FS", "-FC", "-Gm-",
+ "-GR", "-GR-", "-GS", "-GS-",
+ "-Gy", "-Gy-", "-GL",
+ "-Gd", "-Gr", "-Gz", "-Gv",
+ "-TC", "-TP",
+ "-utf-8", "-bigobj", "-MP",
+ "-showIncludes"
+ })
+ _g.known_flags = known_flags
+ end
+ if known_flags:has(flag) then
+ return true
+ end
+ -- check flags with known prefixes that always accept values (all MSVC versions)
+ if flag:startswith("-D") or
+ flag:startswith("-U") or
+ flag:startswith("-I") or
+ flag:startswith("-Fo") or
+ flag:startswith("-Fe") or
+ flag:startswith("-Fd") or
+ flag:startswith("-Fi") or
+ flag:startswith("-Fp") or
+ flag:startswith("-FI") or
+ flag:startswith("-wd") or
+ flag:startswith("-we") or
+ flag:startswith("-wo") then
+ return true
+ end
+end
diff --git a/xmake/modules/core/tools/cl/has_flags.lua b/xmake/modules/core/tools/cl/has_flags.lua
index 57c5d2d0c..5d24818be 100644
--- a/xmake/modules/core/tools/cl/has_flags.lua
+++ b/xmake/modules/core/tools/cl/has_flags.lua
@@ -21,48 +21,7 @@
-- imports
import("core.language.language")
import("core.cache.global_detectcache")
-import("core.base.hashset")
-
--- attempt to check it from known flags
-function _check_from_knownargs(flags, opt)
- local flag = flags[1]:gsub("/", "-")
- local known_flags = _g.known_flags
- if known_flags == nil then
- known_flags = hashset.from({
- "-Ox", "-O1", "-O2", "-Od",
- "-MT", "-MD", "-MTd", "-MDd",
- "-EHsc", "-EHa", "-EHs",
- "-W0", "-W1", "-W2", "-W3", "-W4", "-Wall", "-WX",
- "-Z7", "-Zi", "-ZI",
- "-c", "-nologo", "-FS", "-FC", "-Gm-",
- "-GR", "-GR-", "-GS", "-GS-",
- "-Gy", "-Gy-", "-GL",
- "-Gd", "-Gr", "-Gz", "-Gv",
- "-TC", "-TP",
- "-utf-8", "-bigobj", "-MP",
- "-showIncludes"
- })
- _g.known_flags = known_flags
- end
- if known_flags:has(flag) then
- return true
- end
- -- check flags with known prefixes that always accept values (all MSVC versions)
- if flag:startswith("-D") or
- flag:startswith("-U") or
- flag:startswith("-I") or
- flag:startswith("-Fo") or
- flag:startswith("-Fe") or
- flag:startswith("-Fd") or
- flag:startswith("-Fi") or
- flag:startswith("-Fp") or
- flag:startswith("-FI") or -- force include
- flag:startswith("-wd") or -- e.g. /wd4251
- flag:startswith("-we") or -- e.g. /we4062
- flag:startswith("-wo") then
- return true
- end
-end
+import("core.tools.cl.check_knownargs")
-- attempt to check it from the argument list
function _check_from_arglist(flags, opt)
@@ -137,7 +96,7 @@ function main(flags, opt)
-- attempt to check it from the argument list
opt = opt or {}
if not opt.tryrun then
- if _check_from_knownargs(flags, opt) then
+ if check_knownargs(flags) then
return true
end
if _check_from_arglist(flags, opt) then
diff --git a/xmake/modules/core/tools/clang_cl/has_flags.lua b/xmake/modules/core/tools/clang_cl/has_flags.lua
index 2a670a5ee..7d6e8c742 100644
--- a/xmake/modules/core/tools/clang_cl/has_flags.lua
+++ b/xmake/modules/core/tools/clang_cl/has_flags.lua
@@ -21,46 +21,7 @@
-- imports
import("core.cache.detectcache")
import("core.language.language")
-import("core.base.hashset")
-
--- attempt to check it from known flags
-function _check_from_knownargs(flags, opt)
- local flag = flags[1]:gsub("/", "-")
- local known_flags = _g.known_flags
- if known_flags == nil then
- known_flags = hashset.from({
- "-Ox", "-O1", "-O2", "-Od",
- "-MT", "-MD", "-MTd", "-MDd",
- "-EHsc", "-EHa", "-EHs",
- "-W0", "-W1", "-W2", "-W3", "-W4", "-Wall", "-WX",
- "-Z7", "-Zi", "-ZI",
- "-c", "-nologo", "-FS", "-FC", "-Gm-",
- "-GR", "-GR-", "-GS", "-GS-",
- "-Gy", "-Gy-", "-GL",
- "-Gd", "-Gr", "-Gz", "-Gv",
- "-TC", "-TP",
- "-utf-8", "-bigobj", "-MP",
- "-showIncludes"
- })
- _g.known_flags = known_flags
- end
- if known_flags:has(flag) then
- return true
- end
- -- check flags with known prefixes that always accept values (all versions)
- if flag:startswith("-D") or
- flag:startswith("-U") or
- flag:startswith("-I") or
- flag:startswith("-Fo") or
- flag:startswith("-Fe") or
- flag:startswith("-Fd") or
- flag:startswith("-FI") or
- flag:startswith("-wd") or
- flag:startswith("-we") or
- flag:startswith("-wo") then
- return true
- end
-end
+import("core.tools.cl.check_knownargs")
-- attempt to check it from the argument list
function _check_from_arglist(flags, opt)
@@ -131,7 +92,7 @@ function main(flags, opt)
-- attempt to check it from known flags
opt = opt or {}
- if _check_from_knownargs(flags, opt) then
+ if check_knownargs(flags) then
return true
end