summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-09-06 00:43:05 +0800
committerruki <[email protected]>2019-09-05 22:18:30 +0800
commitcfb90668f507c9b93fa3e53f78f8f46cdb136413 (patch)
tree6517400be4e448ffce8c1c8d3ac6d0257ff817ad
parent5f3ad152caf5509dd6e8a8249872c8969be1d49f (diff)
add c++.build.modules
-rw-r--r--xmake/modules/private/action/build/object.lua4
-rw-r--r--xmake/rules/c++/modules/xmake.lua28
2 files changed, 28 insertions, 4 deletions
diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua
index abfb3682b..7201185ff 100644
--- a/xmake/modules/private/action/build/object.lua
+++ b/xmake/modules/private/action/build/object.lua
@@ -38,7 +38,7 @@ function _do_build_file(target, sourcefile, opt)
local compinst = compiler.load(sourcekind, {target = target})
-- get compile flags
- local compflags = compinst:compflags({target = target, sourcefile = sourcefile})
+ local compflags = compinst:compflags({target = target, sourcefile = sourcefile, configs = opt.configs})
-- load dependent info
local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
@@ -97,7 +97,7 @@ function _build_object(target, sourcebatch, index, opt)
local progress_now = progress.start + ((index - 1) * (progress.stop - progress.start)) / #sourcebatch.sourcefiles
-- init build option
- local opt = {objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = progress_now}
+ local opt = {objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = progress_now, configs = opt.configs}
-- do before build
local before_build_file = target:script("build_file_before")
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 26421103b..2ecb829fc 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -20,8 +20,32 @@
-- define rule: c++.build.modules
rule("c++.build.modules")
- set_extensions(".mpp")
+ set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
+ before_load(function (target)
+ --target:add("cxxflags", "-fprebuilt-module-path=")
+ end)
before_build_files(function (target, sourcebatch, opt)
- print(sourcebatch)
+
+ -- imports
+ import("core.tool.compiler")
+
+ -- attempt to compile the module files as cxx
+ sourcebatch.sourcekind = "cxx"
+ sourcebatch.objectfiles = sourcebatch.objectfiles or {}
+ sourcebatch.dependfiles = sourcebatch.dependfiles or {}
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ local objectfile = target:objectfile(sourcefile)
+ table.insert(sourcebatch.objectfiles, objectfile)
+ table.insert(sourcebatch.dependfiles, target:dependfile(objectfile))
+ end
+
+ -- do compile
+ local compinst = compiler.load("cxx")
+ if compinst:name() == "clang" then
+ opt.configs = {cxxflags = {"-fmodules-ts", "--precompile"}}
+ else
+ raise("compiler(%s): does not support module!", compinst:name())
+ end
+ import("private.action.build.object")(target, sourcebatch, opt)
end)