summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules/xmake.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-11-24 00:56:24 +0800
committerruki <[email protected]>2021-11-24 00:56:24 +0800
commit12ee3ed6eb196f5d9e5cdeb619c40f51b2bec144 (patch)
tree15757810c3fb3f7d953d681c803236c770705921 /xmake/rules/c++/modules/xmake.lua
parent499b857f587073a09145c44d4ab9c312afb9a69a (diff)
improve c++ modules
Diffstat (limited to 'xmake/rules/c++/modules/xmake.lua')
-rw-r--r--xmake/rules/c++/modules/xmake.lua34
1 files changed, 29 insertions, 5 deletions
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 9018f5e2d..78f754521 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -21,12 +21,36 @@
-- define rule: c++.build.modules
rule("c++.build.modules")
set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
- before_build_files(function (target, batchjobs, sourcebatch, opt)
+ after_load(function (target)
-- we disable to build across targets in parallel, because the source files may depend on other target modules
- -- @note we cannot set it in on_load, because it will affect all c++ projects
- target:set("policy", "build.across_targets_in_parallel", false)
-
- -- build module files with batchjobs
+ -- @see https://github.com/xmake-io/xmake/issues/1858
+ local target_with_modules
+ for _, dep in ipairs(target:orderdeps()) do
+ local sourcebatches = dep:sourcebatches()
+ if sourcebatches and sourcebatches["c++.build.modules"] then
+ target_with_modules = true
+ break
+ end
+ end
+ if target_with_modules then
+ -- @note this will cause cross-parallel builds to be disabled for all sub-dependent targets,
+ -- even if some sub-targets do not contain C++ modules.
+ --
+ -- maybe we will have a more fine-grained configuration strategy to disable it in the future.
+ target:set("policy", "build.across_targets_in_parallel", false)
+ local _, toolname = target:tool("cxx")
+ if toolname:find("clang", 1, true) then
+ import("build_modules.clang").load_parent(target, opt)
+ elseif toolname:find("gcc", 1, true) then
+ import("build_modules.gcc").load_parent(target, opt)
+ elseif toolname == "cl" then
+ import("build_modules.msvc").load_parent(target, opt)
+ else
+ raise("compiler(%s): does not support c++ module!", toolname)
+ end
+ end
+ end)
+ before_build_files(function (target, batchjobs, sourcebatch, opt)
local _, toolname = target:tool("cxx")
if toolname:find("clang", 1, true) then
import("build_modules.clang").build_with_batchjobs(target, batchjobs, sourcebatch, opt)