From b90d7a3a8204e965e3cb59ddab8f9c171f6e0691 Mon Sep 17 00:00:00 2001 From: scivision Date: Thu, 12 Sep 2024 12:32:25 -0400 Subject: [PATCH] FindMatlab: On macOS search under ~/Applications and /Applications users with locked-down macOS may not be able to install their desired Matlab under /Applications, but may use the standard ~/Applications instead --- Modules/FindMatlab.cmake | 50 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 45d4681c60..5c78a8d6aa 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -66,8 +66,9 @@ specific: Windows registry. The ``REGISTRY_VIEW`` argument may optionally be specified to manually control whether 32bit or 64bit versions shall be searched for. * macOS: The installed versions of Matlab/MCR are given by the MATLAB - default installation paths in ``/Application``. If no such application is - found, it falls back to the one that might be accessible from the ``PATH``. + default installation paths under ``$HOME/Applications`` and ``/Applications``. + 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``. This does not work for MCR installation and :variable:`Matlab_ROOT_DIR` should be specified on this platform. @@ -1489,7 +1490,7 @@ endfunction() function(_Matlab_find_instances_macos matlab_roots) set(_matlab_possible_roots) - # on mac, we look for the /Application paths + # on macOS, we look for the standard /Applications paths # this corresponds to the behavior on Windows. On Linux, we do not have # any other guess. matlab_get_supported_releases(_matlab_releases) @@ -1499,32 +1500,33 @@ function(_Matlab_find_instances_macos matlab_roots) endif() foreach(_matlab_current_release IN LISTS _matlab_releases) - matlab_get_version_from_release_name("${_matlab_current_release}" _matlab_current_version) - string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}") - set(_matlab_base_path "/Applications/MATLAB_${_matlab_current_release}.app") + foreach(_macos_app_base IN ITEMS "$ENV{HOME}/Applications" "/Applications") + matlab_get_version_from_release_name("${_matlab_current_release}" _matlab_current_version) + string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}") + set(_matlab_base_path "${_macos_app_base}/MATLAB_${_matlab_current_release}.app") - _Matlab_VersionInfoXML("${_matlab_base_path}" _matlab_version_tmp) - if(NOT "${_matlab_version_tmp}" STREQUAL "unknown") - set(_matlab_current_version ${_matlab_version_tmp}) - endif() - - # Check Matlab, has precedence over MCR - if(IS_DIRECTORY "${_matlab_base_path}") - if(MATLAB_FIND_DEBUG) - message(STATUS "[MATLAB] Found version ${_matlab_current_release} (${_matlab_current_version}) in ${_matlab_base_path}") + _Matlab_VersionInfoXML("${_matlab_base_path}" _matlab_version_tmp) + if(NOT "${_matlab_version_tmp}" STREQUAL "unknown") + set(_matlab_current_version ${_matlab_version_tmp}) endif() - list(APPEND _matlab_possible_roots "MATLAB" ${_matlab_current_version} ${_matlab_base_path}) - endif() - # Checks MCR - set(_mcr_path "/Applications/MATLAB/MATLAB_Runtime/v${_matlab_current_version_without_dot}") - if(IS_DIRECTORY "${_mcr_path}") - if(MATLAB_FIND_DEBUG) - message(STATUS "[MATLAB] Found MCR version ${_matlab_current_release} (${_matlab_current_version}) in ${_mcr_path}") + # Check Matlab, has precedence over MCR + if(IS_DIRECTORY "${_matlab_base_path}") + if(MATLAB_FIND_DEBUG) + message(STATUS "[MATLAB] Found version ${_matlab_current_release} (${_matlab_current_version}) in ${_matlab_base_path}") + endif() + list(APPEND _matlab_possible_roots "MATLAB" ${_matlab_current_version} ${_matlab_base_path}) endif() - list(APPEND _matlab_possible_roots "MCR" ${_matlab_current_version} ${_mcr_path}) - endif() + # Checks MCR + set(_mcr_path "${_macos_app_base}/MATLAB/MATLAB_Runtime/v${_matlab_current_version_without_dot}") + if(IS_DIRECTORY "${_mcr_path}") + if(MATLAB_FIND_DEBUG) + message(STATUS "[MATLAB] Found MCR version ${_matlab_current_release} (${_matlab_current_version}) in ${_mcr_path}") + endif() + list(APPEND _matlab_possible_roots "MCR" ${_matlab_current_version} ${_mcr_path}) + endif() + endforeach() endforeach() set(${matlab_roots} ${_matlab_possible_roots} PARENT_SCOPE)