summaryrefslogtreecommitdiff
path: root/xmake/modules/lib/detect/has_flags.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2017-06-20 12:57:35 +0800
committerruki <[email protected]>2017-06-20 12:57:35 +0800
commit0ef4acaa5f9d78c7fd8941ccbe8d3f237e91268c (patch)
treef6f953421cbff144644ab5e6781ad8b187bf12ff /xmake/modules/lib/detect/has_flags.lua
parentbc5021e091a9e7b962243354c88e0fe11dff563f (diff)
improve has_flags for gcc
Diffstat (limited to 'xmake/modules/lib/detect/has_flags.lua')
-rw-r--r--xmake/modules/lib/detect/has_flags.lua57
1 files changed, 10 insertions, 47 deletions
diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua
index 43abc5a1e..bbd972c0d 100644
--- a/xmake/modules/lib/detect/has_flags.lua
+++ b/xmake/modules/lib/detect/has_flags.lua
@@ -25,36 +25,6 @@
-- imports
import("lib.detect.find_tool")
--- get flag name
---
--- .e.g
---
--- "-fsanitize=address": fsanitize_address
--- "--coverage": coverage
--- "-nodefaultlib:\"msvcrt.lib\"": nodefaultlib
--- "/TP": tp
--- "fomit-frame-pointer": fomit_frame_pointer
--- "-Wno-error=deprecated-declarations": wno_error_deprecated_declarations
--- "-pagezero_size 10000" pagezero_size
---
-function _get_flagname(flag)
-
- -- get the first name by ' '
- local name = flag:lower():split('%s+')[1]
-
- -- split ':'
- name = name:split(':')[1]
-
- -- translate '-', '/' and '=' to '_'
- name = name:gsub("[%-/=]", "_")
-
- -- remove prefix '_*' .. xxxx
- name = name:gsub("^_+", "")
-
- -- ok?
- return name
-end
-
-- has this flag?
function _has_flag(name, flag, opt)
@@ -66,12 +36,12 @@ function _has_flag(name, flag, opt)
end
-- init tool
- opt.tool = tool
-
- -- TODO tool.check, semver(tool.version)
+ opt.toolname = tool.name
+ opt.program = tool.program
+ opt.programver = tool.version
-- init cache and key
- local key = tool.program .. "_" .. (tool.version or "") .. "_" .. flag
+ local key = tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. flag
local results = _g._RESULTS or {}
-- get result from the cache first
@@ -80,21 +50,13 @@ function _has_flag(name, flag, opt)
return result
end
- -- get flag name
- local flagname = _get_flagname(flag)
- print(flagname)
-
- -- "detect.tools.find_xxx" exists?
- local result = nil
- if os.isfile(path.join(os.programdir(), "modules", "detect", "flags", "has_ " .. flagname .. ".lua")) then
- local hasflag = import("detect.flags.has_" .. flagname)
+ -- detect.tools.xxx.has_flag(flag, opt)?
+ if os.isfile(path.join(os.programdir(), "modules", "detect", "tools", tool.name, "has_flag.lua")) then
+ local hasflag = import("detect.tools." .. tool.name .. ".has_flag")
if hasflag then
result = hasflag(flag, opt)
end
- end
-
- -- attempt to check it directly
- if result == nil then
+ else
result = try { function () os.runv(tool.program, {flag}); return true end }
end
@@ -110,13 +72,14 @@ end
--
-- @param name the tool name
-- @param flags the flags
--- @param opt the argument options, .e.g {program = ""}
+-- @param opt the argument options, .e.g {program = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"}
--
-- @return true or false
--
-- @code
-- local ok = has_flags("clang", "-g")
-- local ok = has_flags("clang", {"-g", "-O0"}, {program = "xcrun -sdk macosx clang"})
+-- local ok = has_flags("clang", "-g", {toolkind = "cxx"})
-- @endcode
--
function main(name, flags, opt)