Skip to content

find_package(Matlab) doesn't work with the MCR

Hi,

There's this thing called the Matlab Compiler Runtime (MCR - https://www.mathworks.com/products/compiler/mcr.html). It's freely downloadable and includes the Matlab headers and libraries so that one can build Matlab mex-files, without having to have the "full" Matlab program (and a license for it).

However, CMake's find_package(Matlab) seems to work only with a "full" Matlab installation and not with the MCR, even though the MCR is completely sufficient to for example build mex files.

If you have this in a CMakeLists.txt: find_package(Matlab COMPONENTS MX_LIBRARY REQUIRED) And you do

cmake -G "Visual Studio 14 Win64" ..\myproj_source -DMatlab_ROOT_DIR=C:\MCR_2016b\v91, it gives an error:

CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/FindMatlab.cmake:575 (string):
  string sub-command STRIP requires two arguments.
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindMatlab.cmake:1353 (matlab_get_mex_suffix)
  matlab/CMakeLists.txt:5 (find_package)

CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
  Could NOT find Matlab (missing: Matlab_MEX_EXTENSION)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.7/Modules/FindMatlab.cmake:1504 (find_package_handle_standard_args)
  matlab/CMakeLists.txt:5 (find_package)


-- Configuring incomplete, errors occurred!
See also "C:/myproj/build/CMakeFiles/CMakeOutput.log".

You can make the error go away by additionally specifying -DMatlab_MEX_EXTENSION=mexw64 but I believe this is an ugly hack because the CMake documentation itself says here that this should be determined by the installed Matlab.

I think this use case should definitely be made to work, since FindMatlab has actually awesome mex support: For example I think CMake 3.7 added matlab_add_mex(...), which I must say is pretty awesome for generating Matlab bindings for C++ code :-) And I think the FindMatlab script has already some support for the MCR or something like that, since for example MAIN_PROGRAM (which would be Matlab.exe) is only defined/returned if you explicitly request it (at least the CMake documentation says that).

Additionally, for example on travis/AppVeyor the only way to test mex bindings is with the MCR, since a full Matlab installation is not an option for licensing reasons.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information