From 36bdca38baa44cba883108516e8d48866c7a54bb Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 8 Mar 2023 22:49:48 +0800 Subject: improve has_flags --- xmake/modules/detect/tools/cl/has_flags.lua | 19 +++++++++++++++++-- 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 -- cgit v1.3.1