diff options
| author | ruki <[email protected]> | 2022-04-20 00:44:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-20 00:44:22 +0800 |
| commit | 4941a07e94c5356ca33f60097797581a7fc06b51 (patch) | |
| tree | c6ff13d699ced7e8f6327ae34cd409e5251730a6 | |
| parent | 77e9c353d2d6c4236465ba343191e162445e884a (diff) | |
add filegroups api
| -rw-r--r-- | xmake/core/project/target.lua | 1 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 1 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua | 47 |
3 files changed, 40 insertions, 9 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 122082129..88ba324f4 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2039,6 +2039,7 @@ function target.apis() , "target.set_strip" , "target.set_rules" , "target.set_group" + , "target.add_filegroups" , "target.set_version" , "target.set_license" , "target.set_enabled" diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 2560faa77..52ef5c7f3 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -576,6 +576,7 @@ function make(outputdir, vsinfo) _target.kind = target:kind() _target.scriptdir = target:scriptdir() _target.info = _target.info or {} + _target.instance = target table.insert(_target.info, _make_targetinfo(mode, arch, target, _target.project_dir)) -- save all sourcefiles and headerfiles diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua index fb47926ed..e66f6db96 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua @@ -53,16 +53,45 @@ end -- make filter function _make_filter(filepath, target, vcxprojdir) - - -- make filter - local filter = path.relative(path.absolute(path.directory(filepath)), target.scriptdir or vcxprojdir) - - -- is '.'? no filter - if filter and filter == '.' then - filter = nil + local filter + local targetinst = assert(target.instance, "target instance not found!") + local filegroups = targetinst:get("filegroups") + if filegroups then + filepath = path.absolute(filepath) + local scriptdir = target.scriptdir + for _, filegroup in ipairs(filegroups) do + local rootdir = targetinst:extraconf("filegroups", filegroup, "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 = targetinst:extraconf("filegroups", filegroup, "files") or "**" + local mode = targetinst:extraconf("filegroups", filegroup, "mode") + for _, filepattern in ipairs(files) do + filepattern = path.pattern(path.translate(filepattern)) + if fileitem:match(filepattern) then + if mode == "plain" then + filter = path.translate(filegroup) + else + -- file tree mode (default) + filter = path.join(filegroup, path.directory(fileitem)) + end + if filter and filter == '.' then + filter = nil + end + break + end + end + end + end + if not filter then + -- use the default filter rule + filter = path.relative(path.absolute(path.directory(filepath)), target.scriptdir or vcxprojdir) + if filter and filter == '.' then + filter = nil + end end - - -- ok? return filter end |
