I am trying to setup a CMakeLists.txt
under Windows to compile matlab-mex-files. But I struggle with find_package(Matlab)
to select the correct version.
I am using cmake 3.26.4 under Windows 10. I have matlab versions 8.2, 9.3, 9.12, and 9.13 installed.
My CMakeLists.txt
looks as follows
cmake_minimum_required(VERSION 3.26)
project(MatlabMex)
set(MATLAB_FIND_DEBUG ON)
find_package(Matlab 9.3 EXACT REQUIRED)
matlab_extract_all_installed_versions_from_registry(TRUE matlab_versions)
matlab_get_all_valid_matlab_roots_from_registry("${matlab_versions}" matlab_roots)
message("${matlab_roots}")
IF(MATLAB_FOUND)
matlab_get_release_name_from_version(${Matlab_VERSION_STRING} Matlab_release)
message(STATUS "Matlab found: ${Matlab_release}")
ELSE(MATLAB_FOUND)
message("Matlab not found")
ENDIF(MATLAB_FOUND)
The debug output of FindMatlab provides:
-- [MATLAB] Matlab root folders are UNKNOWN;9.13;C:/Program Files/MATLAB/R2022b
-- [MATLAB] Current version is 9.13 located C:/Program Files/MATLAB/R2022b
-- [MATLAB] [DEBUG]_matlab_lib_prefix_for_search = lib | _matlab_lib_dir_for_search = C:/Program Files/MATLAB/R2022b/extern/lib/win64/mingw64
When using the EXACT
in find_package
I then get the error, that no suitable version can be found:
Could NOT find Matlab: Found unsuitable version "9.13", but required is
exact version "9.3" (found C:/Program Files/MATLAB/R2022b/extern/include, )
However, when I omit EXACT
, it selects 9.13 and runs the two macros to retrieve the information from the registry. This yields the following, which clearly includes all installed versions.
MATLAB;9.13;C:/Program Files/MATLAB/R2022b;MATLAB;9.12;C:/Program Files/MATLAB/R2022a;MATLAB;9.3;C:/Program Files/MATLAB/R2017b;MATLAB;8.2;C:/Program Files/MATLAB/R2013b
So now the question: Why does FindMatlab not find all versions in the first place and selects my desired 9.3?
I came across two issues, which seem to relate, but are solved a long time ago:
For now I consider a user error rather than a cmake issue.