summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-18 22:41:11 +0800
committerruki <[email protected]>2025-09-18 22:41:11 +0800
commit7e3c48b59afbbb53a58951d81413cd438553ad05 (patch)
tree6dac695956c1caa4a4f30b69f04e8ce75e670674
parent44812793dd6e8c9cae32bf8517d516709e91b3db (diff)
improve has_flags
-rw-r--r--xmake/modules/core/tools/gcc/has_flags.lua13
-rw-r--r--xmake/modules/detect/tools/find_cmake.lua1
-rw-r--r--xmake/modules/detect/tools/find_ninja.lua1
3 files changed, 13 insertions, 2 deletions
diff --git a/xmake/modules/core/tools/gcc/has_flags.lua b/xmake/modules/core/tools/gcc/has_flags.lua
index 731e5da2f..b56596e3e 100644
--- a/xmake/modules/core/tools/gcc/has_flags.lua
+++ b/xmake/modules/core/tools/gcc/has_flags.lua
@@ -21,6 +21,7 @@
-- imports
import("core.cache.detectcache")
import("core.language.language")
+import("core.base.hashset")
-- is linker?
function _islinker(flags, opt)
@@ -45,6 +46,14 @@ end
-- attempt to check it from known flags
function _check_from_knownargs(flags, opt, islinker)
local flag = flags[1]
+ local known_flags = _g.known_flags
+ if known_flags == nil then
+ known_flags = hashset.from({"-O0", "-O1", "-O2", "-O3", "-g"})
+ _g.known_flags = known_flags
+ end
+ if known_flags:has(flag) then
+ return true
+ end
if not islinker then
if flag:startswith("-D") or
flag:startswith("-U") or
@@ -119,10 +128,10 @@ function main(flags, opt)
-- attempt to check it from the argument list
if not opt.tryrun then
- if _check_from_arglist(flags, opt, islinker) then
+ if _check_from_knownargs(flags, opt, islinker) then
return true
end
- if _check_from_knownargs(flags, opt, islinker) then
+ if _check_from_arglist(flags, opt, islinker) then
return true
end
end
diff --git a/xmake/modules/detect/tools/find_cmake.lua b/xmake/modules/detect/tools/find_cmake.lua
index cebb5487d..a9267543d 100644
--- a/xmake/modules/detect/tools/find_cmake.lua
+++ b/xmake/modules/detect/tools/find_cmake.lua
@@ -40,6 +40,7 @@ function main(opt)
-- init options
opt = opt or {}
+ opt.norunfile = true
if is_host("windows") then
opt.paths = "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\CMake;InstallDir)\\bin"
end
diff --git a/xmake/modules/detect/tools/find_ninja.lua b/xmake/modules/detect/tools/find_ninja.lua
index 4a03d9e41..06b95f24c 100644
--- a/xmake/modules/detect/tools/find_ninja.lua
+++ b/xmake/modules/detect/tools/find_ninja.lua
@@ -40,6 +40,7 @@ function main(opt)
-- find program
opt = opt or {}
+ opt.norunfile = true
local program = find_program(opt.program or "ninja", opt)
if not program and is_host("windows") then
local msvc = toolchain.load("msvc", {plat = os.host(), arch = os.arch()})