summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-12-12 14:22:23 +0800
committerGitHub <[email protected]>2023-12-12 14:22:23 +0800
commitba0ce32c4aa16fee4fb78e52ca172a1ade421c8e (patch)
tree367dcb937c9523f6bdfbc6481c2a7cae159ada9f
parent818bc24a309ea3559c2ffa4f5035d66f8af602b4 (diff)
parentb69f77d19a8eae5251968bad1703d21ea9b39f9b (diff)
Merge pull request #4484 from tokomine/swig_includedirs
add includedirs for swig
-rw-r--r--tests/projects/swig/auto_include/src/example.cpp14
-rw-r--r--tests/projects/swig/auto_include/src/example.i13
-rw-r--r--tests/projects/swig/auto_include/xmake.lua10
-rw-r--r--xmake/rules/swig/build_module_file.lua26
4 files changed, 60 insertions, 3 deletions
diff --git a/tests/projects/swig/auto_include/src/example.cpp b/tests/projects/swig/auto_include/src/example.cpp
new file mode 100644
index 000000000..b0ddc9c26
--- /dev/null
+++ b/tests/projects/swig/auto_include/src/example.cpp
@@ -0,0 +1,14 @@
+double My_variable = 3.0;
+
+/* Compute factorial of n */
+int fact(int n) {
+ if (n <= 1)
+ return 1;
+ else
+ return n*fact(n-1);
+}
+
+/* Compute n mod m */
+int my_mod(int n, int m) {
+ return(n % m);
+}
diff --git a/tests/projects/swig/auto_include/src/example.i b/tests/projects/swig/auto_include/src/example.i
new file mode 100644
index 000000000..945b77892
--- /dev/null
+++ b/tests/projects/swig/auto_include/src/example.i
@@ -0,0 +1,13 @@
+%module example
+
+%{
+/* Put headers and other declarations here */
+#include "nlohmann/json.hpp"
+extern double My_variable;
+extern int fact(int);
+extern int my_mod(int n, int m);
+%}
+
+extern double My_variable;
+extern int fact(int);
+extern int my_mod(int n, int m);
diff --git a/tests/projects/swig/auto_include/xmake.lua b/tests/projects/swig/auto_include/xmake.lua
new file mode 100644
index 000000000..63afe351a
--- /dev/null
+++ b/tests/projects/swig/auto_include/xmake.lua
@@ -0,0 +1,10 @@
+add_rules("mode.release", "mode.debug")
+add_requires("python 3.x")
+add_requires("nlohmann_json")
+
+target("example")
+ add_rules("swig.cpp", {moduletype = "python"})
+ add_files("src/example.i", {scriptdir = "share"})
+ add_files("src/example.cpp")
+ add_packages("python")
+ add_packages("nlohmann_json") \ No newline at end of file
diff --git a/xmake/rules/swig/build_module_file.lua b/xmake/rules/swig/build_module_file.lua
index 42c9d9238..2599834ae 100644
--- a/xmake/rules/swig/build_module_file.lua
+++ b/xmake/rules/swig/build_module_file.lua
@@ -22,11 +22,11 @@
import("lib.detect.find_tool")
function main(target, batchcmds, sourcefile, opt)
-
-- get swig
opt = opt or {}
local swig = assert(find_tool("swig"), "swig not found!")
- local sourcefile_cx = path.join(target:autogendir(), "rules", "swig", path.basename(sourcefile) .. (opt.sourcekind == "cxx" and ".cpp" or ".c"))
+ local sourcefile_cx = path.join(target:autogendir(), "rules", "swig",
+ path.basename(sourcefile) .. (opt.sourcekind == "cxx" and ".cpp" or ".c"))
-- add objectfile
local objectfile = target:objectfile(sourcefile_cx)
@@ -34,7 +34,7 @@ function main(target, batchcmds, sourcefile, opt)
-- add commands
local moduletype = assert(target:data("swig.moduletype"), "swig.moduletype not found!")
- local argv = {"-" .. moduletype, "-o", sourcefile_cx}
+ local argv = { "-" .. moduletype, "-o", sourcefile_cx }
if opt.sourcekind == "cxx" then
table.insert(argv, "-c++")
end
@@ -42,6 +42,26 @@ function main(target, batchcmds, sourcefile, opt)
if fileconfig.swigflags then
table.join2(argv, fileconfig.swigflags)
end
+
+ -- add includedirs
+ local function _get_values_from_target(target, name)
+ local values = {}
+ for _, value in ipairs((target:get_from(name, "*"))) do
+ table.join2(values, value)
+ end
+ return table.unique(values)
+ end
+ local pathmaps = {
+ { "includedirs", "includedir" },
+ { "sysincludedirs", "includedir" },
+ { "frameworkdirs", "frameworkdir" }
+ }
+ for _, pathmap in ipairs(pathmaps) do
+ for _, item in ipairs(_get_values_from_target(target, pathmap[1])) do
+ table.join2(argv, "-I" .. item)
+ end
+ end
+
table.insert(argv, sourcefile)
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.swig.%s %s", moduletype, sourcefile)
batchcmds:mkdir(path.directory(sourcefile_cx))