summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-22 22:52:23 +0800
committerruki <[email protected]>2021-02-22 22:52:23 +0800
commit67fc38bb41020f518d4ff40829bdf3520388c518 (patch)
treea57400e1d3fe92dfe5c5b922387fee4d8530617d
parentb6c0282918b7e10dd601c4300e125091e0cf2af0 (diff)
improve vs/vsxmake generator to support startproject
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_solution.lua40
-rw-r--r--xmake/plugins/project/vsxmake/getinfo.lua22
2 files changed, 50 insertions, 12 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua
index 45551e1da..4aeaa204a 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua
@@ -42,21 +42,39 @@ function _make_projects(slnfile, vsinfo)
-- make all targets
local groups = {}
+ local targets = {}
local vctool = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"
for targetname, target in pairs(project.targets()) do
if not target:isphony() then
- slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.vcxproj\", \"{%s}\"", vctool, targetname, targetname, targetname, hash.uuid4(targetname))
- for _, dep in ipairs(target:get("deps")) do
- slnfile:enter("ProjectSection(ProjectDependencies) = postProject")
- slnfile:print("{%s} = {%s}", hash.uuid4(dep), hash.uuid4(dep))
- slnfile:leave("EndProjectSection")
- end
- slnfile:leave("EndProject")
- local group_path = target:get("group")
- if group_path then
- for _, group_name in ipairs(path.split(group_path)) do
- groups[group_name] = hash.uuid4(group_name)
+ -- we need set startup project for default or binary target
+ -- @see https://github.com/xmake-io/xmake/issues/1249
+ if target:get("default") == true then
+ table.insert(targets, 1, target)
+ elseif target:kind() == "binary" then
+ local first_target = targets[1]
+ if not first_target or first_target:get("default") ~= true then
+ table.insert(targets, 1, target)
+ else
+ table.insert(targets, target)
end
+ else
+ table.insert(targets, target)
+ end
+ end
+ end
+ for _, target in ipairs(targets) do
+ local targetname = target:name()
+ slnfile:enter("Project(\"{%s}\") = \"%s\", \"%s\\%s.vcxproj\", \"{%s}\"", vctool, targetname, targetname, targetname, hash.uuid4(targetname))
+ for _, dep in ipairs(target:get("deps")) do
+ slnfile:enter("ProjectSection(ProjectDependencies) = postProject")
+ slnfile:print("{%s} = {%s}", hash.uuid4(dep), hash.uuid4(dep))
+ slnfile:leave("EndProjectSection")
+ end
+ slnfile:leave("EndProject")
+ local group_path = target:get("group")
+ if group_path then
+ for _, group_name in ipairs(path.split(group_path)) do
+ groups[group_name] = hash.uuid4(group_name)
end
end
end
diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua
index b770152b8..e5cbaa196 100644
--- a/xmake/plugins/project/vsxmake/getinfo.lua
+++ b/xmake/plugins/project/vsxmake/getinfo.lua
@@ -438,7 +438,27 @@ function main(outputdir, vsinfo)
target._deps[v] = targets[v]
end
end
- vsinfo.targets = table.keys(targets)
+
+ -- we need set startup project for default or binary target
+ -- @see https://github.com/xmake-io/xmake/issues/1249
+ local targetnames = {}
+ for targetname, target in pairs(project.targets()) do
+ if not target:isphony() then
+ if target:get("default") == true then
+ table.insert(targetnames, 1, targetname)
+ elseif target:kind() == "binary" then
+ local first_target = targetnames[1] and project.target(targetnames[1])
+ if not first_target or first_target:get("default") ~= true then
+ table.insert(targetnames, 1, targetname)
+ else
+ table.insert(targetnames, targetname)
+ end
+ else
+ table.insert(targetnames, targetname)
+ end
+ end
+ end
+ vsinfo.targets = targetnames
vsinfo._targets = targets
return vsinfo
end