summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-04-06 22:03:58 +0800
committerruki <[email protected]>2025-04-08 15:31:58 +0800
commit43c3b8607775f7ee5b52e24a7f785b4c7a5ab292 (patch)
tree6d3d7546d3142faea4188fdbe59d9b04c068c397
parent3b2e44ef7fce4baca2ede46bf1edb8cbf42734bb (diff)
add modules with pch test
-rw-r--r--tests/projects/c++/modules/hello_with_pch/src/hello.mpp10
-rw-r--r--tests/projects/c++/modules/hello_with_pch/src/main.cpp8
-rw-r--r--tests/projects/c++/modules/hello_with_pch/src/test.h1
-rw-r--r--tests/projects/c++/modules/hello_with_pch/test.lua1
-rw-r--r--tests/projects/c++/modules/hello_with_pch/xmake.lua7
-rw-r--r--xmake/rules/c++/precompiled_header/xmake.lua6
6 files changed, 31 insertions, 2 deletions
diff --git a/tests/projects/c++/modules/hello_with_pch/src/hello.mpp b/tests/projects/c++/modules/hello_with_pch/src/hello.mpp
new file mode 100644
index 000000000..124bd72bc
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/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_pch/src/main.cpp b/tests/projects/c++/modules/hello_with_pch/src/main.cpp
new file mode 100644
index 000000000..739309dd4
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/src/main.cpp
@@ -0,0 +1,8 @@
+#include "test.h"
+
+import hello;
+
+int main() {
+ hello::say("hello module!");
+ return 0;
+}
diff --git a/tests/projects/c++/modules/hello_with_pch/src/test.h b/tests/projects/c++/modules/hello_with_pch/src/test.h
new file mode 100644
index 000000000..d5a732287
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/src/test.h
@@ -0,0 +1 @@
+#include <string>
diff --git a/tests/projects/c++/modules/hello_with_pch/test.lua b/tests/projects/c++/modules/hello_with_pch/test.lua
new file mode 100644
index 000000000..7717f8049
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/test.lua
@@ -0,0 +1 @@
+inherit(".test_base")
diff --git a/tests/projects/c++/modules/hello_with_pch/xmake.lua b/tests/projects/c++/modules/hello_with_pch/xmake.lua
new file mode 100644
index 000000000..79ddb6b58
--- /dev/null
+++ b/tests/projects/c++/modules/hello_with_pch/xmake.lua
@@ -0,0 +1,7 @@
+add_rules("mode.release", "mode.debug")
+set_languages("c++20")
+
+target("hello")
+ set_kind("binary")
+ set_pcxxheader("src/test.h")
+ add_files("src/*.cpp", "src/*.mpp")
diff --git a/xmake/rules/c++/precompiled_header/xmake.lua b/xmake/rules/c++/precompiled_header/xmake.lua
index 7216a1f13..3f30c1ea1 100644
--- a/xmake/rules/c++/precompiled_header/xmake.lua
+++ b/xmake/rules/c++/precompiled_header/xmake.lua
@@ -19,18 +19,20 @@
--
rule("c.build.pcheader")
+ add_orders("c.build.pcheader", "c++.build.modules.builder")
on_config(function (target, opt)
import("private.action.build.pcheader").config(target, "c", opt)
end)
- before_build(function (target, opt)
+ on_prepare(function (target, opt)
import("private.action.build.pcheader").build(target, "c", opt)
end)
rule("c++.build.pcheader")
+ add_orders("c++.build.pcheader", "c++.build.modules.builder")
on_config(function (target, opt)
import("private.action.build.pcheader").config(target, "cxx", opt)
end)
- before_build(function (target, opt)
+ on_prepare(function (target, opt)
import("private.action.build.pcheader").build(target, "cxx", opt)
end)