summaryrefslogtreecommitdiff
path: root/Modules/FindMatlab.cmake
diff options
context:
space:
mode:
authorAlexander Neumann <neumann@imt.uni-luebeck.de>2021-07-02 16:24:20 +0200
committerBrad King <brad.king@kitware.com>2021-09-29 14:33:36 -0400
commit7fdd5128b17d0edc97ec555c0afa54c0608804d2 (patch)
tree55356152506544c922ab0db540f13cd23370c314 /Modules/FindMatlab.cmake
parent5bd94332c760a6f861b411273921b204076ab9a6 (diff)
downloadcmake-7fdd5128b17d0edc97ec555c0afa54c0608804d2.tar.gz
FindMatlab: Fix version selection if a version is given
Fixes: #22377
Diffstat (limited to 'Modules/FindMatlab.cmake')
-rw-r--r--Modules/FindMatlab.cmake23
1 files changed, 23 insertions, 0 deletions
diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake
index fdab9e9362..0ca593e98f 100644
--- a/Modules/FindMatlab.cmake
+++ b/Modules/FindMatlab.cmake
@@ -1572,6 +1572,29 @@ if(_numbers_of_matlab_roots GREATER 0)
list(GET _matlab_possible_roots ${_matlab_or_mcr_index} Matlab_Or_MCR)
list(GET _matlab_possible_roots ${_list_index} Matlab_VERSION_STRING)
list(GET _matlab_possible_roots ${_matlab_root_dir_index} Matlab_ROOT_DIR)
+ elseif(DEFINED Matlab_FIND_VERSION)
+ foreach(_matlab_root_index RANGE 1 ${_numbers_of_matlab_roots} 3)
+ list(GET _matlab_possible_roots ${_matlab_root_index} _matlab_root_version)
+ if(_matlab_root_version VERSION_GREATER_EQUAL Matlab_FIND_VERSION)
+ set(_list_index ${_matlab_root_index})
+ break()
+ endif()
+ endforeach()
+
+ if(_list_index LESS 0)
+ set(_list_index 1)
+ endif()
+
+ math(EXPR _matlab_or_mcr_index "${_list_index} - 1")
+ math(EXPR _matlab_root_dir_index "${_list_index} + 1")
+ list(GET _matlab_possible_roots ${_matlab_or_mcr_index} Matlab_Or_MCR)
+ list(GET _matlab_possible_roots ${_list_index} Matlab_VERSION_STRING)
+ list(GET _matlab_possible_roots ${_matlab_root_dir_index} Matlab_ROOT_DIR)
+ # adding a warning in case of ambiguity
+ if(_numbers_of_matlab_roots GREATER 3 AND MATLAB_FIND_DEBUG)
+ message(WARNING "[MATLAB] Found several distributions of Matlab. Setting the current version to ${Matlab_VERSION_STRING} (located ${Matlab_ROOT_DIR})."
+ " If this is not the desired behavior, use the EXACT keyword or provide the -DMatlab_ROOT_DIR=... on the command line")
+ endif()
else()
list(GET _matlab_possible_roots 0 Matlab_Or_MCR)
list(GET _matlab_possible_roots 1 Matlab_VERSION_STRING)