diff options
| author | ruki <[email protected]> | 2026-07-08 21:49:56 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-08 21:49:56 +0800 |
| commit | 03e4bc9076d6cd9e642f4a9c565c85757db72ce2 (patch) | |
| tree | b7ff177a4734ea7634cf739ea9b2deaa34b7674e /xmake/plugins/project/vstudio/impl | |
| parent | 0a2255cc281327f60a53d321705f607ab3c72e8f (diff) | |
| parent | 4e518789d0509056bbdcd9165af03ea8bbfebfb8 (diff) | |
Merge pull request #7629 from xmake-io/vsxmake
Improve custom source types in Solution Explorer
Diffstat (limited to 'xmake/plugins/project/vstudio/impl')
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 10 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua | 12 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vsutils.lua | 41 |
3 files changed, 61 insertions, 2 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index f1f44c3a8..24e1a70ac 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -1438,6 +1438,16 @@ function _make_source_files(vcxprojfile, vsinfo, target) end end vcxprojfile:leave("</ItemGroup>") + + -- add other files (e.g. files added by add_files but handled by a custom rule), for display only + local otherfiles = vsutils.otherfiles(target) + if #otherfiles > 0 then + vcxprojfile:enter("<ItemGroup>") + for _, otherfile in ipairs(otherfiles) do + vcxprojfile:print("<None Include=\"%s\" />", path.relative(path.absolute(otherfile), target.project_dir)) + end + vcxprojfile:leave("</ItemGroup>") + end end -- make vcxproj diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua index ed9002662..6c4c0ea8d 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua @@ -23,8 +23,10 @@ -- -- imports +import("core.base.hashset") import("core.tool.compiler") import("vsfile") +import("vsutils") -- make header function _make_header(filtersfile, vsinfo) @@ -147,14 +149,20 @@ end -- make sources function _make_sources(filtersfile, vsinfo, target, vcxprojdir) + -- the source files that are not natively built by VS, list them as <None> for display only + local otherfiles = hashset.from(vsutils.otherfiles(target)) + -- the files displayed as include files (e.g. also added by add_extrafiles), skip them to avoid duplicate + local includefiles = hashset.from(table.join(target.headerfiles or {}, target.extrafiles or {})) + -- and sources filtersfile:enter("<ItemGroup>") for _, sourcefile in ipairs(target.sourcefiles) do local filter = _make_filter(sourcefile, target, vcxprojdir) - if filter then + if filter and not includefiles:has(sourcefile) then local nodename local ext = path.extension(sourcefile) - if ext == "asm" then nodename = "CustomBuild" + if otherfiles:has(sourcefile) then nodename = "None" + elseif ext == "asm" then nodename = "CustomBuild" elseif ext == "cu" then nodename = "CudaCompile" else nodename = "ClCompile" end diff --git a/xmake/plugins/project/vstudio/impl/vsutils.lua b/xmake/plugins/project/vstudio/impl/vsutils.lua index 30832ae3f..2cf5e7bdb 100644 --- a/xmake/plugins/project/vstudio/impl/vsutils.lua +++ b/xmake/plugins/project/vstudio/impl/vsutils.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.hashset") import("core.project.config") import("core.project.project") import("core.cache.memcache") @@ -64,6 +65,46 @@ function translate_path(filepath) return (filepath:gsub("::", "#")) end +-- get the source files that are not natively built by VS, e.g. files added by add_files but handled +-- by a custom rule. we list them as <None> in the project for display only (like add_extrafiles). +-- this must be consistent with vs201x_vcxproj._make_source_files. +-- @see https://github.com/xmake-io/xmake/issues/7619 +function otherfiles(target) + + -- collect the source files that are natively built by VS + local builtfiles = hashset.new() + for _, targetinfo in ipairs(target.info or {}) do + for _, sourcebatch in pairs(targetinfo.sourcebatches or {}) do + local sourcekind = sourcebatch.sourcekind + local rulename = sourcebatch.rulename + if rulename == "c.build" or rulename == "c++.build" or rulename == "c++.build.modules" + or sourcekind == "as" or sourcekind == "mrc" or sourcekind == "cu" then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + builtfiles:insert(sourcefile) + end + end + end + end + + -- exclude the header/extra files and the precompiled header to avoid duplicate display + local excludefiles = hashset.from(table.join(target.headerfiles or {}, target.extrafiles or {})) + if target.pcheader then + excludefiles:insert(target.pcheader) + end + if target.pcxxheader then + excludefiles:insert(target.pcxxheader) + end + + -- the remaining source files are the custom files + local results = {} + for _, sourcefile in ipairs(target.sourcefiles or {}) do + if not builtfiles:has(sourcefile) and not excludefiles:has(sourcefile) then + table.insert(results, sourcefile) + end + end + return results +end + function reset_config_and_caches(mode, arch) -- reload config, project and platform -- modify config |
