summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-02-17 22:47:48 +0800
committerruki <[email protected]>2022-02-17 22:47:48 +0800
commit168e70b7e06cfcfbadff763fed0d838b92130ad9 (patch)
tree401fe00d3aaa38d7db950f1d90eba8a292b9d24e
parent54efc65b6ed2dfc86c28ba7cc3f40a6084785026 (diff)
improve modules with space
-rw-r--r--tests/projects/c++/modules/hello with spaces/src/hello.mpp10
-rw-r--r--tests/projects/c++/modules/hello with spaces/src/main.cpp6
-rw-r--r--tests/projects/c++/modules/hello with spaces/xmake.lua4
-rw-r--r--tests/projects/c++/modules/hello/xmake.lua2
-rw-r--r--xmake/core/tool/builder.lua27
-rw-r--r--xmake/rules/c++/modules/build_modules/msvc.lua14
6 files changed, 41 insertions, 22 deletions
diff --git a/tests/projects/c++/modules/hello with spaces/src/hello.mpp b/tests/projects/c++/modules/hello with spaces/src/hello.mpp
new file mode 100644
index 000000000..124bd72bc
--- /dev/null
+++ b/tests/projects/c++/modules/hello with spaces/src/hello.mpp
@@ -0,0 +1,10 @@
+module;
+#include <cstdio>
+
+export module hello;
+
+export namespace hello {
+ void say(const char* str) {
+ printf("%s\n", str);
+ }
+}
diff --git a/tests/projects/c++/modules/hello with spaces/src/main.cpp b/tests/projects/c++/modules/hello with spaces/src/main.cpp
new file mode 100644
index 000000000..1e5cc698f
--- /dev/null
+++ b/tests/projects/c++/modules/hello with spaces/src/main.cpp
@@ -0,0 +1,6 @@
+import hello;
+
+int main() {
+ hello::say("hello module!");
+ return 0;
+}
diff --git a/tests/projects/c++/modules/hello with spaces/xmake.lua b/tests/projects/c++/modules/hello with spaces/xmake.lua
new file mode 100644
index 000000000..6a69ce121
--- /dev/null
+++ b/tests/projects/c++/modules/hello with spaces/xmake.lua
@@ -0,0 +1,4 @@
+set_languages("c++20")
+target("A hello")
+ set_kind("binary")
+ add_files("src/*.cpp", "src/*.mpp")
diff --git a/tests/projects/c++/modules/hello/xmake.lua b/tests/projects/c++/modules/hello/xmake.lua
index 6a69ce121..2315cf287 100644
--- a/tests/projects/c++/modules/hello/xmake.lua
+++ b/tests/projects/c++/modules/hello/xmake.lua
@@ -1,4 +1,4 @@
set_languages("c++20")
-target("A hello")
+target("hello")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 8685c34b7..b7ef1fdc0 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -58,11 +58,13 @@ function builder:_mapflag(flag, flagkind, mapflags, auto_ignore_flags)
return flag_mapped
end
- -- find and replace it using pattern
- for k, v in pairs(mapflags) do
- local flag_mapped, count = flag:gsub("^" .. k .. "$", function (w) return v end)
- if flag_mapped and count ~= 0 then
- return #flag_mapped ~= 0 and flag_mapped
+ -- find and replace it using pattern, maybe flag is table, e.g. {"-I", "/xxx"}
+ if type(flag) == "string" then
+ for k, v in pairs(mapflags) do
+ local flag_mapped, count = flag:gsub("^" .. k .. "$", function (w) return v end)
+ if flag_mapped and count ~= 0 then
+ return #flag_mapped ~= 0 and flag_mapped
+ end
end
end
@@ -70,7 +72,7 @@ function builder:_mapflag(flag, flagkind, mapflags, auto_ignore_flags)
if auto_ignore_flags == false or self:has_flags(flag, flagkind) then
return flag
else
- utils.warning("add_%s(\"%s\") is ignored, please pass `{force = true}` or call `set_policy(\"check.auto_ignore_flags\", false)` if you want to set it.", flagkind, flag)
+ utils.warning("add_%s(\"%s\") is ignored, please pass `{force = true}` or call `set_policy(\"check.auto_ignore_flags\", false)` if you want to set it.", flagkind, os.args(flag))
end
end
@@ -132,20 +134,17 @@ function builder:_add_flags_from_flagkind(flags, target, flagkind, opt)
local extraconf = target:extraconf(flagkind)
if extraconf then
for _, flag in ipairs(table.wrap(targetflags)) do
- -- force to add flags?
+ -- @note we need join the single flag with shallow mode, aboid expand table values
+ -- e.g. add_cflags({"-I", "/tmp/xxx foo"}, {force = true, expand = false})
local flagconf = extraconf[flag]
if flagconf and flagconf.force then
- table.join2(flags, flag)
- print("111")
+ table.shallow_join2(flags, flag)
else
- table.join2(flags, self:_mapflags(flag, flagkind, target))
- print("222")
- utils.dump(self:_mapflags(flag, flagkind, target))
+ table.shallow_join2(flags, self:_mapflag(flag, flagkind, target))
end
end
else
table.join2(flags, self:_mapflags(targetflags, flagkind, target))
- print("xxxx")
end
end
@@ -217,13 +216,11 @@ function builder:_add_flags_from_target(flags, target)
self:_inherit_flags_from_targetdeps(targetflags, target)
end
- utils.dump(targetflags)
-- add the target flags
for _, flagkind in ipairs(self:_flagkinds()) do
self:_add_flags_from_flagkind(targetflags, target, flagkind)
end
cache[key] = targetflags
- utils.dump(targetflags)
end
table.join2(flags, targetflags)
end
diff --git a/xmake/rules/c++/modules/build_modules/msvc.lua b/xmake/rules/c++/modules/build_modules/msvc.lua
index 2b227e354..f1062b044 100644
--- a/xmake/rules/c++/modules/build_modules/msvc.lua
+++ b/xmake/rules/c++/modules/build_modules/msvc.lua
@@ -43,7 +43,7 @@ function load_parent(target, opt)
local sourcebatches = dep:sourcebatches()
if sourcebatches and sourcebatches["c++.build.modules"] then
local cachedir = path.join(dep:autogendir(), "rules", "modules", "cache")
- target:add("cxxflags", {"/ifcSearchDir", cachedir}, {force = true, expand = false})
+ target:add("cxxflags", {"/ifcSearchDir", os.args(cachedir)}, {force = true, expand = true})
end
end
end
@@ -128,8 +128,10 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt)
local sourcefile = sourcebatch.sourcefiles[i]
local moduledep = assert(moduledeps_files[sourcefile], "moduledep(%s) not found!", sourcefile)
moduledep.job = batchjobs:newjob(sourcefile, function (index, total)
- local opt2 = table.join(opt, {configs = {force = {cxxflags = {interfaceflag,
- {outputflag, modulefiles[i]}, "/TP"}}}})
+ local opt2 = table.join(opt, {configs = {force = {cxxflags = {
+ interfaceflag,
+ {outputflag, modulefiles[i]},
+ "/TP"}}}})
opt2.progress = (index * 100) / total
opt2.objectfile = sourcebatch.objectfiles[i]
opt2.dependfile = sourcebatch.dependfiles[i]
@@ -140,7 +142,7 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt)
count = count + 1
if count == sourcefiles_total and not cachedir then
for _, modulefile in ipairs(modulefiles) do
- target:add("cxxflags", referenceflag .. " " .. os.args(modulefile))
+ target:add("cxxflags", {referenceflag, os.args(modulefile)}, {force = true, expand = false})
end
end
end)
@@ -149,7 +151,7 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt)
-- add module flags
target:add("cxxflags", modulesflag)
if cachedir then
- target:add("cxxflags", {"/ifcSearchDir", cachedir}, {expand = false})
+ target:add("cxxflags", {"/ifcSearchDir", os.args(cachedir)}, {force = true, expand = false})
end
if stdifcdirflag then
for _, toolchain_inst in ipairs(target:toolchains()) do
@@ -158,7 +160,7 @@ function build_with_batchjobs(target, batchjobs, sourcebatch, opt)
if vcvars.VCInstallDir and vcvars.VCToolsVersion then
local stdifcdir = path.join(vcvars.VCInstallDir, "Tools", "MSVC", vcvars.VCToolsVersion, "ifc", target:is_arch("x64") and "x64" or "x86")
if os.isdir(stdifcdir) then
- target:add("cxxflags", stdifcdirflag .. " " .. winos.short_path(stdifcdir))
+ target:add("cxxflags", {stdifcdirflag, winos.short_path(stdifcdir)}, {force = true, expand = false})
end
end
break