From 310b916dd4d1735507a72f55496185606c396a5c Mon Sep 17 00:00:00 2001
From: Raffi Enficiaud <raffi.enficiaud@tuebingen.mpg.de>
Date: Thu, 26 Feb 2015 17:59:11 +0100
Subject: [PATCH] =?UTF-8?q?Simplified=20workflow=20Removing=20the=20"which?=
 =?UTF-8?q?=20matlab"=20as=20the=20find=5Fprogram=20was=20erroneous=20MATL?=
 =?UTF-8?q?AB=5FUSER=5FROOT=20now=20reflects=20the=20found=20root,=20remov?=
 =?UTF-8?q?ed=20Matlab=5FROOT=20Reduced=20the=20number=20of=20find=5Fprogr?=
 =?UTF-8?q?am(matlab)=E2=80=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Modules/FindMatlab.cmake                           | 398 ++++++++++-----------
 Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m |   3 +-
 Tests/RunCMake/CMakeLists.txt                      |   3 +-
 3 files changed, 199 insertions(+), 205 deletions(-)

diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake
index 9686a76..8b63139 100644
--- a/Modules/FindMatlab.cmake
+++ b/Modules/FindMatlab.cmake
@@ -35,7 +35,8 @@
 # * Windows: The installed versions of Matlab are retrieved from the
 #   Windows registry
 # * OS X: The installed versions of Matlab are given by the MATLAB
-#   paths in ``/Application``
+#   paths in ``/Application``. If no such application is found, it falls back 
+#   to the one that might be accessible from the PATH.
 # * Unix: The desired Matlab should be accessible from the PATH.
 #
 # Additional information is provided when :variable:`MATLAB_FIND_DEBUG` is set.
@@ -192,6 +193,10 @@
 #         "R2013b=8.2"
 #         "R2013a=8.1"
 #         "R2012b=8.0")
+#
+#   The order of entries in this list matters when several versions of 
+#   Matlab are installed. The priority is set according to the ordering in
+#   this list. 
 
 #=============================================================================
 # Copyright 2014-2015 Raffi Enficiaud, Max Planck Society
@@ -918,255 +923,250 @@ function(matlab_add_mex )
 endfunction()
 
 
+# (internal)
+# Used to get the version of matlab, using caching. This basically transforms the 
+# output of the root list, with possible unknown version, to a version
+#
+function(_Matlab_get_version_from_root matlab_root matlab_known_version matlab_final_version)
 
+  # if the version is not trivial, we query matlab for that
+  # we keep track of the location of matlab that induced this version
+  set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version") 
 
 
+  if(NOT ${matlab_known_version} STREQUAL "NOTFOUND")
+    # the version is known, we just return it
+    set(${matlab_final_version} ${matlab_known_version} PARENT_SCOPE)
+    return()
+  endif()
+  
+  
+  # do we already have a matlab program?
+  if(NOT Matlab_MAIN_PROGRAM)
+  
+    set(_find_matlab_options)
+    if(matlab_root AND EXISTS ${matlab_root})
+      set(_find_matlab_options PATHS ${matlab_root} ${matlab_root}/bin NO_DEFAULT_PATH)
+    endif()
+  
+    find_program(
+        Matlab_MAIN_PROGRAM
+        matlab
+        ${_find_matlab_options}
+        DOC "Matlab main program"
+      )  
+  endif()
 
