summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-12 11:57:01 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-09-12 11:57:11 (GMT)
commitc6e07514a1bb8534dc3d2ab0018e7f9aaa56866b (patch)
tree508de5783e18944259a8b3d64e679178edb22c52 /Modules
parent9beb4dd8a752e3c9ea0e19152b85f68b0f96d7c6 (diff)
parent8ea398a7af125cf530f092c185107e6c1940d6f2 (diff)
downloadCMake-c6e07514a1bb8534dc3d2ab0018e7f9aaa56866b.zip
CMake-c6e07514a1bb8534dc3d2ab0018e7f9aaa56866b.tar.gz
CMake-c6e07514a1bb8534dc3d2ab0018e7f9aaa56866b.tar.bz2
Merge topic 'FindMatlab-version'
8ea398a7af FindMatlab: Prefer to use VersionInfo.xml to get version, fallback to run Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8760
Diffstat (limited to 'Modules')
-rw-r--r--Modules/FindMatlab.cmake67
1 files changed, 43 insertions, 24 deletions
diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake
index 8a2e1a1..fcd30ff 100644
--- a/Modules/FindMatlab.cmake
+++ b/Modules/FindMatlab.cmake
@@ -1290,7 +1290,7 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
if(EXISTS "${matlab_root}/appdata/version.xml")
# we inspect the application version.xml file that contains the product information
- file(STRINGS "${matlab_root}/appdata/version.xml" productinfo_string NEWLINE_CONSUME)
+ file(READ "${matlab_root}/appdata/version.xml" productinfo_string)
string(REGEX MATCH "<installedProductData.*displayedString=\"([a-zA-Z ]+)\".*/>"
product_reg_match
${productinfo_string}
@@ -1363,8 +1363,14 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
${_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)
+ _Matlab_VersionInfoXML()
+ if(Matlab_VERSION_STRING_INTERNAL AND NOT Matlab_VERSION_STRING_INTERNAL STREQUAL "unknown")
+ # at least back to R2016 VersionInfo.xml exists
+ set(matlab_list_of_all_versions ${Matlab_VERSION_STRING_INTERNAL})
+ else()
+ # time consuming, less stable way to find Matlab version by running Matlab
+ matlab_get_version_from_matlab_run("${Matlab_PROG_VERSION_STRING_AUTO_DETECT}" matlab_list_of_all_versions)
+ endif()
list(LENGTH matlab_list_of_all_versions list_of_all_versions_length)
if(list_of_all_versions_length GREATER 0)
@@ -1381,32 +1387,45 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
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_INTERNAL} PARENT_SCOPE)
- elseif(EXISTS "${matlab_root}/VersionInfo.xml")
+ else()
# MCR
# we cannot run anything in order to extract the version. We assume that the file
# VersionInfo.xml exists under the MatlabRoot, we look for it and extract the version from there
- set(_matlab_version_tmp "unknown")
- file(STRINGS "${matlab_root}/VersionInfo.xml" versioninfo_string NEWLINE_CONSUME)
-
- if(versioninfo_string)
- # parses "<version>9.2.0.538062</version>"
- string(REGEX MATCH "<version>(.*)</version>"
- version_reg_match
- ${versioninfo_string}
- )
+ _Matlab_VersionInfoXML()
+ endif() # Matlab or MCR
- if(CMAKE_MATCH_1 MATCHES "(([0-9]+)\\.([0-9]+))[\\.0-9]*")
- set(_matlab_version_tmp "${CMAKE_MATCH_1}")
- endif()
+ # return the updated value
+ set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE)
+
+endfunction()
+
+
+function(_Matlab_VersionInfoXML)
+
+ set(_matlab_version_tmp "unknown")
+
+ set(_XMLfile ${matlab_root}/VersionInfo.xml)
+ if(NOT EXISTS ${_XMLfile})
+ return()
+ endif()
+
+ file(READ ${_XMLfile} versioninfo_string)
+
+ if(versioninfo_string)
+ # parses "<version>9.2.0.538062</version>"
+ string(REGEX MATCH "<version>(.*)</version>"
+ version_reg_match
+ ${versioninfo_string}
+ )
+
+ if(CMAKE_MATCH_1 MATCHES "(([0-9]+)\\.([0-9]+))[\\.0-9]*")
+ set(_matlab_version_tmp "${CMAKE_MATCH_1}")
endif()
- set(${matlab_final_version} "${_matlab_version_tmp}" PARENT_SCOPE)
- set(Matlab_VERSION_STRING_INTERNAL
- "${_matlab_version_tmp}"
- CACHE INTERNAL "Matlab (MCR) version (automatically determined)"
- FORCE)
- endif() # Matlab or MCR
+ endif()
+
+ if(_matlab_version_tmp)
+ set(Matlab_VERSION_STRING_INTERNAL "${_matlab_version_tmp}" CACHE INTERNAL "Matlab version" FORCE)
+ endif()
endfunction()