summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-06-19 00:44:07 +0800
committerruki <[email protected]>2021-06-19 00:44:07 +0800
commite3e9c9a4cabe1fd164f5f8ad79e90d2e9e391437 (patch)
tree28e59298a52a80149d1e80a4b8cc18371176c468
parentabcb36d06cf324c64968606950ec7c586dbafa61 (diff)
export c++ classes
-rw-r--r--tests/projects/c++/shared_library_export_all/src/foo.cpp6
-rw-r--r--tests/projects/c++/shared_library_export_all/src/foo.h5
-rw-r--r--tests/projects/c++/shared_library_export_all/src/main.cpp10
-rw-r--r--tests/projects/c++/shared_library_export_all/test.lua6
-rw-r--r--tests/projects/c++/shared_library_export_all/xmake.lua13
-rw-r--r--tests/projects/c/shared_library_export_all/xmake.lua2
-rw-r--r--xmake/rules/utils/symbols/export_all/export_all.lua9
7 files changed, 48 insertions, 3 deletions
diff --git a/tests/projects/c++/shared_library_export_all/src/foo.cpp b/tests/projects/c++/shared_library_export_all/src/foo.cpp
new file mode 100644
index 000000000..3ab50856c
--- /dev/null
+++ b/tests/projects/c++/shared_library_export_all/src/foo.cpp
@@ -0,0 +1,6 @@
+#include "foo.h"
+
+int test::add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/projects/c++/shared_library_export_all/src/foo.h b/tests/projects/c++/shared_library_export_all/src/foo.h
new file mode 100644
index 000000000..f671c7d32
--- /dev/null
+++ b/tests/projects/c++/shared_library_export_all/src/foo.h
@@ -0,0 +1,5 @@
+class test
+{
+public:
+ static int add(int a, int b);
+};
diff --git a/tests/projects/c++/shared_library_export_all/src/main.cpp b/tests/projects/c++/shared_library_export_all/src/main.cpp
new file mode 100644
index 000000000..e48f4730e
--- /dev/null
+++ b/tests/projects/c++/shared_library_export_all/src/main.cpp
@@ -0,0 +1,10 @@
+#include "foo.h"
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ cout << "add(1, 2) = " << test::add(1, 2) << endl;
+ return 0;
+}
diff --git a/tests/projects/c++/shared_library_export_all/test.lua b/tests/projects/c++/shared_library_export_all/test.lua
new file mode 100644
index 000000000..b76241be2
--- /dev/null
+++ b/tests/projects/c++/shared_library_export_all/test.lua
@@ -0,0 +1,6 @@
+-- main entry
+function main(t)
+
+ -- build project
+ t:build()
+end
diff --git a/tests/projects/c++/shared_library_export_all/xmake.lua b/tests/projects/c++/shared_library_export_all/xmake.lua
new file mode 100644
index 000000000..6bac1947f
--- /dev/null
+++ b/tests/projects/c++/shared_library_export_all/xmake.lua
@@ -0,0 +1,13 @@
+add_rules("mode.debug", "mode.release")
+
+target("foo")
+ set_kind("shared")
+ add_files("src/foo.cpp")
+ add_rules("utils.symbols.export_all", {with_classes = true})
+
+target("demo")
+ set_kind("binary")
+ add_deps("foo")
+ add_files("src/main.cpp")
+
+
diff --git a/tests/projects/c/shared_library_export_all/xmake.lua b/tests/projects/c/shared_library_export_all/xmake.lua
index 4e3d86ef5..6466a16fc 100644
--- a/tests/projects/c/shared_library_export_all/xmake.lua
+++ b/tests/projects/c/shared_library_export_all/xmake.lua
@@ -3,7 +3,7 @@ add_rules("mode.release", "mode.debug")
target("foo")
set_kind("shared")
add_files("src/foo.c", "src/bar.cpp")
- add_rules("utils.symbols.export_all")
+ add_rules("utils.symbols.export_all", {class = true})
target("test")
set_kind("binary")
diff --git a/xmake/rules/utils/symbols/export_all/export_all.lua b/xmake/rules/utils/symbols/export_all/export_all.lua
index 54fe738ea..83f92eb2a 100644
--- a/xmake/rules/utils/symbols/export_all/export_all.lua
+++ b/xmake/rules/utils/symbols/export_all/export_all.lua
@@ -47,6 +47,9 @@ function main (target, opt)
local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()})
local dumpbin = assert(find_tool("dumpbin", {envs = msvc:runenvs()}), "dumpbin not found!")
+ -- export with c++ class?
+ local export_with_classes = target:extraconf("rules", "utils.symbols.export_all", "with_classes")
+
-- get all symbols from object files
local allsymbols = hashset.new()
for _, objectfile in ipairs(target:objectfiles()) do
@@ -58,11 +61,13 @@ function main (target, opt)
local symbol = line:match(".*External%s+| (.*)")
if symbol then
symbol = symbol:split('%s')[1]
- if not symbol:startswith("__") and not symbol:startswith("?") then
+ if not symbol:startswith("__") then
if target:is_arch("x86") and symbol:startswith("_") then
symbol = symbol:sub(2)
end
- allsymbols:insert(symbol)
+ if export_with_classes or not symbol:startswith("?") then
+ allsymbols:insert(symbol)
+ end
end
end
end