summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-04-20 22:37:51 +0800
committerruki <[email protected]>2022-04-20 22:37:51 +0800
commitac4e75aa8863be23f984a44a3b05f5855251441a (patch)
tree40311c7ef5fb0ea0558b1013db03956629c295c2
parent8cf2fc8a4af32248837c7a48e7a0028b65f02979 (diff)
add source group for cmake
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua44
1 files changed, 35 insertions, 9 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index ee056c5b4..0a1b1e3c8 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -216,24 +216,50 @@ function _add_target_sources(cmakelists, target)
end
-- add target source groups
+-- @see https://github.com/xmake-io/xmake/issues/1149
function _add_target_source_groups(cmakelists, target)
- --[[TODO
local filegroups = target:get("filegroups")
for _, filegroup in ipairs(filegroups) do
local files = target:extraconf("filegroups", filegroup, "files") or "**"
local mode = target:extraconf("filegroups", filegroup, "mode")
- if mode and mode == "plain" then
- mode = ""
- else
- mode = "TREE "
- end
local rootdir = target:extraconf("filegroups", filegroup, "rootdir")
assert(rootdir, "please set root directory, e.g. add_filegroups(%s, {rootdir = 'xxx'})", filegroup)
+ local sources = {}
+ local recurse_sources = {}
+ if path.is_absolute(rootdir) then
+ rootdir = _get_unix_path(rootdir)
+ else
+ rootdir = string.format("${CMAKE_CURRENT_SOURCE_DIR}/%s", _get_unix_path(rootdir))
+ end
for _, filepattern in ipairs(files) do
- cmakelists:print("source_group(%s%s %s REGULAR_EXPRESSION %s)",
- mode, _get_unix_path(filegroup), _get_unix_path(rootdir), _get_unix_path(filepattern))
+ if filepattern:find("**", 1, true) then
+ filepattern = filepattern:gsub("%*%*", "*")
+ table.insert(recurse_sources, _get_unix_path(path.join(rootdir, filepattern)))
+ else
+ table.insert(sources, _get_unix_path(path.join(rootdir, filepattern)))
+ end
end
- end]]
+ if #sources > 0 then
+ cmakelists:print("FILE(GLOB %s_GROUP_SOURCE_LIST %s)", target:name(), table.concat(sources, " "))
+ if mode and mode == "plain" then
+ cmakelists:print("source_group(%s FILES ${%s_GROUP_SOURCE_LIST})",
+ _get_unix_path(filegroup), target:name())
+ else
+ cmakelists:print("source_group(TREE %s PREFIX %s FILES ${%s_GROUP_SOURCE_LIST})",
+ rootdir, _get_unix_path(filegroup), target:name())
+ end
+ end
+ if #recurse_sources > 0 then
+ cmakelists:print("FILE(GLOB_RECURSE %s_GROUP_RECURSE_SOURCE_LIST %s)", target:name(), table.concat(recurse_sources, " "))
+ if mode and mode == "plain" then
+ cmakelists:print("source_group(%s FILES ${%s_GROUP_RECURSE_SOURCE_LIST})",
+ _get_unix_path(filegroup), target:name())
+ else
+ cmakelists:print("source_group(TREE %s PREFIX %s FILES ${%s_GROUP_RECURSE_SOURCE_LIST})",
+ rootdir, _get_unix_path(filegroup), target:name())
+ end
+ end
+ end
end
-- add target precompilied header