summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-02-19 22:58:39 +0800
committerruki <[email protected]>2024-02-19 22:58:39 +0800
commit6793b55d1a7b0f79bc3cf2d26f3e5c94f8f57fdb (patch)
treebedf52fa48698ae69f15b79571803e491f74bedc
parent42a99c91fca4e56d5166751cd7667886e1a6801f (diff)
add native c++ module support for cmake
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua23
1 files changed, 20 insertions, 3 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index 503cbd384..43f7e63f6 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -134,16 +134,29 @@ function _get_configs_from_target(target, name)
return table.unique(values)
end
+-- Did the current cmake native support for c++ modules?
+function _can_native_support_for_cxxmodules()
+ local cmake_minver = _get_cmake_minver()
+ if cmake_minver and cmake_minver:ge("3.28") then
+ return true
+ end
+end
+
-- this sourcebatch is built?
function _sourcebatch_is_built(sourcebatch)
-- we can only use rulename to filter them because sourcekind may be bound to multiple rules
local rulename = sourcebatch.rulename
- if rulename == "c.build" or rulename == "c++.build" or rulename == "c++.build.modules"
+ if rulename == "c.build" or rulename == "c++.build"
or rulename == "asm.build" or rulename == "cuda.build"
or rulename == "objc.build" or rulename == "objc++.build"
or rulename == "win.sdk.resource" then
return true
end
+ if _can_native_support_for_cxxmodules() then
+ if rulename == "c++.build.modules" then
+ return true
+ end
+ end
end
-- translate flag
@@ -347,7 +360,8 @@ function _add_target_sources(cmakelists, target, outputdir)
cmakelists:print("target_sources(%s PRIVATE", target:name())
local sourcebatches = target:sourcebatches()
for name, sourcebatch in table.orderpairs(sourcebatches) do
- if _sourcebatch_is_built(sourcebatch) and not name:startswith("c++.build.modules") then
+ print(sourcebatch)
+ if _sourcebatch_is_built(sourcebatch) then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
cmakelists:print(" " .. _get_relative_unix_path(sourcefile, outputdir))
end
@@ -974,7 +988,10 @@ function _add_target_custom_commands(cmakelists, target, outputdir)
local sourcegroups = rule_groups.build_sourcebatch_groups(target, target:sourcebatches())
-- ignore c++ modules rules
- local ignored_rules = {"c++.build.modules", "c++.build.modules.builder"}
+ local ignored_rules
+ if _can_native_support_for_cxxmodules() then
+ ignored_rules = {"c++.build.modules", "c++.build.modules.builder"}
+ end
-- add before commands
-- we use irpairs(groups), because the last group that should be given the highest priority.