+  
+  if(NOT Matlab_MAIN_PROGRAM OR NOT EXISTS ${Matlab_MAIN_PROGRAM})
+    # if not found, clear the dependent variables
+    set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
+    set(Matlab_VERSION_STRING "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
+    return()
+  endif()
+  
+  # is it the same as the previous one?
+  get_filename_component(_matlab_main_real_path_tmp "${Matlab_MAIN_PROGRAM}" REALPATH)
+  if(_matlab_main_real_path_tmp STREQUAL Matlab_PROG_VERSION_STRING_AUTO_DETECT)
+    set(${matlab_final_version} ${Matlab_VERSION_STRING} PARENT_SCOPE)
+    return()
+  endif()
 
+  
+  # update the location of the program
+  set(Matlab_PROG_VERSION_STRING_AUTO_DETECT ${_matlab_main_real_path_tmp} CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
+
+  set(matlab_list_of_all_versions)
+  matlab_get_version_from_matlab_run("${Matlab_PROG_VERSION_STRING_AUTO_DETECT}" matlab_list_of_all_versions)
+
+  list(GET matlab_list_of_all_versions 0 _matlab_version_tmp)
+  
+  # set the version into the cache
+  set(Matlab_VERSION_STRING ${_matlab_version_tmp} CACHE INTERNAL "Matlab version (automatically determined)" FORCE)
+  
+  # warning, just in case several versions found (should not happen)
+  list(LENGTH matlab_list_of_all_versions list_of_all_versions_length)
+  if((${list_of_all_versions_length} GREATER 1) AND MATLAB_FIND_DEBUG)
+    message(WARNING "[MATLAB] Found several versions, taking the first one (versions found ${matlab_list_of_all_versions})")
+  endif()  
+  
+  # return the updated value
+  set(${matlab_final_version} ${Matlab_VERSION_STRING} PARENT_SCOPE)
 
-# this variable will get all Matlab installations found in the current system.
-set(_matlab_possible_roots)
-
-
-# listing the Matlab versions installed on the WIN machine if MATLAB_USER_ROOT
-# is not set
-if(WIN32)
-
-  # for windows
-
-
-  if(NOT MATLAB_USER_ROOT)
-    # if MATLAB_USER_ROOT not specified, we look for Matlab installation in
-    # the registry
-    # if unsuccessful, we look for all known revision and filter the existing
-    # ones.
+endfunction()
+  
+  
 
-    # testing if we are able to extract the needed information from the registry
-    set(matlab_versions_from_registry)
-    matlab_extract_all_installed_versions_from_registry(CMAKE_CL_64 matlab_versions_from_registry)
 
-    # the returned list is empty, doing the search on all known versions
-    if(NOT matlab_versions_from_registry)
 
-      if(MATLAB_FIND_DEBUG)
-        message(STATUS "[MATLAB] Search for Matlab from the registry unsuccessful, testing all supported versions")
-      endif()
 
-      extract_matlab_versions_from_registry_brute_force(matlab_versions_from_registry)
-    endif()
 
-    # filtering the results with the registry keys
-    matlab_get_all_valid_matlab_roots_from_registry("${matlab_versions_from_registry}" _matlab_possible_roots)
+# ###################################
+# Exploring the possible Matlab_ROOTS
 
+# this variable will get all Matlab installations found in the current system.
+set(_matlab_possible_roots)
 
 
-  elseif(NOT EXISTS ${MATLAB_USER_ROOT})
 
+if(MATLAB_USER_ROOT)
+  # if the user specifies a possible root, we keep this one
+  
+  if(NOT EXISTS ${MATLAB_USER_ROOT})
     # if MATLAB_USER_ROOT specified but erroneous
     if(MATLAB_FIND_DEBUG)
       message(WARNING "[MATLAB] the specified path for MATLAB_USER_ROOT does not exist (${MATLAB_USER_ROOT})")
     endif()
   else()
+    # NOTFOUND indicates the code below to search for the version automatically
     list(APPEND _matlab_possible_roots "NOTFOUND" ${MATLAB_USER_ROOT}) # empty version
   endif()
 
 
 else()
-  # for linux/osx
-
-  if(NOT MATLAB_USER_ROOT)
+  
+  # if the user does not specify the possible installation root, we look for 
+  # one installation using the appropriate heuristics
 
-    # if MATLAB_USER_ROOT not specified, we look for Matlab from the command
-    # line PATH
-    # maybe using CMAKE_PROGRAM_PATH to add some more hints
+  if(WIN32)
 
-    set(_matlab_main_tmp "")
-    if(Matlab_MAIN_PROGRAM)
-      set(_matlab_main_tmp ${Matlab_MAIN_PROGRAM})
-    endif()
+    # On WIN32, we look for Matlab installation in the registry
+    # if unsuccessful, we look for all known revision and filter the existing
+    # ones.
 
-    if(NOT _matlab_main_tmp)
+    # testing if we are able to extract the needed information from the registry
+    set(_matlab_versions_from_registry)
+    matlab_extract_all_installed_versions_from_registry(CMAKE_CL_64 _matlab_versions_from_registry)
 
-      find_program(
-        _matlab_main_tmp
-        NAMES matlab)
-
-      if(NOT _matlab_main_tmp)
-        execute_process(
-          COMMAND "which" matlab
-          OUTPUT_VARIABLE _matlab_main_tmp
-          ERROR_VARIABLE _matlab_main_tmp_err)
-        # the output should be cleaned up
-        string(STRIP "${_matlab_main_tmp}" _matlab_main_tmp)
-      endif()
+    # the returned list is empty, doing the search on all known versions
+    if(NOT _matlab_versions_from_registry)
 
-      if(EXISTS ${_matlab_main_tmp})
-        if(MATLAB_FIND_DEBUG)
-          message(STATUS "[MATLAB] matlab found from PATH: ${_matlab_main_tmp}")
-        endif()
-      else()
-        # found candidate is not good, we remove it
-        unset(_matlab_main_tmp)
-        unset(_matlab_main_tmp CACHE)
+      if(MATLAB_FIND_DEBUG)
+        message(STATUS "[MATLAB] Search for Matlab from the registry unsuccessful, testing all supported versions")
       endif()
 
-    endif() # if(NOT _matlab_main_tmp)
-
-    if(_matlab_main_tmp AND EXISTS ${_matlab_main_tmp})
-      # resolve symlinks
-      get_filename_component(_matlab_current_location "${_matlab_main_tmp}" REALPATH)
-      set(_directory_alias DIRECTORY)
-
-      # get the directory (the command below has to be run twice)
-      get_filename_component(_matlab_current_location "${_matlab_current_location}" ${_directory_alias})
-      get_filename_component(_matlab_current_location "${_matlab_current_location}" ${_directory_alias}) # Matlab should be in bin
-      list(APPEND _matlab_possible_roots "NOTFOUND" ${_matlab_current_location}) # empty version
+      extract_matlab_versions_from_registry_brute_force(_matlab_versions_from_registry)
     endif()
 
+    # filtering the results with the registry keys
+    matlab_get_all_valid_matlab_roots_from_registry("${_matlab_versions_from_registry}" _matlab_possible_roots)
+    unset(_matlab_versions_from_registry)
 
+  elseif(APPLE)
+  
     # on mac, we look for the /Application paths
     # this corresponds to the behaviour on Windows. On Linux, we do not have
     # any other guess.
-    if((NOT _matlab_possible_roots) AND APPLE)
+    matlab_get_supported_releases(_matlab_releases)
+    if(MATLAB_FIND_DEBUG)
+      message(STATUS "[MATLAB] Matlab supported versions ${_matlab_releases}. If more version should be supported "
+                   "the variable MATLAB_ADDITIONAL_VERSIONS can be set according to the documentation")
+    endif()
 
-      matlab_get_supported_releases(_matlab_releases)
-      if(MATLAB_FIND_DEBUG)
-        message(STATUS "[MATLAB] Matlab supported versions ${_matlab_releases}. If more version should be supported "
-                     "the variable MATLAB_ADDITIONAL_VERSIONS can be set according to the documentation")
+    foreach(_matlab_current_release IN LISTS _matlab_releases)
+      set(_matlab_full_string "/Applications/MATLAB_${_matlab_current_release}.app")
+      if(EXISTS ${_matlab_full_string})
+        set(_matlab_current_version)
+        matlab_get_version_from_release_name("${_matlab_current_release}" _matlab_current_version)
+        if(MATLAB_FIND_DEBUG)
+          message(STATUS "[MATLAB] Found version ${_matlab_current_release} (${_matlab_current_version}) in ${_matlab_full_string}")
+        endif()
+        list(APPEND _matlab_possible_roots ${_matlab_current_version} ${_matlab_full_string})
+        unset(_matlab_current_version)
       endif()
 
-      foreach(_matlab_current_release IN LISTS _matlab_releases)
-        set(_matlab_full_string "/Applications/MATLAB_${_matlab_current_release}.app")
-        if(EXISTS ${_matlab_full_string})
-          set(_matlab_current_version)
-          matlab_get_version_from_release_name("${_matlab_current_release}" _matlab_current_version)
-          if(MATLAB_FIND_DEBUG)
-            message(STATUS "[MATLAB] Found version ${_matlab_current_release} (${_matlab_current_version}) in ${_matlab_full_string}")
-          endif()
-          list(APPEND _matlab_possible_roots ${_matlab_current_version})
-          list(APPEND _matlab_possible_roots ${_matlab_full_string})
-          unset(_matlab_current_version)
-        endif()
+      unset(_matlab_full_string)
+    endforeach(_matlab_current_release)
+    
+    unset(_matlab_current_release)
+    unset(_matlab_releases)  
+  
+  endif()
 
-        unset(_matlab_full_string)
-      endforeach(_matlab_current_release)
-      unset(_matlab_current_release)
-      unset(_matlab_releases)
-    endif()
+endif()
 
-    # we need to clear _matlab_main_tmp here
-    unset(_matlab_main_tmp CACHE)
-    unset(_matlab_main_tmp)
 
-  elseif(NOT EXISTS ${MATLAB_USER_ROOT})
-    # if MATLAB_USER_ROOT specified but erroneous
+
+list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots)
+if(_numbers_of_matlab_roots EQUAL 0)
+  # if we have not found anything, we fall back on the PATH
+ 
+ 
+  # At this point, we have no other choice than trying to find it from PATH.
+  # If set by the user, this wont change
+  find_program(
+    Matlab_MAIN_PROGRAM
+    NAMES matlab)
+
+  
+  if(Matlab_MAIN_PROGRAM)
+    # we then populate the list of roots, with empty version
     if(MATLAB_FIND_DEBUG)
-      message(WARNING "[MATLAB] the specified path for MATLAB_USER_ROOT does not exist (${MATLAB_USER_ROOT})")
+      message(STATUS "[MATLAB] matlab found from PATH: ${_matlab_main_tmp}")
     endif()
-  else()
-    list(APPEND _matlab_possible_roots "NOTFOUND" ${MATLAB_USER_ROOT}) # empty version
+
+    # resolve symlinks
+    get_filename_component(_matlab_current_location "${Matlab_MAIN_PROGRAM}" REALPATH)
+    
+    # get the directory (the command below has to be run twice)
+    # this will be the matlab root
+    get_filename_component(_matlab_current_location "${_matlab_current_location}" DIRECTORY)
+    get_filename_component(_matlab_current_location "${_matlab_current_location}" DIRECTORY) # Matlab should be in bin
+    
+    list(APPEND _matlab_possible_roots "NOTFOUND" ${_matlab_current_location})
+    
+    unset(_matlab_current_location)
+    
   endif()
+
 endif()
 
 
+
+
+
 if(MATLAB_FIND_DEBUG)
   message(STATUS "[MATLAB] Matlab root folders are ${_matlab_possible_roots}")
 endif()
 
 
 
-if(DEFINED Matlab_ROOT_DIR)
-  unset(Matlab_ROOT_DIR)
-endif()
+
 
 # take the first possible Matlab root
-if(_matlab_possible_roots)
+list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots)
+set(Matlab_VERSION_STRING "NOTFOUND")
+if(_numbers_of_matlab_roots GREATER 0)
   list(GET _matlab_possible_roots 0 Matlab_VERSION_STRING)
