summaryrefslogtreecommitdiff
path: root/xmake/rules/c++/modules
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-04 00:43:07 +0800
committerruki <[email protected]>2022-08-04 00:43:07 +0800
commit533fa58d9ed5c4fe63017342b3eba282ac72f12e (patch)
tree545e08f3eae8bd6e8f18f51b01faf7a49543370e /xmake/rules/c++/modules
parente387de53870b6ac9432a6599d9904910b088bc7c (diff)
format some codes
Diffstat (limited to 'xmake/rules/c++/modules')
-rw-r--r--xmake/rules/c++/modules/xmake.lua64
1 files changed, 30 insertions, 34 deletions
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 785e8fed5..0c0f8cac9 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -21,6 +21,7 @@
-- define rule: c++.build.modules
rule("c++.build.modules")
set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
+
add_deps("c++.build.modules.dependencies")
add_deps("c++.build.modules.builder")
add_deps("c++.build.modules.install")
@@ -51,28 +52,29 @@ rule("c++.build.modules")
end
end)
-
+-- build dependencies
rule("c++.build.modules.dependencies")
before_build(function(target, opt)
if not target:data("cxx.has_modules") then
return
end
+ -- patch sourcebatch
import("modules_support.common")
- local modules_support = common.modules_support(target)
-
- -- build dependency data
- local batch = target:sourcebatches()["c++.build.modules.builder"]
- common.patch_sourcebatch(target, batch, opt)
+ local sourcebatch = target:sourcebatches()["c++.build.modules.builder"]
+ common.patch_sourcebatch(target, sourcebatch, opt)
- modules_support.generate_dependencies(target, batch, opt)
+ -- generate dependencies
+ local modules_support = common.modules_support(target)
+ modules_support.generate_dependencies(target, sourcebatch, opt)
- local moduleinfos = common.load(target, batch, opt)
+ -- load and parse module dependencies
+ local moduleinfos = common.load(target, sourcebatch, opt)
local modules = common.parse_dependency_data(target, moduleinfos, opt)
-
target:data_set("cxx.modules", modules)
end)
+-- build modules
rule("c++.build.modules.builder")
set_sourcekinds("cxx")
set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
@@ -83,27 +85,23 @@ rule("c++.build.modules.builder")
return
end
+ -- patch sourcebatch
import("modules_support.common")
- local modules_support = common.modules_support(target)
-
- local batch = sourcebatch
-
- batch.objectfiles = {}
- batch.dependfiles = {}
- common.patch_sourcebatch(target, batch, opt)
-
- local modules = target:data("cxx.modules")
+ sourcebatch.objectfiles = {}
+ sourcebatch.dependfiles = {}
+ common.patch_sourcebatch(target, sourcebatch, opt)
+ -- get headerunits info, TODO maybe need optimize it
local headerunits
- for _, objectfile in ipairs(batch.objectfiles) do
+ local modules = target:data("cxx.modules")
+ for _, objectfile in ipairs(sourcebatch.objectfiles) do
for obj, m in pairs(modules) do
if obj == objectfile then
for name, r in pairs(m.requires) do
if r.method ~= "by-name" then
headerunits = headerunits or {}
-
- local type = r.method == "include-angle" and ":angle" or ":quote"
- table.append(headerunits, { name = name, path = r.path, type = type, stl = common.is_stl_header(name) })
+ local unittype = r.method == "include-angle" and ":angle" or ":quote"
+ table.append(headerunits, {name = name, path = r.path, type = unittype, stl = common.is_stl_header(name)})
end
end
break
@@ -111,12 +109,13 @@ rule("c++.build.modules.builder")
end
end
+ -- generate headerunits
local headerunits_flags
local private_headerunits_flags
+ local modules_support = common.modules_support(target)
if headerunits then
headerunits_flags, private_headerunits_flags = modules_support.generate_headerunits(target, batchcmds, headerunits, opt)
end
-
if headerunits_flags then
target:add("cxxflags", headerunits_flags, {force = true, expand = false})
end
@@ -124,24 +123,21 @@ rule("c++.build.modules.builder")
target:add("cxxflags", private_headerunits_flags, {force = true, expand = false})
end
- local modules = target:data("cxx.modules")
-
-- topological sort
- local objectfiles = common.sort_modules_by_dependencies(batch.objectfiles, modules)
-
+ local objectfiles = common.sort_modules_by_dependencies(sourcebatch.objectfiles, modules)
modules_support.build_modules(target, batchcmds, objectfiles, modules, opt)
end)
+-- install modules
rule("c++.build.modules.install")
set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
before_install(function (target)
- if not target:data("cxx.has_modules") then
- return
- end
-
- local sourcebatch = target:sourcebatches()["c++.build.modules.install"]
- if sourcebatch then
- target:add("installfiles", sourcebatch.sourcefiles, {prefixdir = "include"})
+ import("modules_support.common")
+ if common.contains_modules(target) then
+ local sourcebatch = target:sourcebatches()["c++.build.modules.install"]
+ if sourcebatch then
+ target:add("installfiles", sourcebatch.sourcefiles, {prefixdir = "include"})
+ end
end
end)