diff options
| author | ruki <[email protected]> | 2023-03-08 22:49:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-03-08 22:49:48 +0800 |
| commit | 36bdca38baa44cba883108516e8d48866c7a54bb (patch) | |
| tree | 67c0d4182a228d8b67ad3048eb863a65fcb5b1dc | |
| parent | 35d03309c144f81131198b1dacd94640cbfad83d (diff) | |
improve has_flags
| -rw-r--r-- | xmake/modules/detect/tools/cl/has_flags.lua | 19 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gcc/has_flags.lua | 21 |
2 files changed, 36 insertions, 4 deletions
diff --git a/xmake/modules/detect/tools/cl/has_flags.lua b/xmake/modules/detect/tools/cl/has_flags.lua index e1e986303..7eb5d15b5 100644 --- a/xmake/modules/detect/tools/cl/has_flags.lua +++ b/xmake/modules/detect/tools/cl/has_flags.lua @@ -22,6 +22,16 @@ import("core.language.language") import("core.cache.global_detectcache") +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt) + local flag = flags[1]:gsub("/", "-") + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end +end + -- attempt to check it from the argument list function _check_from_arglist(flags, opt) local key = "detect.tools.cl.has_flags" @@ -84,8 +94,13 @@ function main(flags, opt) -- attempt to check it from the argument list opt = opt or {} - if not opt.tryrun and _check_from_arglist(flags, opt) then - return true + if not opt.tryrun then + if _check_from_arglist(flags, opt) then + return true + end + if _check_from_knownargs(flags, opt) then + return true + end end -- try running to check it diff --git a/xmake/modules/detect/tools/gcc/has_flags.lua b/xmake/modules/detect/tools/gcc/has_flags.lua index 6ab7ce810..3ab51f1ab 100644 --- a/xmake/modules/detect/tools/gcc/has_flags.lua +++ b/xmake/modules/detect/tools/gcc/has_flags.lua @@ -42,6 +42,18 @@ function _try_running(program, argv, opt) return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors end +-- attempt to check it from known flags +function _check_from_knownargs(flags, opt, islinker) + local flag = flags[1] + if not islinker then + if flag:startswith("-D") or + flag:startswith("-U") or + flag:startswith("-I") then + return true + end + end +end + -- attempt to check it from the argument list function _check_from_arglist(flags, opt, islinker) local key = "detect.tools.gcc." .. (islinker and "has_ldflags" or "has_cflags") @@ -107,8 +119,13 @@ function main(flags, opt) local islinker = _islinker(flags, opt) -- attempt to check it from the argument list - if not opt.tryrun and _check_from_arglist(flags, opt, islinker) then - return true + if not opt.tryrun then + if _check_from_arglist(flags, opt, islinker) then + return true + end + if _check_from_knownargs(flags, opt, islinker) then + return true + end end -- try running to check it |
