FindMatlab: `matlab_get_version_from_matlab_run` fails to get version on system in which `matlab -r` does not work
MathWorks recently released support to run MATLAB-based tests on GitHub Actions, both in GitHub-hosted runners for public repositories, or on self-hosted runners for private repos, see https://github.com/matlab-actions/overview .
In case of public repo, the version of MATLAB installed in the machine is a version that fail to execute when run with the -r
option, that is used in FindMatlab
to run the script to obtain the precise MATLAB version (see https://gitlab.kitware.com/cmake/cmake/-/blob/v3.21.2/Modules/FindMatlab.cmake#L748). However, the version installed on that machine works fine when is invoked with the -batch
option, that has a semantics similar to -r
, but it actually explicitly launches a non-interactive version of the MATLAB interpreter, see https://mathworks.com/help/matlab/ref/matlablinux.html . Furthermore -r
is deprecated, i.e. in https://mathworks.com/help/matlab/ref/matlablinux.html it is written:
-r option for non-interactive use is not recommended
Not recommended starting in R2019a
To start MATLAB non-interactively, use the -batch option. To start MATLAB interactively, use the -r option.
Unfortunatly, -batch
is only available since R2019a, see https://mathworks.com/help/releases/R2018b/matlab/ref/matlablinux.html .
Ideally, we would like to use -batch
if MATLAB >= 2019a or -r
otherwise, but given that the option is used exactly to determine the version, we can't simply have a logic to use -r
or -batch
depending on the version. A possible solution is to try to get the version with -batch
only if getting the version with -r
fails.