From e0a66639122aef90577f67a1e2b7de664fe31e89 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sat, 11 Dec 2021 23:44:24 +0100 Subject: Project: fix common flag search was wrongly handling the case where a flag was present multiple times --- xmake/plugins/project/make/makefile.lua | 4 ++-- xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua index f9f0581c0..601f920c9 100644 --- a/xmake/plugins/project/make/makefile.lua +++ b/xmake/plugins/project/make/makefile.lua @@ -109,7 +109,7 @@ function _make_common_flags(target, sourcekind, sourcebatch) -- make common flags local commonflags = {} for _, flag in ipairs(first_flags) do - if flags_stats[flag] == files_count then + if flags_stats[flag] >= files_count then table.insert(commonflags, flag) end end @@ -119,7 +119,7 @@ function _make_common_flags(target, sourcekind, sourcebatch) for sourcefile, flags in pairs(sourceflags) do local otherflags = {} for _, flag in ipairs(flags) do - if flags_stats[flag] ~= files_count then + if flags_stats[flag] < files_count then table.insert(otherflags, flag) end end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index d56c1015d..94dd7150e 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -550,7 +550,7 @@ function _make_common_items(vcxprojfile, vsinfo, target, vcxprojdir) -- make common flags targetinfo.commonflags = {} for _, flag in ipairs(first_flags) do - if flags_stats[flag] == files_count then + if flags_stats[flag] >= files_count then table.insert(targetinfo.commonflags, flag) end end @@ -560,7 +560,7 @@ function _make_common_items(vcxprojfile, vsinfo, target, vcxprojdir) for sourcefile, flags in pairs(targetinfo.sourceflags) do local otherflags = {} for _, flag in ipairs(flags) do - if flags_stats[flag] ~= files_count then + if flags_stats[flag] < files_count then table.insert(otherflags, flag) end end -- cgit v1.3.1 From d978a21418a48d0c25b32805abd4ed2fa31f69d4 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sat, 11 Dec 2021 23:45:23 +0100 Subject: project/vstudio: Enable MultiProcessorCompilation by default --- xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 94dd7150e..74f219320 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -334,7 +334,7 @@ function _make_source_options(vcxprojfile, flags, condition) -- handle multi processor compilation if flagstr:find("[%-/]Gm-") or not flagstr:find("[%-/]Gm") then vcxprojfile:print("false", condition) - if flagstr:find("[%-/]MP") then + if not flagstr:find("[%-/]MP1") then vcxprojfile:print("true", condition) end end @@ -357,7 +357,7 @@ function _make_source_options(vcxprojfile, flags, condition) -- make AdditionalOptions local additional_flags = {} - local excludes = {"Od", "Os", "O0", "O1", "O2", "Ot", "Ox", "W0", "W1", "W2", "W3", "WX", "Wall", "Zi", "ZI", "Z7", "MT", "MTd", "MD", "MDd", "TP", "Fd", "fp", "I", "D", "Gm-", "Gm"} + local excludes = {"Od", "Os", "O0", "O1", "O2", "Ot", "Ox", "W0", "W1", "W2", "W3", "WX", "Wall", "Zi", "ZI", "Z7", "MT", "MTd", "MD", "MDd", "TP", "Fd", "fp", "I", "D", "Gm-", "Gm", "MP"} for _, flag in ipairs(flags) do local excluded = false for _, exclude in ipairs(excludes) do -- cgit v1.3.1 From d1cd32f266309971b033b2941abcf8aa02242501 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sat, 11 Dec 2021 23:46:19 +0100 Subject: project/vstudio: Fix external include dirs --- .../project/vstudio/impl/vs201x_vcxproj.lua | 81 ++++++++++------------ 1 file changed, 37 insertions(+), 44 deletions(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 74f219320..5b82dd7a2 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -27,6 +27,18 @@ import("core.tool.toolchain") import("private.utils.batchcmds") import("vsfile") +function _make_dirs(dir, vcxprojdir) + dir = dir:trim() + if #dir == 0 then + return "" + end + dir = path.translate(dir) + if not path.is_absolute(dir) then + dir = path.relative(path.absolute(dir), vcxprojdir) + end + return dir +end + -- get toolset version function _get_toolset_ver(targetinfo, vsinfo) @@ -66,18 +78,16 @@ function _make_compcmd(compargv, sourcefile, objectfile, vcxprojdir) end v = v:gsub("__sourcefile__", sourcefile) v = v:gsub("__objectfile__", objectfile) + -- -Idir or /Idir - v = v:gsub("([%-/]I)(.*)", function (I, dir) - dir = dir:trim() - if #dir == 0 then - return "" - end - dir = path.translate(dir) - if not path.is_absolute(dir) then - dir = path.relative(path.absolute(dir), vcxprojdir) - end - return I .. dir + -- handle external includes as well + for _, pattern in ipairs({"[%-/](I)(.*)", "[%-/](external:I)(.*)"}) do + v = v:gsub(pattern, function (flag, dir) + dir = _make_dirs(dir, vcxprojdir) + return "/" .. flag .. dir end) + end + table.insert(argv, v) end return table.concat(argv, " ") @@ -90,18 +100,15 @@ function _make_compflags(sourcefile, targetinfo, vcxprojdir) local flags = {} for _, flag in ipairs(targetinfo.compflags[sourcefile]) do - -- -Idir or /Idir - flag = flag:gsub("[%-/]I(.*)", function (dir) - dir = dir:trim() - if #dir == 0 then - return "" - end - dir = path.translate(dir) - if not path.is_absolute(dir) then - dir = path.relative(path.absolute(dir), vcxprojdir) - end - return "/I" .. dir - end) + -- handle external includes as well + for _, pattern in ipairs({"[%-/](I)(.*)", "[%-/](external:I)(.*)"}) do + + -- -Idir or /Idir + flag = flag:gsub(pattern, function (flag, dir) + dir = _make_dirs(dir, vcxprojdir) + return "/" .. flag .. dir + end) + end -- save flag table.insert(flags, flag) @@ -124,29 +131,15 @@ function _make_linkflags(targetinfo, vcxprojdir) -- replace -libpath:dir or /libpath:dir flag = flag:gsub(string.ipattern("[%-/]libpath:(.*)"), function (dir) - dir = dir:trim() - if #dir == 0 then - return "" - end - dir = path.translate(dir) - if not path.is_absolute(dir) then - dir = path.relative(path.absolute(dir), vcxprojdir) - end - return "/libpath:" .. dir - end) + dir = _make_dirs(dir, vcxprojdir) + return "/libpath:" .. dir + end) -- replace -def:dir or /def:dir flag = flag:gsub(string.ipattern("[%-/]def:(.*)"), function (dir) - dir = dir:trim() - if #dir == 0 then - return "" - end - dir = path.translate(dir) - if not path.is_absolute(dir) then - dir = path.relative(path.absolute(dir), vcxprojdir) - end - return "/def:" .. dir - end) + dir = _make_dirs(dir, vcxprojdir) + return "/def:" .. dir + end) -- save flag table.insert(flags, flag) @@ -240,8 +233,8 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) -- make OutputDirectory and IntermediateDirectory for _, targetinfo in ipairs(target.info) do vcxprojfile:enter("", targetinfo.mode, targetinfo.arch) - vcxprojfile:print("%s\\", path.relative(path.absolute(targetinfo.targetdir), vcxprojdir)) - vcxprojfile:print("%s\\", path.relative(path.absolute(targetinfo.objectdir), vcxprojdir)) + vcxprojfile:print("%s\\", _make_dirs(targetinfo.targetdir, vcxprojdir)) + vcxprojfile:print("%s\\", _make_dirs(targetinfo.objectdir, vcxprojdir)) vcxprojfile:print("%s", path.basename(targetinfo.targetfile)) vcxprojfile:print("%s", path.extension(targetinfo.targetfile)) -- cgit v1.3.1 From 6291b59a2433a4349dbd51e88290297349130ca6 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sat, 11 Dec 2021 23:46:36 +0100 Subject: project/vstudio: add rundir handling --- xmake/plugins/project/vstudio/impl/vs201x.lua | 4 ++++ xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 7 +++++++ 2 files changed, 11 insertions(+) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 3c7d62737..d835a4270 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -32,6 +32,7 @@ import("vs201x_vcxproj") import("vs201x_vcxproj_filters") import("core.cache.memcache") import("core.cache.localcache") +import("private.action.run.make_runenvs") import("private.action.require.install", {alias = "install_requires"}) import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()}) @@ -243,6 +244,9 @@ function _make_targetinfo(mode, arch, target) local linkflags = linker.linkflags(target:kind(), target:sourcekinds(), {target = target}) targetinfo.linkflags = linkflags + -- save execution dir (when executed from VS) + targetinfo.rundir = target:rundir() + -- use mfc? save the mfc runtime kind if target:rule("win.sdk.mfc.shared_app") or target:rule("win.sdk.mfc.shared") then targetinfo.usemfc = "Dynamic" diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 5b82dd7a2..19a1b20bd 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -213,6 +213,13 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) vcxprojfile:leave("") end + -- make Debugger + for _, targetinfo in ipairs(target.info) do + vcxprojfile:enter("", targetinfo.mode, targetinfo.arch) + vcxprojfile:print("%s", targetinfo.rundir) + vcxprojfile:leave("") + end + -- import Microsoft.Cpp.props vcxprojfile:print("") -- cgit v1.3.1 From 0a9fa4f1f43ebde6f12bce1afcb968a5f3e850a6 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sat, 11 Dec 2021 23:52:06 +0100 Subject: Remove make_runenvs imports (but it would be nice to handle runenvs as well) --- xmake/plugins/project/vstudio/impl/vs201x.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index d835a4270..bf76b13dc 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -32,7 +32,6 @@ import("vs201x_vcxproj") import("vs201x_vcxproj_filters") import("core.cache.memcache") import("core.cache.localcache") -import("private.action.run.make_runenvs") import("private.action.require.install", {alias = "install_requires"}) import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()}) -- cgit v1.3.1 From 94fff01ece05949fbc0cced5fff83f959b3f5ada Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sun, 12 Dec 2021 00:19:38 +0100 Subject: project/vstudio: Add support for /W4 warning level --- xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 19a1b20bd..b48d423a0 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -288,6 +288,8 @@ function _make_source_options(vcxprojfile, flags, condition) vcxprojfile:print("Level2", condition) elseif flagstr:find("[%-/]W3") then vcxprojfile:print("Level3", condition) + elseif flagstr:find("[%-/]W4") then + vcxprojfile:print("Level4", condition) elseif flagstr:find("[%-/]Wall") then vcxprojfile:print("EnableAllWarnings", condition) else @@ -357,7 +359,7 @@ function _make_source_options(vcxprojfile, flags, condition) -- make AdditionalOptions local additional_flags = {} - local excludes = {"Od", "Os", "O0", "O1", "O2", "Ot", "Ox", "W0", "W1", "W2", "W3", "WX", "Wall", "Zi", "ZI", "Z7", "MT", "MTd", "MD", "MDd", "TP", "Fd", "fp", "I", "D", "Gm-", "Gm", "MP"} + local excludes = {"Od", "Os", "O0", "O1", "O2", "Ot", "Ox", "W0", "W1", "W2", "W3", "W4", "WX", "Wall", "Zi", "ZI", "Z7", "MT", "MTd", "MD", "MDd", "TP", "Fd", "fp", "I", "D", "Gm-", "Gm", "MP"} for _, flag in ipairs(flags) do local excluded = false for _, exclude in ipairs(excludes) do -- cgit v1.3.1 From 3b0392340c94152238b2db03327415e553c44045 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sun, 12 Dec 2021 01:32:28 +0100 Subject: project/vstudio: Add support for ExternalWarningLevel and ExternalTemplatesDiagnostics --- .../project/vstudio/impl/vs201x_vcxproj.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index b48d423a0..fd14acbfe 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -299,6 +299,26 @@ function _make_source_options(vcxprojfile, flags, condition) vcxprojfile:print("true", condition) end + -- make ExternalWarningLevel + if flagstr:find("[%-/]external:W1") then + vcxprojfile:print("Level1", condition) + elseif flagstr:find("[%-/]external:W2") then + vcxprojfile:print("Level2", condition) + elseif flagstr:find("[%-/]external:W3") then + vcxprojfile:print("Level3", condition) + elseif flagstr:find("[%-/]external:W4") then + vcxprojfile:print("Level4", condition) + else + vcxprojfile:print("TurnOffAllWarnings", condition) + end + + -- make ExternalTemplatesDiagnostics + if flagstr:find("[%-/]external:templates-") then + vcxprojfile:print("true", condition) + else + vcxprojfile:print("false", condition) + end + -- make PreprocessorDefinitions local defstr = "" for _, flag in ipairs(flags) do @@ -359,7 +379,7 @@ function _make_source_options(vcxprojfile, flags, condition) -- make AdditionalOptions local additional_flags = {} - local excludes = {"Od", "Os", "O0", "O1", "O2", "Ot", "Ox", "W0", "W1", "W2", "W3", "W4", "WX", "Wall", "Zi", "ZI", "Z7", "MT", "MTd", "MD", "MDd", "TP", "Fd", "fp", "I", "D", "Gm-", "Gm", "MP"} + local excludes = {"Od", "Os", "O0", "O1", "O2", "Ot", "Ox", "W0", "W1", "W2", "W3", "W4", "WX", "Wall", "Zi", "ZI", "Z7", "MT", "MTd", "MD", "MDd", "TP", "Fd", "fp", "I", "D", "Gm-", "Gm", "MP", "external:W0", "external:W1", "external:W2", "external:W3", "external:W4", "external:templates-", "external:templates" } for _, flag in ipairs(flags) do local excluded = false for _, exclude in ipairs(excludes) do -- cgit v1.3.1 From faf3404c42491b7e1e1fa0ced8386321507f4c5c Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sun, 12 Dec 2021 14:27:31 +0100 Subject: project/vstudio: Fix Debugger rundir --- xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index fd14acbfe..b167468d7 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -213,13 +213,6 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) vcxprojfile:leave("") end - -- make Debugger - for _, targetinfo in ipairs(target.info) do - vcxprojfile:enter("", targetinfo.mode, targetinfo.arch) - vcxprojfile:print("%s", targetinfo.rundir) - vcxprojfile:leave("") - end - -- import Microsoft.Cpp.props vcxprojfile:print("") @@ -250,6 +243,13 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) end vcxprojfile:leave("") end + + -- make Debugger + for _, targetinfo in ipairs(target.info) do + vcxprojfile:enter("", targetinfo.mode, targetinfo.arch) + vcxprojfile:print("%s", targetinfo.rundir) + vcxprojfile:leave("") + end end -- make source options -- cgit v1.3.1 From f3b110572f3720905fc3ee97362d6055f5f29d78 Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sun, 12 Dec 2021 14:32:15 +0100 Subject: Update vs201x_vcxproj.lua --- xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index b167468d7..98f49c098 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -247,7 +247,7 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir) -- make Debugger for _, targetinfo in ipairs(target.info) do vcxprojfile:enter("", targetinfo.mode, targetinfo.arch) - vcxprojfile:print("%s", targetinfo.rundir) + vcxprojfile:print("%s", _make_dirs(targetinfo.rundir, vcxprojdir)) vcxprojfile:leave("") end end @@ -550,6 +550,7 @@ function _make_common_items(vcxprojfile, vsinfo, target, vcxprojdir) -- no common flags for asm if sourcekind ~= "as" then + local foundDebug = false for _, flag in ipairs(flags) do flags_stats[flag] = (flags_stats[flag] or 0) + 1 end -- cgit v1.3.1 From 89a488735ab235ee856bb61f5821f429013d6c2e Mon Sep 17 00:00:00 2001 From: Jérôme Leclercq Date: Sun, 12 Dec 2021 14:45:05 +0100 Subject: Update vs201x_vcxproj.lua --- xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'xmake/plugins/project') diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 98f49c098..154e0763b 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -550,7 +550,6 @@ function _make_common_items(vcxprojfile, vsinfo, target, vcxprojdir) -- no common flags for asm if sourcekind ~= "as" then - local foundDebug = false for _, flag in ipairs(flags) do flags_stats[flag] = (flags_stats[flag] or 0) + 1 end -- cgit v1.3.1