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/vsutils.lua | |
| 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/vsutils.lua')
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vsutils.lua | 41 |
1 files changed, 41 insertions, 0 deletions
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 |
