Skip to content

FindMatlab: Fix logic error when minimum version is not found

scivision requested to merge scivision/cmake:master into master

ensures that _list_index is always initialized to -1, akin to list(FIND) not finding a match. This seems to be simple algorithmic oversight in !6300 (merged). Before the present MR, specifying a minimum Matlab version would fail, e.g.

find_package(Matlab 9.9)
CMake Error at /cmake-3.23.0-rc2-linux-x86_64/share/cmake-3.23/Modules/FindMatlab.cmake:1592 (list):
  list sub-command GET requires at least three arguments.
Call Stack (most recent call first):
  CMakeLists.txt:22 (find_package)


CMake Error at /cmake-3.23.0-rc2-linux-x86_64/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Matlab: Found unsuitable version "NOTFOUND", but required is
  at least "9.9" (found Matlab_INCLUDE_DIRS-NOTFOUND)

This is because the if() statement below does not execute (not defined variable is NOT LESS 0) when _list_index is not defined:

if(_list_index LESS 0)
  set(_list_index 1)
endif()

Backport: release
Topic-rename: FindMatlab-minver

Edited by Brad King

Merge request reports