Skip to content

Commit 0a1787f

Browse files
committed
buildfile: use task
1 parent a3d0ff6 commit 0a1787f

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

buildfile.m

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,46 @@
33

44
plan.DefaultTasks = "test";
55

6+
if ~isMATLABReleaseOlderThan("R2023b")
7+
plan("check") = matlab.buildtool.tasks.CodeIssuesTask("+stdlib", IncludeSubfolders=true);
8+
end
9+
610
if ~isMATLABReleaseOlderThan("R2024b")
711

812
cxx = mex.getCompilerConfigurations('c++');
13+
flags = cxx.Details.CompilerFlags;
14+
15+
msvc = startsWith(cxx.ShortName, "MSVCPP");
916

1017
% disp("Mex using: " + cxx.Name + " " + cxx.Version)
1118

12-
compiler_opt = "CXXFLAGS=$CXXFLAGS -std=c++17";
19+
std = "-std=c++17";
20+
compiler_id = "";
1321
% FIXME: Windows oneAPI
14-
if startsWith(cxx.ShortName, "MSVCPP")
15-
compiler_opt = "COMPFLAGS=$COMPFLAGS /std:c++17";
22+
if msvc
23+
std = "/std:c++17";
1624
elseif ismac
17-
compiler_opt = "CXXFLAGS=$CXXFLAGS -std=c++17";
25+
% keep for if-logic
1826
elseif isunix && cxx.ShortName == "g++"
19-
compiler_opt = compiler_opt + " -fPIC";
2027
% FIXME: update when desired GCC != 10 for newer Matlab
2128
if isMATLABReleaseOlderThan("R2025b") && ~startsWith(cxx.Version, "10")
2229
% https://www.mathworks.com/help/matlab/matlab_external/choose-c-or-c-compilers.html
2330
% https://www.mathworks.com/help/matlab/matlab_external/change-default-gcc-compiler-on-linux-system.html
2431
[s, ~] = system("which g++-10");
2532
if s == 0
26-
compiler_opt = "CXX=g++-10 " + compiler_opt;
33+
compiler_id = "CXX=g++-10";
2734
else
2835
warning("GCC 10 not found, using default, may fail on runtime")
2936
end
3037
end
3138
end
3239

40+
if msvc
41+
compiler_opt = "COMPFLAGS=" + flags + " " + std;
42+
else
43+
compiler_opt = compiler_id + " CXXFLAGS=" + flags + " " + std;
44+
end
45+
3346
root = plan.RootFolder;
3447
bin = fullfile(root, "bin");
3548
if ~isfolder(bin), mkdir(bin), end
@@ -46,17 +59,15 @@
4659
end
4760

4861

49-
function checkTask(~)
50-
% Identify code issues (recursively all Matlab .m files)
51-
issues = codeIssues("+stdlib");
52-
assert(isempty(issues.Issues), formattedDisplayText(issues.Issues))
53-
end
54-
5562
function testTask(~)
5663
t = fileparts(mfilename("fullpath"));
5764
addpath(t)
5865

59-
r = runtests(IncludeSubfolders=true, strict=true, UseParallel=true, OutputDetail="Concise");
66+
r = runtests("test", ...
67+
IncludeSubfolders=true, ...
68+
strict=true, ...
69+
UseParallel=true, ...
70+
OutputDetail="Concise");
6071

6172
assert(~isempty(r), "No tests were run")
6273
assertSuccess(r)

0 commit comments

Comments
 (0)