diff options
| author | ruki <[email protected]> | 2023-04-04 16:34:21 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-04 16:34:21 +0800 |
| commit | 315229f079381cbb3e89bcd602d1173451d0ceb2 (patch) | |
| tree | da7192d98210101376c3f507fa0d03c2efd5133f | |
| parent | f95a9574c033c90a914cc98e1a21a094694c2648 (diff) | |
| parent | 0118c90a5cdab98f61e700f4d06006d8f3861892 (diff) | |
Merge pull request #3595 from xmake-io/check
improve to check flags
7 files changed, 39 insertions, 6 deletions
diff --git a/xmake/modules/private/check/checkers/api/api_checker.lua b/xmake/modules/private/check/checkers/api/api_checker.lua index 10b63d19c..caa82a1df 100644 --- a/xmake/modules/private/check/checkers/api/api_checker.lua +++ b/xmake/modules/private/check/checkers/api/api_checker.lua @@ -138,6 +138,39 @@ function _check_target(target, apiname, valueset, level, opt) end end +-- check flag +-- @see https://github.com/xmake-io/xmake/issues/3594 +function check_flag(target, toolinst, flagkind, flag) + local extraconf = target:extraconf(flagkind) + + -- does this flag belong to this tool? + -- @see https://github.com/xmake-io/xmake/issues/3022 + -- + -- e.g. + -- for all: add_cxxflags("-g") + -- only for clang: add_cxxflags("clang::-stdlib=libc++") + -- only for clang and multiple flags: add_cxxflags("-stdlib=libc++", "-DFOO", {tools = "clang"}) + -- + local for_this_tool = true + local flagconf = extraconf and extraconf[flag] + if type(flag) == "string" and flag:find("::", 1, true) then + for_this_tool = false + local splitinfo = flag:split("::", {plain = true}) + local toolname = splitinfo[1] + if toolname == toolinst:name() then + flag = splitinfo[2] + for_this_tool = true + end + elseif flagconf and flagconf.tools then + for_this_tool = table.contains(table.wrap(flagconf.tools), toolinst:name()) + end + if for_this_tool then + return toolinst:has_flags(flag) + else + return true + end +end + -- check api configuration in targets function check_targets(apiname, opt) opt = opt or {} diff --git a/xmake/modules/private/check/checkers/api/target/asflags.lua b/xmake/modules/private/check/checkers/api/target/asflags.lua index 07de9c4ec..94e30c95f 100644 --- a/xmake/modules/private/check/checkers/api/target/asflags.lua +++ b/xmake/modules/private/check/checkers/api/target/asflags.lua @@ -26,7 +26,7 @@ function main(opt) opt = opt or {} api_checker.check_targets("asflags", table.join(opt, {check = function(target, value) local compinst = target:compiler("as") - if not compinst:has_flags(value) then + if not api_checker.check_flag(target, compinst, "asflags", value) then return false, string.format("%s: unknown assembler flag '%s'", compinst:name(), value) end return true diff --git a/xmake/modules/private/check/checkers/api/target/cflags.lua b/xmake/modules/private/check/checkers/api/target/cflags.lua index db35a7bcf..446d7b355 100644 --- a/xmake/modules/private/check/checkers/api/target/cflags.lua +++ b/xmake/modules/private/check/checkers/api/target/cflags.lua @@ -26,7 +26,7 @@ function main(opt) opt = opt or {} api_checker.check_targets("cflags", table.join(opt, {check = function(target, value) local compinst = target:compiler("cc") - if not compinst:has_flags(value) then + if not api_checker.check_flag(target, compinst, "cflags", value) then return false, string.format("%s: unknown c compiler flag '%s'", compinst:name(), value) end return true diff --git a/xmake/modules/private/check/checkers/api/target/cxflags.lua b/xmake/modules/private/check/checkers/api/target/cxflags.lua index ba09366e0..dd79aaec5 100644 --- a/xmake/modules/private/check/checkers/api/target/cxflags.lua +++ b/xmake/modules/private/check/checkers/api/target/cxflags.lua @@ -26,7 +26,7 @@ function main(opt) opt = opt or {} api_checker.check_targets("cxflags", table.join(opt, {check = function(target, value) local compinst = target:compiler("cxx") - if not compinst:has_flags(value) then + if not api_checker.check_flag(target, compinst, "cxflags", value) then return false, string.format("%s: unknown c/c++ compiler flag '%s'", compinst:name(), value) end return true diff --git a/xmake/modules/private/check/checkers/api/target/cxxflags.lua b/xmake/modules/private/check/checkers/api/target/cxxflags.lua index 84660cfa4..384baca5b 100644 --- a/xmake/modules/private/check/checkers/api/target/cxxflags.lua +++ b/xmake/modules/private/check/checkers/api/target/cxxflags.lua @@ -26,7 +26,7 @@ function main(opt) opt = opt or {} api_checker.check_targets("cxxflags", table.join(opt, {check = function(target, value) local compinst = target:compiler("cxx") - if not compinst:has_flags(value) then + if not api_checker.check_flag(target, compinst, "cxxflags", value) then return false, string.format("%s: unknown c++ compiler flag '%s'", compinst:name(), value) end return true diff --git a/xmake/modules/private/check/checkers/api/target/ldflags.lua b/xmake/modules/private/check/checkers/api/target/ldflags.lua index e06d5bb09..dae55226a 100644 --- a/xmake/modules/private/check/checkers/api/target/ldflags.lua +++ b/xmake/modules/private/check/checkers/api/target/ldflags.lua @@ -27,7 +27,7 @@ function main(opt) api_checker.check_targets("ldflags", table.join(opt, {check = function(target, value) if target:is_binary() then local linker = target:linker() - if not linker:has_flags(value) then + if not api_checker.check_flag(target, linker, "ldflags", value) then return false, string.format("%s: unknown linker flag '%s'", linker:name(), value) end end diff --git a/xmake/modules/private/check/checkers/api/target/shflags.lua b/xmake/modules/private/check/checkers/api/target/shflags.lua index 20b2f6a05..0fb46819f 100644 --- a/xmake/modules/private/check/checkers/api/target/shflags.lua +++ b/xmake/modules/private/check/checkers/api/target/shflags.lua @@ -27,7 +27,7 @@ function main(opt) api_checker.check_targets("shflags", table.join(opt, {check = function(target, value) if target:is_shared() then local linker = target:linker() - if not linker:has_flags(value) then + if not api_checker.check_flag(target, linker, "shflags", value) then return false, string.format("%s: unknown linker flag '%s'", linker:name(), value) end end |
