summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2022-08-03 03:28:35 +0200
committerArthur LAURENT <[email protected]>2022-08-03 03:28:35 +0200
commitda5627858bd40e911a8d5514a80613e35f5716e1 (patch)
tree7293244f6d9bfb876e8882118fb8a0d82294b2de
parentfd7340759c71bd253da2d2ccaeede55fb57dfa24 (diff)
[C++20 Modules] Use a helper function to get module_builder
-rw-r--r--xmake/rules/c++/modules/modules_support/common.lua15
-rw-r--r--xmake/rules/c++/modules/xmake.lua40
2 files changed, 19 insertions, 36 deletions
diff --git a/xmake/rules/c++/modules/modules_support/common.lua b/xmake/rules/c++/modules/modules_support/common.lua
index 0bfcc7211..7df0b3d34 100644
--- a/xmake/rules/c++/modules/modules_support/common.lua
+++ b/xmake/rules/c++/modules/modules_support/common.lua
@@ -148,6 +148,21 @@ function get_bmi_ext(target)
assert(false)
end
+function modules_support(target)
+ local module_builder
+ if target:has_tool("cxx", "clang", "clangxx") then
+ module_builder = import("clang", {anonymous = true})
+ elseif target:has_tool("cxx", "gcc", "gxx") then
+ module_builder = import("gcc", {anonymous = true})
+ elseif target:has_tool("cxx", "cl") then
+ module_builder = import("msvc", {anonymous = true})
+ else
+ local _, toolname = target:tool("cxx")
+ raise("compiler(%s): does not support c++ module!", toolname)
+ end
+ return module_builder
+end
+
function load(target, sourcebatch, opt)
local cachedir = get_cache_dir(target)
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index fd178f1d8..233fcab9f 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -44,18 +44,8 @@ rule("c++.build.modules")
-- @see https://github.com/xmake-io/xmake/issues/1858
target:set("policy", "build.across_targets_in_parallel", false)
- -- import modules_support
- local modules_support
- if target:has_tool("cxx", "clang", "clangxx") then
- modules_support = import("modules_support.clang")
- elseif target:has_tool("cxx", "gcc", "gxx") then
- modules_support = import("modules_support.gcc")
- elseif target:has_tool("cxx", "cl") then
- modules_support = import("modules_support.msvc")
- else
- local _, toolname = target:tool("cxx")
- raise("compiler(%s): does not support c++ module!", toolname)
- end
+ local common = import("modules_support.common")
+ local modules_support = common.modules_support(target)
-- check C++20 module support
modules_support.check_module_support(target)
@@ -74,19 +64,8 @@ rule("c++.build.modules.dependencies")
return
end
- local modules_support
- if target:has_tool("cxx", "clang", "clangxx") then
- modules_support = import("modules_support.clang")
- elseif target:has_tool("cxx", "gcc", "gxx") then
- modules_support = import("modules_support.gcc")
- elseif target:has_tool("cxx", "cl") then
- modules_support = import("modules_support.msvc")
- else
- local _, toolname = target:tool("cxx")
- raise("compiler(%s): does not support c++ module!", toolname)
- end
-
local common = import("modules_support.common")
+ local modules_support = common.modules_support(target)
-- build dependency data
local batch = target:sourcebatches()["c++.build.modules.builder"]
@@ -110,19 +89,8 @@ rule("c++.build.modules.builder")
return
end
- local modules_support
- if target:has_tool("cxx", "clang", "clangxx") then
- modules_support = import("modules_support.clang")
- elseif target:has_tool("cxx", "gcc", "gxx") then
- modules_support = import("modules_support.gcc")
- elseif target:has_tool("cxx", "cl") then
- modules_support = import("modules_support.msvc")
- else
- local _, toolname = target:tool("cxx")
- raise("compiler(%s): does not support c++ module!", toolname)
- end
-
local common = import("modules_support.common")
+ local modules_support = common.modules_support(target)
local batch = sourcebatch