FindMatlab breaks with multiple installations on OS X
I have two Matlab installations, /Applications/MATLAB_R2015a.app/
and /Applications/MATLAB_R2018b.app/
. I am running OS X 10.14.2 and cmake version 3.13.4.
FindMatlab seems to get "stuck" on the older R2015a. Please note, I am not setting Matlab_ROOT_DIR
anywhere.
For example, if I use this:
set(MATLAB_FIND_DEBUG 1)
message("Was Matlab_ROOT_DIR set: ${Matlab_ROOT_DIR}")
find_package (Matlab 9.3 REQUIRED MX_LIBRARY ENG_LIBRARY)
I get
Was Matlab_ROOT_DIR set: /Applications/MATLAB_R2015a.app
-- [MATLAB] Matlab root folders are UNKNOWN;8.5;/Applications/MATLAB_R2015a.app
-- [MATLAB] Current version is 8.5 located /Applications/MATLAB_R2015a.app
-- [MATLAB] [DEBUG]_matlab_lib_prefix_for_search = lib | _matlab_lib_dir_for_search = /Applications/MATLAB_R2015a.app/bin/maci64
CMake Error at /usr/local/Cellar/cmake/3.13.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find Matlab: Found unsuitable version "8.5", but required is at
least "9.3" (found /Applications/MATLAB_R2015a.app/extern/include)
However, if I force-clear this variable every single time, it works as expected e.g.
set(MATLAB_FIND_DEBUG 1)
set(Matlab_ROOT_DIR "" CACHE PATH "" FORCE)
message("Was Matlab_ROOT_DIR set: ${Matlab_ROOT_DIR}")
find_package (Matlab 9.3 REQUIRED MX_LIBRARY ENG_LIBRARY)
Resulting in:
Was Matlab_ROOT_DIR set:
-- [MATLAB] Matlab supported versions R2018b;R2018a;R2017b;R2017a;R2016b;R2016a;R2015b;R2015a;R2014b;R2014a;R2013b;R2013a;R2012b;R2012a;R2011b;R2011a;R2010b. If more version should be supported the variab
le MATLAB_ADDITIONAL_VERSIONS can be set according to the documentation
-- [MATLAB] Found version R2018b (9.5) in /Applications/MATLAB_R2018b.app
-- [MATLAB] Found version R2015a (8.5) in /Applications/MATLAB_R2015a.app
-- [MATLAB] Matlab root folders are MATLAB;9.5;/Applications/MATLAB_R2018b.app;MATLAB;8.5;/Applications/MATLAB_R2015a.app
CMake Warning at /usr/local/Cellar/cmake/3.13.4/share/cmake/Modules/FindMatlab.cmake:1433 (message):
[MATLAB] Found several distributions of Matlab. Setting the current
version to 9.5 (located /Applications/MATLAB_R2018b.app). If this is not
the desired behaviour, provide the -DMatlab_ROOT_DIR=... on the command
line
Call Stack (most recent call first):
CMakeLists.txt:46 (find_package)
-- [MATLAB] Current version is 9.5 located /Applications/MATLAB_R2018b.app
<snip>