diff options
| author | ruki <[email protected]> | 2021-09-24 22:45:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-24 22:45:56 +0800 |
| commit | c3b4b1882e06d80e2a3d2a81e4be594803d56c39 (patch) | |
| tree | 9c8a4f01c417ec60b0b57d118ce5369fcedfac79 | |
| parent | c2f3f280bcfd82618590e9872ddce19b56940ab0 (diff) | |
install swig scripts
| -rw-r--r-- | tests/projects/swig/python_c/xmake.lua | 2 | ||||
| -rw-r--r-- | tests/projects/swig/python_cpp/src/example.cpp | 14 | ||||
| -rw-r--r-- | tests/projects/swig/python_cpp/src/example.i | 11 | ||||
| -rw-r--r-- | tests/projects/swig/python_cpp/xmake.lua | 8 | ||||
| -rw-r--r-- | xmake/rules/swig/xmake.lua | 24 |
5 files changed, 58 insertions, 1 deletions
diff --git a/tests/projects/swig/python_c/xmake.lua b/tests/projects/swig/python_c/xmake.lua index 2b30079b6..89b13cbd4 100644 --- a/tests/projects/swig/python_c/xmake.lua +++ b/tests/projects/swig/python_c/xmake.lua @@ -3,6 +3,6 @@ add_requires("python 3.x") target("example") add_rules("swig.c") - add_files("src/example.i", {moduletype = "python"}) + add_files("src/example.i", {moduletype = "python", scriptdir = "share"}) add_files("src/example.c") add_packages("python") diff --git a/tests/projects/swig/python_cpp/src/example.cpp b/tests/projects/swig/python_cpp/src/example.cpp new file mode 100644 index 000000000..31c659bfa --- /dev/null +++ b/tests/projects/swig/python_cpp/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/python_cpp/src/example.i b/tests/projects/swig/python_cpp/src/example.i new file mode 100644 index 000000000..34193edc7 --- /dev/null +++ b/tests/projects/swig/python_cpp/src/example.i @@ -0,0 +1,11 @@ +%module example +%{ +/* Put headers and other declarations here */ +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/python_cpp/xmake.lua b/tests/projects/swig/python_cpp/xmake.lua new file mode 100644 index 000000000..f0c322310 --- /dev/null +++ b/tests/projects/swig/python_cpp/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.release", "mode.debug") +add_requires("python 3.x") + +target("example") + add_rules("swig.cpp") + add_files("src/example.i", {moduletype = "python", scriptdir = "share"}) + add_files("src/example.cpp") + add_packages("python") diff --git a/xmake/rules/swig/xmake.lua b/xmake/rules/swig/xmake.lua index 1756cf1c9..c02ed1362 100644 --- a/xmake/rules/swig/xmake.lua +++ b/xmake/rules/swig/xmake.lua @@ -30,6 +30,30 @@ rule("swig.base") if target:is_plat("windows") then target:set("extension", ".pyd") end + local scriptfiles = {} + for _, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.rulename:startswith("swig.") then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local scriptdir + local moduletype + local fileconfig = target:fileconfig(sourcefile) + if fileconfig then + moduletype = fileconfig.moduletype + scriptdir = fileconfig.scriptdir + end + local scriptfile = path.join(target:autogendir(), "rules", "swig", path.basename(sourcefile)) + if moduletype == "python" then + scriptfile = scriptfile .. ".py" + end + table.insert(scriptfiles, scriptfile) + if scriptdir then + target:add("installfiles", scriptfile, {prefixdir = scriptdir}) + end + end + end + end + -- for custom on_install/after_install, user can use it to install them + target:set("data", "swig.scriptfiles", scriptfiles) end) rule("swig.c") |