-  list(GET _matlab_possible_roots 1 Matlab_ROOT_DIR)
-  list(LENGTH _matlab_possible_roots numbers_of_matlab_roots)
+  list(GET _matlab_possible_roots 1 MATLAB_USER_ROOT)
 
   # adding a warning in case of ambiguity
-  if(numbers_of_matlab_roots GREATER 2 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(_numbers_of_matlab_roots GREATER 2 AND MATLAB_FIND_DEBUG)
+    message(WARNING "[MATLAB] Found several distributions of Matlab. Setting the current version to ${Matlab_VERSION_STRING} (located ${MATLAB_USER_ROOT})."
                     " If this is not the desired behaviour, provide the -DMATLAB_USER_ROOT on the command line")
   endif()
 endif()
 
 
-if((NOT (DEFINED Matlab_VERSION_STRING)) OR (NOT Matlab_VERSION_STRING))
-  set(Matlab_VERSION_STRING "NOTFOUND")
-endif()
-
-
-
-# if the version is not trivial, we query matlab for that
-# we keep track of the location of matlab that induced this version
-set(Matlab_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version")
-
-set(_matlab_version_should_be_recomputed FALSE)
-if(${Matlab_VERSION_STRING} STREQUAL "NOTFOUND")
-  set(_matlab_version_should_be_recomputed TRUE)
-elseif((NOT Matlab_MAIN_PROGRAM) OR (NOT EXISTS ${Matlab_MAIN_PROGRAM}))
-  set(_matlab_version_should_be_recomputed TRUE)
-else()
-  # just in case the variable is modified to a symlink
-  get_filename_component(_matlab_main_tmp "${Matlab_MAIN_PROGRAM}" REALPATH)
-  if(NOT (_matlab_main_tmp STREQUAL Matlab_VERSION_STRING_AUTO_DETECT))
-    set(_matlab_version_should_be_recomputed TRUE)
-  endif()
-endif()
-
-if(_matlab_version_should_be_recomputed)
-  if(MATLAB_FIND_DEBUG)
-    message(STATUS "[MATLAB] querying for version from Matlab root = ${Matlab_ROOT_DIR}")
-  endif()
-
-  if(Matlab_MAIN_PROGRAM)
-    set(_matlab_main_tmp ${Matlab_MAIN_PROGRAM})
-  else()
-    find_program(
-      _matlab_main_tmp
-      matlab
-      PATHS ${Matlab_ROOT_DIR} ${Matlab_ROOT_DIR}/bin
-      DOC "Matlab main program"
-      NO_DEFAULT_PATH
-    )
-  endif()
 
-  if(_matlab_main_tmp)
-    set(matlab_list_of_all_versions)
-    matlab_get_version_from_matlab_run("${_matlab_main_tmp}" matlab_list_of_all_versions)
+# Fix the version, in case this one is NOTFOUND
+_Matlab_get_version_from_root(
+  "${MATLAB_USER_ROOT}"
+  ${Matlab_VERSION_STRING}
+  Matlab_VERSION_STRING
+)
 
-    list(GET matlab_list_of_all_versions 0 MATLAB_VERSION_tmp)
 
-    # set the version into the cache
-    set(Matlab_VERSION_STRING ${MATLAB_VERSION_tmp} CACHE INTERNAL "Matlab version (automatically determined)" FORCE)
-    list(LENGTH list_of_all_versions list_of_all_versions_length)
-    if((${list_of_all_versions_length} GREATER 1) AND MATLAB_FIND_DEBUG)
-      message(WARNING "[MATLAB] Found several versions, taking the first one (versions found ${list_of_all_versions})")
-    endif()
-
-    # update the location of Matlab that produced this value
-    # we store the real path for comparison
-    get_filename_component(_matlab_main_tmp1 "${_matlab_main_tmp}" REALPATH)
-    set(Matlab_VERSION_STRING_AUTO_DETECT ${_matlab_main_tmp1} CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
-
-    # these are internal variables
-    unset(_matlab_main_tmp)
-    unset(_matlab_main_tmp CACHE)
-    unset(_matlab_main_tmp1)
-  endif()
-endif()
 
 
 if(MATLAB_FIND_DEBUG)
-  message(STATUS "[MATLAB] Current version is ${Matlab_VERSION_STRING} located ${Matlab_ROOT_DIR}")
+  message(STATUS "[MATLAB] Current version is ${Matlab_VERSION_STRING} located ${MATLAB_USER_ROOT}")
 endif()
 
 
 
-if(Matlab_ROOT_DIR)
-  file(TO_CMAKE_PATH ${Matlab_ROOT_DIR} Matlab_ROOT_DIR)
+if(MATLAB_USER_ROOT)
+  file(TO_CMAKE_PATH ${MATLAB_USER_ROOT} MATLAB_USER_ROOT)
 endif()
 
 if(CMAKE_SIZEOF_VOID_P EQUAL 4)
@@ -1191,7 +1191,7 @@ endif()
 
 
 
-set(MATLAB_INCLUDE_DIR_TO_LOOK ${Matlab_ROOT_DIR}/extern/include)
+set(MATLAB_INCLUDE_DIR_TO_LOOK ${MATLAB_USER_ROOT}/extern/include)
 if(_matlab_64Build)
   set(_matlab_current_suffix ${_matlab_bin_suffix_64bits})
 else()
@@ -1199,9 +1199,9 @@ else()
 endif()
 
 set(Matlab_BINARIES_DIR
-    ${Matlab_ROOT_DIR}/bin/${_matlab_bin_prefix}${_matlab_current_suffix})
+    ${MATLAB_USER_ROOT}/bin/${_matlab_bin_prefix}${_matlab_current_suffix})
 set(Matlab_EXTERN_LIBRARY_DIR
-    ${Matlab_ROOT_DIR}/extern/lib/${_matlab_bin_prefix}${_matlab_current_suffix})
+    ${MATLAB_USER_ROOT}/extern/lib/${_matlab_bin_prefix}${_matlab_current_suffix})
 
 if(WIN32)
   set(_matlab_lib_dir_for_search ${Matlab_EXTERN_LIBRARY_DIR}/microsoft)
@@ -1216,7 +1216,7 @@ unset(_matlab_64Build)
 
 if(NOT DEFINED Matlab_MEX_EXTENSION)
   set(_matlab_mex_extension "")
-  matlab_get_mex_suffix("${Matlab_ROOT_DIR}" _matlab_mex_extension)
+  matlab_get_mex_suffix("${MATLAB_USER_ROOT}" _matlab_mex_extension)
 
   # This variable goes to the cache.
   set(Matlab_MEX_EXTENSION ${_matlab_mex_extension} CACHE STRING "Extensions for the mex targets (automatically given by Matlab)")
@@ -1266,7 +1266,7 @@ list(APPEND _matlab_required_variables Matlab_MEX_LIBRARY)
 list(APPEND _matlab_required_variables Matlab_MEX_EXTENSION)
 
 # the matlab root is required
-list(APPEND _matlab_required_variables Matlab_ROOT_DIR)
+list(APPEND _matlab_required_variables MATLAB_USER_ROOT)
 
 
 # component Mex Compiler
@@ -1289,16 +1289,15 @@ unset(_matlab_find_mex_compiler)
 # component Matlab program
 list(FIND Matlab_FIND_COMPONENTS MAIN_PROGRAM _matlab_find_matlab_program)
 if(_matlab_find_matlab_program GREATER -1)
-  # todo cleanup with code above
-  if(NOT DEFINED Matlab_MAIN_PROGRAM)
-    find_program(
-      Matlab_MAIN_PROGRAM
-      matlab
-      PATHS ${Matlab_ROOT_DIR} ${Matlab_ROOT_DIR}/bin
-      DOC "Matlab main program"
-      NO_DEFAULT_PATH
-    )
-  endif()
+  
+  find_program(
+    Matlab_MAIN_PROGRAM
+    matlab
+    PATHS ${MATLAB_USER_ROOT} ${MATLAB_USER_ROOT}/bin
+    DOC "Matlab main program"
+    NO_DEFAULT_PATH
+  )
+
   if(Matlab_MAIN_PROGRAM)
     set(Matlab_MAIN_PROGRAM_FOUND TRUE)
   endif()
@@ -1349,19 +1348,13 @@ unset(_matlab_lib_dir_for_search)
 
 set(Matlab_LIBRARIES ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY} ${Matlab_ENG_LIBRARY})
 
