diff options
| author | ruki <[email protected]> | 2022-02-15 22:34:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-02-15 09:29:07 +0800 |
| commit | 6a555fc9a10749e6189464dd659c87116f60a7a1 (patch) | |
| tree | 3fdbef555e043c9d00f653bff91f5a5bf097bcc8 /xmake/plugins/project/vstudio/impl | |
| parent | 8c0b564b4f3cdb62680dc70b91bc39a335f5d429 (diff) | |
support phony and headeronly target for vs generator
Diffstat (limited to 'xmake/plugins/project/vstudio/impl')
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 45 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_solution.lua | 60 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 14 |
3 files changed, 59 insertions, 60 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index b72827e0b..b7186dab5 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -261,6 +261,9 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) -- save target kind targetinfo.targetkind = target:kind() + if target:is_phony() or target:is_headeronly() then + return targetinfo + end -- save target file targetinfo.targetfile = target:targetfile() @@ -357,8 +360,6 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) -- save custom commands targetinfo.commands = _make_custom_commands(target) - - -- ok return targetinfo end @@ -550,33 +551,31 @@ function make(outputdir, vsinfo) -- save targets for targetname, target in pairs(project.targets()) do - if not target:is_phony() then - -- make target with the given mode and arch - targets[targetname] = targets[targetname] or {} - local _target = targets[targetname] + -- make target with the given mode and arch + targets[targetname] = targets[targetname] or {} + local _target = targets[targetname] - -- the vcxproj directory - _target.project_dir = path.join(vsinfo.solution_dir, targetname) + -- the vcxproj directory + _target.project_dir = path.join(vsinfo.solution_dir, targetname) - -- save c/c++ precompiled header - _target.pcheader = target:pcheaderfile("c") -- header.h - _target.pcxxheader = target:pcheaderfile("cxx") -- header.[hpp|inl] + -- save c/c++ precompiled header + _target.pcheader = target:pcheaderfile("c") -- header.h + _target.pcxxheader = target:pcheaderfile("cxx") -- header.[hpp|inl] - -- init target info - _target.name = targetname - _target.kind = target:kind() - _target.scriptdir = target:scriptdir() - _target.info = _target.info or {} - table.insert(_target.info, _make_targetinfo(mode, arch, target, _target.project_dir)) + -- init target info + _target.name = targetname + _target.kind = target:kind() + _target.scriptdir = target:scriptdir() + _target.info = _target.info or {} + table.insert(_target.info, _make_targetinfo(mode, arch, target, _target.project_dir)) - -- save all sourcefiles and headerfiles - _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) - _target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles()))) + -- save all sourcefiles and headerfiles + _target.sourcefiles = table.unique(table.join(_target.sourcefiles or {}, (target:sourcefiles()))) + _target.headerfiles = table.unique(table.join(_target.headerfiles or {}, (target:headerfiles()))) - -- make target headers - _make_targetheaders(mode, arch, target, mode_idx == #vsinfo.modes and arch_idx == 2) - end + -- make target headers + _make_targetheaders(mode, arch, target, mode_idx == #vsinfo.modes and arch_idx == 2) end end end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua index c4628190f..7d285c154 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_solution.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_solution.lua @@ -45,21 +45,19 @@ function _make_projects(slnfile, vsinfo) local targets = {} local vctool = "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942" for targetname, target in pairs(project.targets()) do - if not target:is_phony() then - -- 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 + -- 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:is_binary() then + local first_target = targets[1] + if not first_target or first_target:is_default() then table.insert(targets, 1, target) - elseif target:is_binary() then - local first_target = targets[1] - if not first_target or first_target:is_default() then - table.insert(targets, 1, target) - else - table.insert(targets, target) - end else table.insert(targets, target) end + else + table.insert(targets, target) end end for _, target in ipairs(targets) do @@ -105,13 +103,11 @@ function _make_global(slnfile, vsinfo) -- add project configuration platforms slnfile:enter("GlobalSection(ProjectConfigurationPlatforms) = postSolution") for targetname, target in pairs(project.targets()) do - if not target:is_phony() then - for _, mode in ipairs(vsinfo.modes) do - for _, arch in ipairs(vsinfo.archs) do - local vs_arch = _vs_arch(arch) - slnfile:print("{%s}.%s|%s.ActiveCfg = %s|%s", hash.uuid4(targetname), mode, arch, mode, vs_arch) - slnfile:print("{%s}.%s|%s.Build.0 = %s|%s", hash.uuid4(targetname), mode, arch, mode, vs_arch) - end + for _, mode in ipairs(vsinfo.modes) do + for _, arch in ipairs(vsinfo.archs) do + local vs_arch = _vs_arch(arch) + slnfile:print("{%s}.%s|%s.ActiveCfg = %s|%s", hash.uuid4(targetname), mode, arch, mode, vs_arch) + slnfile:print("{%s}.%s|%s.Build.0 = %s|%s", hash.uuid4(targetname), mode, arch, mode, vs_arch) end end end @@ -126,21 +122,19 @@ function _make_global(slnfile, vsinfo) slnfile:enter("GlobalSection(NestedProjects) = preSolution") local subgroups = {} for targetname, target in pairs(project.targets()) do - if not target:is_phony() then - local group_path = target:get("group") - if group_path then - -- target -> group - local group_name = path.filename(group_path) - slnfile:print("{%s} = {%s}", hash.uuid4(targetname), hash.uuid4(group_name)) - -- group -> group -> ... - local group_names = path.split(group_path) - for idx, group_name in ipairs(group_names) do - local key = group_name .. (group_name_sub or "") - local group_name_sub = group_names[idx + 1] - if group_name_sub and not subgroups[key] then - slnfile:print("{%s} = {%s}", hash.uuid4(group_name_sub), hash.uuid4(group_name)) - subgroups[key] = true - end + local group_path = target:get("group") + if group_path then + -- target -> group + local group_name = path.filename(group_path) + slnfile:print("{%s} = {%s}", hash.uuid4(targetname), hash.uuid4(group_name)) + -- group -> group -> ... + local group_names = path.split(group_path) + for idx, group_name in ipairs(group_names) do + local key = group_name .. (group_name_sub or "") + local group_name_sub = group_names[idx + 1] + if group_name_sub and not subgroups[key] then + slnfile:print("{%s} = {%s}", hash.uuid4(group_name_sub), hash.uuid4(group_name)) + subgroups[key] = true end end end diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 88780380a..febbbe09b 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -205,7 +205,7 @@ function _make_configurations(vcxprojfile, vsinfo, target) -- make Configuration for _, targetinfo in ipairs(target.info) do vcxprojfile:enter("<PropertyGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\" Label=\"Configuration\">", targetinfo.mode, targetinfo.arch) - vcxprojfile:print("<ConfigurationType>%s</ConfigurationType>", assert(configuration_types[target.kind])) + vcxprojfile:print("<ConfigurationType>%s</ConfigurationType>", configuration_types[target.kind] or "Unknown") vcxprojfile:print("<PlatformToolset>%s</PlatformToolset>", _get_toolset_ver(targetinfo, vsinfo)) vcxprojfile:print("<CharacterSet>%s</CharacterSet>", targetinfo.unicode and "Unicode" or "MultiByte") if targetinfo.usemfc then @@ -230,6 +230,9 @@ function _make_configurations(vcxprojfile, vsinfo, target) -- make UserMacros vcxprojfile:print("<PropertyGroup Label=\"UserMacros\" />") + if not configuration_types[target.kind] then + return + end -- make OutputDirectory and IntermediateDirectory for _, targetinfo in ipairs(target.info) do @@ -463,9 +466,6 @@ end -- make common item function _make_common_item(vcxprojfile, vsinfo, target, targetinfo) - -- enter ItemDefinitionGroup - vcxprojfile:enter("<ItemDefinitionGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">", targetinfo.mode, targetinfo.arch) - -- init the linker kinds local linkerkinds = { @@ -473,6 +473,12 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo) , static = "Lib" , shared = "Link" } + if not linkerkinds[targetinfo.targetkind] then + return + end + + -- enter ItemDefinitionGroup + vcxprojfile:enter("<ItemDefinitionGroup Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">", targetinfo.mode, targetinfo.arch) -- for linker? vcxprojfile:enter("<%s>", linkerkinds[targetinfo.targetkind]) |
