From 29cd3ffaf30a04875672d2f752d1b252030e965f Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 10:17:05 +0800 Subject: improve nvcc warning settings --- xmake/modules/core/tools/nvcc.lua | 49 +++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 543d5d5a4..79a7c8019 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -40,9 +40,10 @@ function init(self) self:set("mapflags", { -- warnings - ["-W1"] = "-Wall" - , ["-W2"] = "-Wall" - , ["-W3"] = "-Wall" + ["-W1"] = "" + , ["-W2"] = "" + , ["-W3"] = "" + , ["-W4"] = "-Wreorder" }) -- init buildmodes @@ -72,25 +73,43 @@ function nf_warning(self, level) local maps = { none = "-w" + , less = "" + , more = "" + , all = "" , extra = "-Wreorder" , everything = "-Wreorder" , error = "-Werror" } + + local cl_maps = + { + none = "-W0" + , less = "-W1" + , more = "-W3" + , all = "-W3" -- = "-Wall" will enable too more warnings + , extra = "-W4" + , everything = "-Wall" + , error = "-WX" + } + + local gcc_clang_maps = + { + none = "-w" + , less = "-Wall" + , more = "-Wall" + , all = "-Wall" + , extra = "-Wextra" + , everything = "-Weverything -Wall -Wextra -Weffc++" -- gcc dosen't support `-Weverything`, use `-Wall -Wextra -Weffc++` for it + , error = "-Werror" + } local warning = maps[level] - if not warning then -- for cl.exe - if is_plat("windows") then - maps.less = "-Xcompiler -W1" - maps.more = "-Xcompiler -W3" - maps.all = "-Xcompiler -W3" - -- for gcc/clang - elseif self:has_flags("-Xcompiler -Wall", "cxflags") then - maps.less = "-Xcompiler -Wall" - maps.more = "-Xcompiler -Wall" - maps.all = "-Xcompiler -Wall" - end - warning = maps[level] + if is_plat("windows") then + warning = warning .. ' -Xcompiler "' .. cl_maps[level] .. '"' + -- for gcc/clang + elseif self:has_flags("-Xcompiler -Wall", "cxflags") then + warning = warning .. ' -Xcompiler "' .. gcc_clang_maps[level] .. '"' end return warning end -- cgit v1.3.1 From ef310a63e8b7d27cc785793b83f0f688711d5305 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 10:40:10 +0800 Subject: add some comments for nvcc warning flags --- xmake/modules/core/tools/nvcc.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 79a7c8019..7698b6f8f 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -81,6 +81,7 @@ function nf_warning(self, level) , error = "-Werror" } + -- for cl.exe on windows local cl_maps = { none = "-W0" @@ -91,7 +92,8 @@ function nf_warning(self, level) , everything = "-Wall" , error = "-WX" } - + + -- for gcc & clang on linux, may be work for other gnu compatible compilers such as icc local gcc_clang_maps = { none = "-w" @@ -99,15 +101,17 @@ function nf_warning(self, level) , more = "-Wall" , all = "-Wall" , extra = "-Wextra" - , everything = "-Weverything -Wall -Wextra -Weffc++" -- gcc dosen't support `-Weverything`, use `-Wall -Wextra -Weffc++` for it + -- gcc dosen't support `-Weverything`, use `-Wall -Wextra -Weffc++` for it + -- no warning will emit for unsupoorted `-W` flags by clang/gcc + , everything = "-Weverything -Wall -Wextra -Weffc++" , error = "-Werror" } local warning = maps[level] - -- for cl.exe + -- for cl.exe on windows, it is the only supported host compiler on the platform if is_plat("windows") then warning = warning .. ' -Xcompiler "' .. cl_maps[level] .. '"' - -- for gcc/clang + -- for gcc/clang, or any gnu compatible compiler on *nix elseif self:has_flags("-Xcompiler -Wall", "cxflags") then warning = warning .. ' -Xcompiler "' .. gcc_clang_maps[level] .. '"' end -- cgit v1.3.1 From 840280ab9f9abcfc5c8c4dbad9e3165b2a4a34f0 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 10:46:29 +0800 Subject: check corrcet warnig flags --- xmake/modules/core/tools/nvcc.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 7698b6f8f..907703b6f 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -107,14 +107,24 @@ function nf_warning(self, level) , error = "-Werror" } - local warning = maps[level] + local warning = maps[level] or "" + + local host_warning = nil -- for cl.exe on windows, it is the only supported host compiler on the platform if is_plat("windows") then - warning = warning .. ' -Xcompiler "' .. cl_maps[level] .. '"' + host_warning = cl_maps[level] -- for gcc/clang, or any gnu compatible compiler on *nix - elseif self:has_flags("-Xcompiler -Wall", "cxflags") then - warning = warning .. ' -Xcompiler "' .. gcc_clang_maps[level] .. '"' + else + local gcc_clang_warning = gcc_clang_maps[level] + if gcc_clang_warning and self:has_flags(' -Xcompiler "' .. gcc_clang_warning .. '"', "cxflags") then + host_warning = gcc_clang_warning + end end + + if host_warning then + warning = warning .. ' -Xcompiler "' .. host_warning .. '"' + end + return warning end -- cgit v1.3.1 From 43380eb2e3a4771d9ae43b905021c1a2810bf0eb Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 10:50:25 +0800 Subject: return nil for no flags --- xmake/modules/core/tools/nvcc.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 907703b6f..943a060d3 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -107,8 +107,8 @@ function nf_warning(self, level) , error = "-Werror" } - local warning = maps[level] or "" - + local warning = maps[level] + local host_warning = nil -- for cl.exe on windows, it is the only supported host compiler on the platform if is_plat("windows") then @@ -121,11 +121,15 @@ function nf_warning(self, level) end end - if host_warning then - warning = warning .. ' -Xcompiler "' .. host_warning .. '"' + if warning and host_warning then + return warning .. ' -Xcompiler "' .. host_warning .. '"' + elseif warning then + return warning + elseif host_warning then + return '-Xcompiler "' .. host_warning .. '"' + else + return nil end - - return warning end -- make the optimize flag -- cgit v1.3.1 From a8c3110cbd68ee41150daae583ae8789eeadcaaf Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 11:17:10 +0800 Subject: remove compiler check on *nix --- xmake/modules/core/tools/nvcc.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 943a060d3..8578832e6 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -115,10 +115,7 @@ function nf_warning(self, level) host_warning = cl_maps[level] -- for gcc/clang, or any gnu compatible compiler on *nix else - local gcc_clang_warning = gcc_clang_maps[level] - if gcc_clang_warning and self:has_flags(' -Xcompiler "' .. gcc_clang_warning .. '"', "cxflags") then - host_warning = gcc_clang_warning - end + host_warning = gcc_clang_maps[level] end if warning and host_warning then -- cgit v1.3.1 From 339b0a09220f367c76efbd70603014d8b05ccf00 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 18:01:27 +0800 Subject: reduce code --- xmake/modules/core/tools/nvcc.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 8578832e6..5993e9bb8 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -119,14 +119,11 @@ function nf_warning(self, level) end if warning and host_warning then - return warning .. ' -Xcompiler "' .. host_warning .. '"' - elseif warning then - return warning + warning = warning .. ' -Xcompiler "' .. host_warning .. '"' elseif host_warning then - return '-Xcompiler "' .. host_warning .. '"' - else - return nil + warning = '-Xcompiler "' .. host_warning .. '"' end + return warning end -- make the optimize flag -- cgit v1.3.1 From 9921a973ef37a89394f9a96366cd29eb70b6ba02 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 18:15:21 +0800 Subject: simplify --- xmake/modules/core/tools/nvcc.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 5993e9bb8..b284313a7 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -106,7 +106,7 @@ function nf_warning(self, level) , everything = "-Weverything -Wall -Wextra -Weffc++" , error = "-Werror" } - + local warning = maps[level] local host_warning = nil @@ -118,12 +118,11 @@ function nf_warning(self, level) host_warning = gcc_clang_maps[level] end - if warning and host_warning then - warning = warning .. ' -Xcompiler "' .. host_warning .. '"' - elseif host_warning then - warning = '-Xcompiler "' .. host_warning .. '"' + if host_warning then + warning = ((warning or "") .. ' -Xcompiler "' .. host_warning .. '"'):trim() end return warning + end -- make the optimize flag -- cgit v1.3.1 From f7252184c07d7708e9270a51523e46957e054f1c Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 18:17:21 +0800 Subject: remove empty flags --- xmake/modules/core/tools/nvcc.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index b284313a7..560145fde 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -73,9 +73,9 @@ function nf_warning(self, level) local maps = { none = "-w" - , less = "" - , more = "" - , all = "" + , less = nil + , more = nil + , all = nil , extra = "-Wreorder" , everything = "-Wreorder" , error = "-Werror" -- cgit v1.3.1 From 82277e5222154ff4463127681f2d18abb07d7f4a Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Tue, 21 May 2019 18:40:38 +0800 Subject: add flag mapping --- xmake/modules/core/tools/nvcc.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 560145fde..b830e2c65 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -40,10 +40,9 @@ function init(self) self:set("mapflags", { -- warnings - ["-W1"] = "" - , ["-W2"] = "" - , ["-W3"] = "" - , ["-W4"] = "-Wreorder" + ["-W4"] = "-Wreorder" + , ["-Wextra"] = "-Wreorder" + , ["-Weverything"] = "-Wreorder" }) -- init buildmodes -- cgit v1.3.1