Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add includedirs for swig #4484

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/projects/swig/auto_include/src/example.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
13 changes: 13 additions & 0 deletions tests/projects/swig/auto_include/src/example.i
Original file line number Diff line number Diff line change
@@ -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);
10 changes: 10 additions & 0 deletions tests/projects/swig/auto_include/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")
26 changes: 23 additions & 3 deletions xmake/rules/swig/build_module_file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,46 @@
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)
table.insert(target:objectfiles(), objectfile)

-- 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
local fileconfig = target:fileconfig(sourcefile)
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))
Expand Down
Loading