diff options
| author | SirLynix <[email protected]> | 2023-07-31 19:35:51 +0200 |
|---|---|---|
| committer | SirLynix <[email protected]> | 2023-07-31 19:35:51 +0200 |
| commit | 5d92eb8501d693b15e0960f90d34983608fa6758 (patch) | |
| tree | 121e5a878b80e5f5ae52082201d442ee1878a83b | |
| parent | 05b62d2a23b5ad1cc8cf5df357f8c8cd0229e8c2 (diff) | |
vsproject generation: handle filegroups merging
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 20 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua | 44 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 64 |
3 files changed, 82 insertions, 46 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 39cfcc65c..cc00c6b8e 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -589,8 +589,24 @@ function make(outputdir, vsinfo) table.sort(_target.headerfiles) -- save file groups - _target.filegroups = target:get("filegroups") - _target.filegroups_extraconf = target:extraconf("filegroups") + _target.filegroups = table.unique(table.join(_target.filegroups or {}, target:get("filegroups"))) + + for filegroup, groupconf in pairs(target:extraconf("filegroups")) do + _target.filegroups_extraconf = _target.filegroups_extraconf or {} + local mergedconf = _target.filegroups_extraconf[filegroup] + if not mergedconf then + mergedconf = {} + _target.filegroups_extraconf[filegroup] = mergedconf + end + + if groupconf.rootdir then + mergedconf.rootdir = table.unique(table.join(mergedconf.rootdir or {}, table.wrap(groupconf.rootdir))) + end + if groupconf.files then + mergedconf.files = table.unique(table.join(mergedconf.files or {}, table.wrap(groupconf.files))) + end + mergedconf.plain = groupconf.plain or mergedconf.plain + end -- make target headers _make_targetheaders(mode, arch, target, mode_idx == #vsinfo.modes and arch_idx == 2) diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua index eda9518d1..c894e3bb6 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua @@ -76,30 +76,32 @@ function _make_filter(filepath, target, vcxprojdir) local extraconf = filegroups_extraconf[filegroup] or {} local rootdir = extraconf.rootdir assert(rootdir, "please set root directory, e.g. add_filegroups(%s, {rootdir = 'xxx'})", filegroup) - if not path.is_absolute(rootdir) then - rootdir = path.absolute(rootdir, scriptdir) - end - local fileitem = path.relative(filepath, rootdir) - local files = extraconf.files or "**" - local mode = extraconf.mode - for _, filepattern in ipairs(files) do - filepattern = path.pattern(path.absolute(path.join(rootdir, filepattern))) - if filepath:match(filepattern) then - if mode == "plain" then - filter = path.normalize(filegroup) - is_plain = true - else - -- file tree mode (default) - if filegroup ~= "" then - filter = path.normalize(path.join(filegroup, path.directory(fileitem))) + for _, rootdir in ipairs(table.wrap(rootdir)) do + if not path.is_absolute(rootdir) then + rootdir = path.absolute(rootdir, scriptdir) + end + local fileitem = path.relative(filepath, rootdir) + local files = extraconf.files or "**" + local mode = extraconf.mode + for _, filepattern in ipairs(files) do + filepattern = path.pattern(path.absolute(path.join(rootdir, filepattern))) + if filepath:match(filepattern) then + if mode == "plain" then + filter = path.normalize(filegroup) + is_plain = true else - filter = path.normalize(path.directory(fileitem)) + -- file tree mode (default) + if filegroup ~= "" then + filter = path.normalize(path.join(filegroup, path.directory(fileitem))) + else + filter = path.normalize(path.directory(fileitem)) + end end + if filter and filter == '.' then + filter = nil + end + break end - if filter and filter == '.' then - filter = nil - end - break end end end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 031cbd66c..861d6a9e6 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -325,30 +325,32 @@ function _make_filter(filepath, target, vcxprojdir) local extraconf = filegroups_extraconf[filegroup] or {} local rootdir = extraconf.rootdir assert(rootdir, "please set root directory, e.g. add_filegroups(%s, {rootdir = 'xxx'})", filegroup) - if not path.is_absolute(rootdir) then - rootdir = path.absolute(rootdir, scriptdir) - end - local fileitem = path.relative(filepath, rootdir) - local files = extraconf.files or "**" - local mode = extraconf.mode - for _, filepattern in ipairs(files) do - filepattern = path.pattern(path.absolute(path.join(rootdir, filepattern))) - if filepath:match(filepattern) then - if mode == "plain" then - filter = path.normalize(filegroup) - is_plain = true - else - -- file tree mode (default) - if filegroup ~= "" then - filter = path.normalize(path.join(filegroup, path.directory(fileitem))) + for _, rootdir in ipairs(table.wrap(rootdir)) do + if not path.is_absolute(rootdir) then + rootdir = path.absolute(rootdir, scriptdir) + end + local fileitem = path.relative(filepath, rootdir) + local files = extraconf.files or "**" + local mode = extraconf.mode + for _, filepattern in ipairs(files) do + filepattern = path.pattern(path.absolute(path.join(rootdir, filepattern))) + if filepath:match(filepattern) then + if mode == "plain" then + filter = path.normalize(filegroup) + is_plain = true else - filter = path.normalize(path.directory(fileitem)) + -- file tree mode (default) + if filegroup ~= "" then + filter = path.normalize(path.join(filegroup, path.directory(fileitem))) + else + filter = path.normalize(path.directory(fileitem)) + end end + if filter and filter == '.' then + filter = nil + end + break end - if filter and filter == '.' then - filter = nil - end - break end end end @@ -497,8 +499,24 @@ function main(outputdir, vsinfo) table.sort(_target.headerfiles) -- save file groups - _target.filegroups = target:get("filegroups") - _target.filegroups_extraconf = target:extraconf("filegroups") + _target.filegroups = table.unique(table.join(_target.filegroups or {}, target:get("filegroups"))) + + for filegroup, groupconf in pairs(target:extraconf("filegroups")) do + _target.filegroups_extraconf = _target.filegroups_extraconf or {} + local mergedconf = _target.filegroups_extraconf[filegroup] + if not mergedconf then + mergedconf = {} + _target.filegroups_extraconf[filegroup] = mergedconf + end + + if groupconf.rootdir then + mergedconf.rootdir = table.unique(table.join(mergedconf.rootdir or {}, table.wrap(groupconf.rootdir))) + end + if groupconf.files then + mergedconf.files = table.unique(table.join(mergedconf.files or {}, table.wrap(groupconf.files))) + end + mergedconf.plain = groupconf.plain or mergedconf.plain + end -- save deps _target.deps = table.unique(table.join(_target.deps or {}, table.orderkeys(target:deps()), nil)) |
