summaryrefslogtreecommitdiff
path: root/xmake/plugins/project/vstudio
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-12 22:32:36 +0800
committerGitHub <[email protected]>2021-12-12 22:32:36 +0800
commit20f9cb8dc40760dc7d117136ca47ca52c854dc2e (patch)
treec95d9e8b1f2af850368392cd9c065d7f40f1f6fd /xmake/plugins/project/vstudio
parent5c4adb14e1f45b40bb3d90a9459386f67f08c15f (diff)
parent89a488735ab235ee856bb61f5821f429013d6c2e (diff)
Merge pull request #1904 from SirLynix/vsproject_fix
Improve vstudio
Diffstat (limited to 'xmake/plugins/project/vstudio')
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua3
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua118
2 files changed, 73 insertions, 48 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 3c7d62737..bf76b13dc 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -243,6 +243,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 d56c1015d..154e0763b 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("<PropertyGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">", targetinfo.mode, targetinfo.arch)
- vcxprojfile:print("<OutDir>%s\\</OutDir>", path.relative(path.absolute(targetinfo.targetdir), vcxprojdir))
- vcxprojfile:print("<IntDir>%s\\</IntDir>", path.relative(path.absolute(targetinfo.objectdir), vcxprojdir))
+ vcxprojfile:print("<OutDir>%s\\</OutDir>", _make_dirs(targetinfo.targetdir, vcxprojdir))
+ vcxprojfile:print("<IntDir>%s\\</IntDir>", _make_dirs(targetinfo.objectdir, vcxprojdir))
vcxprojfile:print("<TargetName>%s</TargetName>", path.basename(targetinfo.targetfile))
vcxprojfile:print("<TargetExt>%s</TargetExt>", path.extension(targetinfo.targetfile))
@@ -250,6 +243,13 @@ function _make_configurations(vcxprojfile, vsinfo, target, vcxprojdir)
end
vcxprojfile:leave("</PropertyGroup>")
end
+
+ -- make Debugger
+ for _, targetinfo in ipairs(target.info) do
+ vcxprojfile:enter("<PropertyGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\" Label=\"Debugger\">", targetinfo.mode, targetinfo.arch)
+ vcxprojfile:print("<LocalDebuggerWorkingDirectory>%s</LocalDebuggerWorkingDirectory>", _make_dirs(targetinfo.rundir, vcxprojdir))
+ vcxprojfile:leave("</PropertyGroup>")
+ end
end
-- make source options
@@ -288,6 +288,8 @@ function _make_source_options(vcxprojfile, flags, condition)
vcxprojfile:print("<WarningLevel%s>Level2</WarningLevel>", condition)
elseif flagstr:find("[%-/]W3") then
vcxprojfile:print("<WarningLevel%s>Level3</WarningLevel>", condition)
+ elseif flagstr:find("[%-/]W4") then
+ vcxprojfile:print("<WarningLevel%s>Level4</WarningLevel>", condition)
elseif flagstr:find("[%-/]Wall") then
vcxprojfile:print("<WarningLevel%s>EnableAllWarnings</WarningLevel>", condition)
else
@@ -297,6 +299,26 @@ function _make_source_options(vcxprojfile, flags, condition)
vcxprojfile:print("<TreatWarningAsError%s>true</TreatWarningAsError>", condition)
end
+ -- make ExternalWarningLevel
+ if flagstr:find("[%-/]external:W1") then
+ vcxprojfile:print("<ExternalWarningLevel%s>Level1</ExternalWarningLevel>", condition)
+ elseif flagstr:find("[%-/]external:W2") then
+ vcxprojfile:print("<ExternalWarningLevel%s>Level2</ExternalWarningLevel>", condition)
+ elseif flagstr:find("[%-/]external:W3") then
+ vcxprojfile:print("<ExternalWarningLevel%s>Level3</ExternalWarningLevel>", condition)
+ elseif flagstr:find("[%-/]external:W4") then
+ vcxprojfile:print("<ExternalWarningLevel%s>Level4</ExternalWarningLevel>", condition)
+ else
+ vcxprojfile:print("<ExternalWarningLevel%s>TurnOffAllWarnings</ExternalWarningLevel>", condition)
+ end
+
+ -- make ExternalTemplatesDiagnostics
+ if flagstr:find("[%-/]external:templates-") then
+ vcxprojfile:print("<ExternalTemplatesDiagnostics%s>true</ExternalTemplatesDiagnostics>", condition)
+ else
+ vcxprojfile:print("<ExternalTemplatesDiagnostics%s>false</ExternalTemplatesDiagnostics>", condition)
+ end
+
-- make PreprocessorDefinitions
local defstr = ""
for _, flag in ipairs(flags) do
@@ -334,7 +356,7 @@ function _make_source_options(vcxprojfile, flags, condition)
-- handle multi processor compilation
if flagstr:find("[%-/]Gm-") or not flagstr:find("[%-/]Gm") then
vcxprojfile:print("<MinimalRebuild%s>false</MinimalRebuild>", condition)
- if flagstr:find("[%-/]MP") then
+ if not flagstr:find("[%-/]MP1") then
vcxprojfile:print("<MultiProcessorCompilation%s>true</MultiProcessorCompilation>", condition)
end
end
@@ -357,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", "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", "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
@@ -550,7 +572,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 +582,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