From d4c1b5e00bc84b7ed9f30a0468b40cae8baad6e2 Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Fri, 19 Jan 2024 17:14:39 +0100 Subject: FindMatlab: Fixup indentation --- Modules/FindMatlab.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 89f1757..4970918 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -476,8 +476,8 @@ function(matlab_extract_all_installed_versions_from_registry win64 matlab_versio foreach(_installation_type IN ITEMS "MATLAB" "MATLAB Runtime" "MATLAB Compiler Runtime") cmake_host_system_information(RESULT _reg - QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Mathworks/${_installation_type}" - SUBKEYS VIEW ${_view} + QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Mathworks/${_installation_type}" + SUBKEYS VIEW ${_view} ) if(_reg) -- cgit v0.12 From cd2541bb5658059a19e31e94da3f0731f02f2503 Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Fri, 19 Jan 2024 17:22:03 +0100 Subject: FindMatlab: Remove unnecessary if statements and loops --- Modules/FindMatlab.cmake | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 4970918..1ff2aff 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -480,16 +480,10 @@ function(matlab_extract_all_installed_versions_from_registry win64 matlab_versio SUBKEYS VIEW ${_view} ) - if(_reg) - string(REGEX MATCHALL "([0-9]+(\\.[0-9]+)+)" _versions_regex "${_reg}") + string(REGEX MATCHALL "([0-9]+(\\.[0-9]+)+)" _versions_regex "${_reg}") - foreach(_match IN LISTS _versions_regex) - if(_match MATCHES "([0-9]+(\\.[0-9]+)+)") - list(APPEND matlabs_from_registry ${_match}) - endif() - endforeach() + list(APPEND matlabs_from_registry ${_versions_regex}) - endif() endforeach() if(matlabs_from_registry) -- cgit v0.12 From c847be4fc7afde1e74adb8befb7d84a3be68c6cb Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Fri, 19 Jan 2024 17:24:00 +0100 Subject: FindMatlab: Remove extra [Debug] from log message --- Modules/FindMatlab.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 1ff2aff..eb19380 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -1785,7 +1785,7 @@ unset(_matlab_64Build) if(MATLAB_FIND_DEBUG) - message(STATUS "[MATLAB] [DEBUG]_matlab_lib_prefix_for_search = ${_matlab_lib_prefix_for_search} | _matlab_lib_dir_for_search = ${_matlab_lib_dir_for_search}") + message(STATUS "[MATLAB] _matlab_lib_prefix_for_search = ${_matlab_lib_prefix_for_search} | _matlab_lib_dir_for_search = ${_matlab_lib_dir_for_search}") endif() -- cgit v0.12 From 657064b6d489060d4efde89aca6951eed38fb48e Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Wed, 24 Jan 2024 13:17:32 +0100 Subject: FindMatlab: Refactor: Eliminate _matlab_64Build --- Modules/FindMatlab.cmake | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index eb19380..1f02797 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -1717,12 +1717,6 @@ if(Matlab_ROOT_DIR) file(TO_CMAKE_PATH ${Matlab_ROOT_DIR} Matlab_ROOT_DIR) endif() -if(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(_matlab_64Build FALSE) -else() - set(_matlab_64Build TRUE) -endif() - if(NOT DEFINED Matlab_MEX_EXTENSION) set(_matlab_mex_extension "") @@ -1756,7 +1750,7 @@ endif() set(MATLAB_INCLUDE_DIR_TO_LOOK ${Matlab_ROOT_DIR}/extern/include) -if(_matlab_64Build) +if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(_matlab_current_suffix ${_matlab_bin_suffix_64bits}) else() set(_matlab_current_suffix ${_matlab_bin_suffix_32bits}) @@ -1781,8 +1775,6 @@ else() set(_matlab_lib_prefix_for_search "lib") endif() -unset(_matlab_64Build) - if(MATLAB_FIND_DEBUG) message(STATUS "[MATLAB] _matlab_lib_prefix_for_search = ${_matlab_lib_prefix_for_search} | _matlab_lib_dir_for_search = ${_matlab_lib_dir_for_search}") -- cgit v0.12 From 07256587f1186526844a9361be469ed5cdcee49f Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Wed, 24 Jan 2024 08:53:44 +0100 Subject: FindMatlab: Simplify ROOT lookup for new and old MCR --- Modules/FindMatlab.cmake | 50 ++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 1f02797..0b8ba86 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -560,42 +560,26 @@ function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_ endforeach() # Check for MCR installations - foreach(_matlab_current_version IN LISTS matlab_versions) - cmake_host_system_information(RESULT current_MATLAB_ROOT - QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Mathworks/MATLAB Runtime/${_matlab_current_version}" - VALUE "MATLABROOT" - ) - cmake_path(CONVERT "${current_MATLAB_ROOT}" TO_CMAKE_PATH_LIST current_MATLAB_ROOT) + foreach(_installation_type IN ITEMS "MATLAB Runtime" "MATLAB Compiler Runtime") + foreach(_matlab_current_version IN LISTS matlab_versions) + cmake_host_system_information(RESULT current_MATLAB_ROOT + QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Mathworks/${_installation_type}/${_matlab_current_version}" + VALUE "MATLABROOT" + ) + cmake_path(CONVERT "${current_MATLAB_ROOT}" TO_CMAKE_PATH_LIST current_MATLAB_ROOT) - # remove the dot - string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}") + # remove the dot + string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}") - if(IS_DIRECTORY "${current_MATLAB_ROOT}") - _Matlab_VersionInfoXML("${current_MATLAB_ROOT}" _matlab_version_tmp) - if("${_matlab_version_tmp}" STREQUAL "unknown") - list(APPEND _matlab_roots_list "MCR" ${_matlab_current_version} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") - else() - list(APPEND _matlab_roots_list "MCR" ${_matlab_version_tmp} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") + if(IS_DIRECTORY "${current_MATLAB_ROOT}") + _Matlab_VersionInfoXML("${current_MATLAB_ROOT}" _matlab_version_tmp) + if("${_matlab_version_tmp}" STREQUAL "unknown") + list(APPEND _matlab_roots_list "MCR" ${_matlab_current_version} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") + else() + list(APPEND _matlab_roots_list "MCR" ${_matlab_version_tmp} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") + endif() endif() - endif() - - endforeach() - - # Check for old MCR installations - foreach(_matlab_current_version IN LISTS matlab_versions) - cmake_host_system_information(RESULT current_MATLAB_ROOT - QUERY WINDOWS_REGISTRY "HKLM/SOFTWARE/Mathworks/MATLAB Compiler Runtime/${_matlab_current_version}" - VALUE "MATLABROOT" - ) - cmake_path(CONVERT "${current_MATLAB_ROOT}" TO_CMAKE_PATH_LIST current_MATLAB_ROOT) - - # remove the dot - string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}") - - if(IS_DIRECTORY "${current_MATLAB_ROOT}") - list(APPEND _matlab_roots_list "MCR" ${_matlab_current_version} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") - endif() - + endforeach() endforeach() set(${matlab_roots} ${_matlab_roots_list} PARENT_SCOPE) endfunction() -- cgit v0.12 From 37723c4beeb246d6e2d1b05e7c77db8d9b7dee6f Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Wed, 24 Jan 2024 09:29:58 +0100 Subject: FindMatlab: Refactor Matlab root list append operation --- Modules/FindMatlab.cmake | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 0b8ba86..3365ceb 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -551,10 +551,9 @@ function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_ if(IS_DIRECTORY "${current_MATLAB_ROOT}") _Matlab_VersionInfoXML("${current_MATLAB_ROOT}" _matlab_version_tmp) if("${_matlab_version_tmp}" STREQUAL "unknown") - list(APPEND _matlab_roots_list "MATLAB" ${_matlab_current_version} ${current_MATLAB_ROOT}) - else() - list(APPEND _matlab_roots_list "MATLAB" ${_matlab_version_tmp} ${current_MATLAB_ROOT}) + set(_matlab_version_tmp ${_matlab_current_version}) endif() + list(APPEND _matlab_roots_list "MATLAB" ${_matlab_version_tmp} ${current_MATLAB_ROOT}) endif() endforeach() @@ -574,10 +573,9 @@ function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_ if(IS_DIRECTORY "${current_MATLAB_ROOT}") _Matlab_VersionInfoXML("${current_MATLAB_ROOT}" _matlab_version_tmp) if("${_matlab_version_tmp}" STREQUAL "unknown") - list(APPEND _matlab_roots_list "MCR" ${_matlab_current_version} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") - else() - list(APPEND _matlab_roots_list "MCR" ${_matlab_version_tmp} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") + set(_matlab_version_tmp ${_matlab_current_version}) endif() + list(APPEND _matlab_roots_list "MCR" ${_matlab_version_tmp} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}") endif() endforeach() endforeach() -- cgit v0.12 From ce426e2a450505e5d523ff3883c42b729f12f269 Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Wed, 24 Jan 2024 10:39:16 +0100 Subject: FindMatlab: Do not query host processor for registry view `matlab_extract_all_installed_versions_from_registry` searched for 32-bit installations on 32-bit Windows even if win64 was set to 'TRUE'. Now, no installation will be found if win64 is set to 'TRUE' on 32-bit Windows, which is also the documented behavior. --- Modules/FindMatlab.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 3365ceb..a2ace66 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -465,7 +465,7 @@ function(matlab_extract_all_installed_versions_from_registry win64 matlab_versio message(FATAL_ERROR "[MATLAB] This function can only be called by a Windows host") endif() - if(${win64} AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "64") + if(${win64}) set(_view "64") else() set(_view "32") -- cgit v0.12 From 91c672e5aedb936abd9015450d6937f613395f8d Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Fri, 2 Feb 2024 17:23:50 +0100 Subject: FindMatlab: Use find_package(Threads) instead of checking -pthread --- Modules/FindMatlab.cmake | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index a2ace66..68596d5 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -287,9 +287,12 @@ cmake_policy(SET CMP0057 NEW) # if IN_LIST set(_FindMatlab_SELF_DIR "${CMAKE_CURRENT_LIST_DIR}") include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -include(CheckCXXCompilerFlag) -include(CheckCCompilerFlag) +if(NOT WIN32 AND NOT APPLE AND NOT Threads_FOUND) + # MEX files use pthread if available + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads) +endif() # The currently supported versions. Other version can be added by the user by # providing MATLAB_ADDITIONAL_VERSIONS @@ -1046,12 +1049,6 @@ function(matlab_add_mex) if(NOT WIN32) # we do not need all this on Windows - # pthread options - if(CMAKE_CXX_COMPILER_LOADED) - check_cxx_compiler_flag(-pthread HAS_MINUS_PTHREAD) - elseif(CMAKE_C_COMPILER_LOADED) - check_c_compiler_flag(-pthread HAS_MINUS_PTHREAD) - endif() # we should use try_compile instead, the link flags are discarded from # this compiler_flag function. #check_cxx_compiler_flag(-Wl,--exclude-libs,ALL HAS_SYMBOL_HIDING_CAPABILITY) @@ -1225,10 +1222,8 @@ function(matlab_add_mex) else() # Linux - if(HAS_MINUS_PTHREAD) - # Apparently, compiling with -pthread generated the proper link flags - # and some defines at compilation - target_compile_options(${${prefix}_NAME} PRIVATE "-pthread") + if(Threads_FOUND) + target_link_libraries(${${prefix}_NAME} Threads::Threads) endif() string(APPEND _link_flags " -Wl,--as-needed") -- cgit v0.12 From ab08e75921828925c6f7f1c36a8f4226c83384f1 Mon Sep 17 00:00:00 2001 From: Hermann von Kleist Date: Fri, 2 Feb 2024 17:26:04 +0100 Subject: FindMatlab: Remove dead commented-out code --- Modules/FindMatlab.cmake | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 68596d5..c71445e 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -1047,14 +1047,6 @@ endfunction() #]=======================================================================] function(matlab_add_mex) - if(NOT WIN32) - # we do not need all this on Windows - # we should use try_compile instead, the link flags are discarded from - # this compiler_flag function. - #check_cxx_compiler_flag(-Wl,--exclude-libs,ALL HAS_SYMBOL_HIDING_CAPABILITY) - - endif() - set(options EXECUTABLE MODULE SHARED R2017b R2018a EXCLUDE_FROM_ALL NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES) set(oneValueArgs NAME DOCUMENTATION OUTPUT_NAME) set(multiValueArgs LINK_TO SRC) -- cgit v0.12