|
15 | 15 | % can't use SourceFiles= if "mex" Task was run, even if |
16 | 16 | % plan("test").DisableIncremental = true; |
17 | 17 | % this means incremental tests can't be used with MEX files (as of R2024b) |
| 18 | + |
| 19 | + plan("clean") = matlab.buildtool.tasks.CleanTask; |
18 | 20 | end |
19 | 21 |
|
20 | 22 | if ~isMATLABReleaseOlderThan("R2024a") |
|
23 | 25 |
|
24 | 26 | plan("publish") = matlab.buildtool.Task(Description="HTML inline doc generate", Actions=@publishTask); |
25 | 27 |
|
| 28 | +%% MexTask |
26 | 29 | bindir = fullfile(plan.RootFolder, pkg_name); |
27 | | -if isMATLABReleaseOlderThan("R2024b") |
28 | | - plan("mex") = matlab.buildtool.Task(Actions=@(~)legacyMexTask(bindir)); |
29 | | -else |
30 | | - plan("clean") = matlab.buildtool.tasks.CleanTask; |
| 30 | +[compiler_id, compiler_opt] = get_compiler_options(); |
31 | 31 |
|
32 | | - [compiler_id, compiler_opt] = get_compiler_options(); |
| 32 | +if isMATLABReleaseOlderThan("R2024b") |
| 33 | + % dummy task to allow "buildtool mex" to build all MEX targets |
| 34 | + plan("mex") = matlab.buildtool.Task(); |
| 35 | + mex_deps = string.empty; |
| 36 | +end |
33 | 37 |
|
34 | | - for s = get_mex_sources() |
35 | | - src = s{1}; |
36 | | - [~, name] = fileparts(src(1)); |
| 38 | +for s = get_mex_sources() |
| 39 | + src = s{1}; |
| 40 | + [~, name] = fileparts(src(1)); |
37 | 41 |
|
| 42 | + % name of MEX target function is name of first source file |
| 43 | + if isMATLABReleaseOlderThan("R2024b") |
| 44 | + mex_name = "mex_" + name; |
| 45 | + % specifying .Inputs and .Outputs enables incremental builds |
| 46 | + % https://www.mathworks.com/help/matlab/matlab_prog/improve-performance-with-incremental-builds.html |
| 47 | + plan(mex_name) = matlab.buildtool.Task(Actions=@(context) legacyMexTask(context, compiler_id, compiler_opt)); |
| 48 | + plan(mex_name).Inputs = matlab.buildtool.io.FileCollection.fromPaths(src); |
| 49 | + plan(mex_name).Outputs = matlab.buildtool.io.FileCollection.fromPaths(fullfile(bindir, name + "." + mexext())); |
| 50 | + mex_deps(end+1) = mex_name; %#ok<AGROW> |
| 51 | + else |
38 | 52 | plan("mex:" + name) = matlab.buildtool.tasks.MexTask(src, bindir, ... |
39 | 53 | Options=[compiler_id, compiler_opt]); |
40 | 54 | end |
41 | 55 | end |
42 | 56 |
|
| 57 | +if isMATLABReleaseOlderThan("R2024b") |
| 58 | + plan("mex").Dependencies = mex_deps; |
43 | 59 | end |
44 | 60 |
|
| 61 | +end |
45 | 62 |
|
46 | | -function legacyMexTask(bindir) |
47 | | - |
48 | | -[compiler_id, compiler_opt] = get_compiler_options(); |
49 | | - |
50 | | -srcs = get_mex_sources(); |
51 | 63 |
|
52 | | -%% build C++ mex |
53 | | -% https://www.mathworks.com/help/matlab/ref/mex.html |
54 | | -for s = srcs |
55 | | - src = s{1}; |
56 | | - [~, name] = fileparts(src(1)); |
57 | | - disp("Building MEX target: " + name) |
58 | | - mex(s{1}{:}, "-outdir", bindir, compiler_id, compiler_opt) |
59 | | -end |
| 64 | +function legacyMexTask(context, compiler_id, compiler_opt) |
| 65 | +bindir = fileparts(context.Task.Outputs.Path); |
| 66 | +mex(context.Task.Inputs.Path, "-outdir", bindir, compiler_id, compiler_opt) |
60 | 67 | end |
61 | 68 |
|
62 | 69 |
|
|
0 commit comments