-if(CMAKE_VERSION VERSION_LESS "2.8.11")
-  find_package_handle_standard_args(
-    Matlab
-    REQUIRED_VARS ${_matlab_required_variables}
-    VERSION_VAR Matlab_VERSION_STRING)
-else()
-  find_package_handle_standard_args(
-    Matlab
-    FOUND_VAR Matlab_FOUND
-    REQUIRED_VARS ${_matlab_required_variables} #MATLAB_REQUIRED_PROGRAMS MATLAB_REQUIRED_LIBRARIES MATLAB_REQUIRED_INCLUDE_DIRS
-    VERSION_VAR Matlab_VERSION_STRING
-    HANDLE_COMPONENTS)
-endif()
+
+find_package_handle_standard_args(
+  Matlab
+  FOUND_VAR Matlab_FOUND
+  REQUIRED_VARS ${_matlab_required_variables} #MATLAB_REQUIRED_PROGRAMS MATLAB_REQUIRED_LIBRARIES MATLAB_REQUIRED_INCLUDE_DIRS
+  VERSION_VAR Matlab_VERSION_STRING
+  HANDLE_COMPONENTS)
 
 unset(_matlab_required_variables)
 unset(_matlab_bin_prefix)
@@ -1380,7 +1373,6 @@ if(Matlab_INCLUDE_DIRS AND Matlab_LIBRARIES)
     Matlab_INCLUDE_DIRS
     Matlab_FOUND
     MATLAB_USER_ROOT
-    Matlab_ROOT_DIR
     Matlab_VERSION_STRING
     Matlab_MAIN_PROGRAM
     Matlab_MEX_EXTENSION
diff --git a/Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m b/Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m
index 66be1bb..11d5e9e 100644
--- a/Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m
+++ b/Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m
@@ -9,7 +9,8 @@ classdef cmake_matlab_unit_tests_timeout < matlab.unittest.TestCase
     function testCallHangsShouldBeTimedOut(testCase)
       cmake_matlab_mex1(rand(3,3));
       disp('Will now wait.');
-      input('Testing the cmake Matlab package timeout - do not press anything');
+      disp('Testing the cmake Matlab package timeout - do not kill');
+      pause(20); % supposed to be killed after 15s
     end
   end
 end
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 7715f1c..5df2d5b 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -200,6 +200,7 @@ if(RPMBUILD_EXECUTABLE)
 endif()
 
 # Matlab module related tests
-if(CMake_TEST_FindMatlab)
+if(CMake_TEST_FindMatlab AND NOT APPLE AND LINUX)
   add_RunCMake_test(FindMatlab)
 endif()
+
-- 
2.0.1

