Browse Source

FindMatlab: simplify several if()-constructs

Rolf Eike Beer 6 years ago
parent
commit
56e89e50d3
1 changed files with 25 additions and 25 deletions
  1. 25 25
      Modules/FindMatlab.cmake

+ 25 - 25
Modules/FindMatlab.cmake

@@ -224,6 +224,9 @@ Reference
   this list.
 #]=======================================================================]
 
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
 set(_FindMatlab_SELF_DIR "${CMAKE_CURRENT_LIST_DIR}")
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
@@ -395,7 +398,7 @@ function(matlab_extract_all_installed_versions_from_registry win64 matlab_versio
       )
 
 
-    if(${resultMatlab} EQUAL 0)
+    if(resultMatlab EQUAL 0)
 
       string(
         REGEX MATCHALL "MATLAB\\\\([0-9]+(\\.[0-9]+)?)"
@@ -612,9 +615,10 @@ function(matlab_get_mex_suffix matlab_root mex_suffix)
     OUTPUT_VARIABLE _matlab_mex_extension
     #RESULT_VARIABLE _matlab_mex_extension_call
     ERROR_VARIABLE _matlab_mex_extension_error
+    OUTPUT_STRIP_TRAILING_WHITESPACE
     ${devnull})
 
-  if(NOT "${_matlab_mex_extension_error}" STREQUAL "")
+  if(_matlab_mex_extension_error)
     if(WIN32)
       # this is only for intel architecture
       if(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -700,7 +704,7 @@ function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_ve
     ${devnull}
     )
 
-  if("${_matlab_result_version_call}" MATCHES "timeout")
+  if(_matlab_result_version_call MATCHES "timeout")
     if(MATLAB_FIND_DEBUG)
       message(WARNING "[MATLAB] Unable to determine the version of Matlab."
         " Matlab call timed out after 120 seconds.")
@@ -955,14 +959,14 @@ function(matlab_add_mex)
     set(${prefix}_OUTPUT_NAME ${${prefix}_NAME})
   endif()
 
-  if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.1") # For 9.1 (R2016b) and newer, add version source file
+  if(NOT Matlab_VERSION_STRING VERSION_LESS "9.1") # For 9.1 (R2016b) and newer, add version source file
     # TODO: check the file extensions in ${${prefix}_SRC} to see if they're C or C++ files
     # Currently, the C and C++ versions of the version files are identical, so this doesn't matter.
     set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/c_mexapi_version.c")
     #set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/cpp_mexapi_version.cpp")
   endif()
 
-  if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.4") # For 9.4 (R2018a) and newer, add API macro
+  if(NOT Matlab_VERSION_STRING VERSION_LESS "9.4") # For 9.4 (R2018a) and newer, add API macro
     if(${${prefix}_R2018a})
       set(MEX_API_MACRO "MATLAB_DEFAULT_RELEASE=R2018a")
     else()
@@ -1023,7 +1027,7 @@ function(matlab_add_mex)
     if (MSVC)
 
       set(_link_flags "${_link_flags} /EXPORT:mexFunction")
-      if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.1") # For 9.1 (R2016b) and newer, export version
+      if(NOT Matlab_VERSION_STRING VERSION_LESS "9.1") # For 9.1 (R2016b) and newer, export version
         set(_link_flags "${_link_flags} /EXPORT:mexfilerequiredapiversion")
       endif()
 
@@ -1042,13 +1046,13 @@ function(matlab_add_mex)
 
   else()
 
-    if(${Matlab_VERSION_STRING} VERSION_LESS "9.1") # For versions prior to 9.1 (R2016b)
+    if(Matlab_VERSION_STRING VERSION_LESS "9.1") # For versions prior to 9.1 (R2016b)
       set(_ver_map_files ${Matlab_EXTERN_LIBRARY_DIR}/mexFunction.map)
     else()                                          # For 9.1 (R2016b) and newer
       set(_ver_map_files ${Matlab_EXTERN_LIBRARY_DIR}/c_exportsmexfileversion.map)
     endif()
 
-    if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.5") # For 9.5 (R2018b) (and newer?)
+    if(NOT Matlab_VERSION_STRING VERSION_LESS "9.5") # For 9.5 (R2018b) (and newer?)
       target_compile_options(${${prefix}_NAME} PRIVATE "-fvisibility=default")
       # This one is weird, it might be a bug in <mex.h> for R2018b. When compiling with
       # -fvisibility=hidden, the symbol `mexFunction` cannot be exported. Reading the
@@ -1112,14 +1116,14 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
   #  set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version")
   #endif()
 
-  if(NOT ${matlab_known_version} STREQUAL "NOTFOUND")
+  if(NOT matlab_known_version STREQUAL "NOTFOUND")
     # the version is known, we just return it
     set(${matlab_final_version} ${matlab_known_version} PARENT_SCOPE)
     set(Matlab_VERSION_STRING_INTERNAL ${matlab_known_version} CACHE INTERNAL "Matlab version (automatically determined)" FORCE)
     return()
   endif()
 
-  if("${matlab_or_mcr}" STREQUAL "UNKNOWN")
+  if(matlab_or_mcr STREQUAL "UNKNOWN")
     if(MATLAB_FIND_DEBUG)
       message(WARNING "[MATLAB] Determining Matlab or MCR")
     endif()
@@ -1134,10 +1138,10 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
 
       # default fallback to Matlab
       set(matlab_or_mcr "MATLAB")
-      if(NOT "${CMAKE_MATCH_1}" STREQUAL "")
+      if(NOT CMAKE_MATCH_1 STREQUAL "")
         string(TOLOWER "${CMAKE_MATCH_1}" product_reg_match)
 
-        if("${product_reg_match}" STREQUAL "matlab runtime")
+        if(product_reg_match STREQUAL "matlab runtime")
           set(matlab_or_mcr "MCR")
         endif()
       endif()
@@ -1151,7 +1155,7 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
   # UNKNOWN is the default behaviour in case we
   # - have an erroneous matlab_root
   # - have an initial 'UNKNOWN'
-  if("${matlab_or_mcr}" STREQUAL "MATLAB" OR "${matlab_or_mcr}" STREQUAL "UNKNOWN")
+  if(matlab_or_mcr STREQUAL "MATLAB" OR matlab_or_mcr STREQUAL "UNKNOWN")
     # MATLAB versions
     set(_matlab_current_program ${Matlab_MAIN_PROGRAM})
 
@@ -1203,7 +1207,7 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
     matlab_get_version_from_matlab_run("${Matlab_PROG_VERSION_STRING_AUTO_DETECT}" matlab_list_of_all_versions)
 
     list(LENGTH matlab_list_of_all_versions list_of_all_versions_length)
-    if(${list_of_all_versions_length} GREATER 0)
+    if(list_of_all_versions_length GREATER 0)
       list(GET matlab_list_of_all_versions 0 _matlab_version_tmp)
     else()
       set(_matlab_version_tmp "unknown")
@@ -1213,7 +1217,7 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
     set(Matlab_VERSION_STRING_INTERNAL ${_matlab_version_tmp} CACHE INTERNAL "Matlab version (automatically determined)" FORCE)
 
     # warning, just in case several versions found (should not happen)
-    if((${list_of_all_versions_length} GREATER 1) AND MATLAB_FIND_DEBUG)
+    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()
 
@@ -1233,10 +1237,8 @@ function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_ve
              ${versioninfo_string}
             )
 
-      if(NOT "${version_reg_match}" STREQUAL "")
-        if("${CMAKE_MATCH_1}" MATCHES "(([0-9])\\.([0-9]))[\\.0-9]*")
-          set(_matlab_version_tmp "${CMAKE_MATCH_1}")
-        endif()
+      if(CMAKE_MATCH_1 MATCHES "(([0-9])\\.([0-9]))[\\.0-9]*")
+        set(_matlab_version_tmp "${CMAKE_MATCH_1}")
       endif()
     endif()
     set(${matlab_final_version} "${_matlab_version_tmp}" PARENT_SCOPE)
@@ -1615,8 +1617,7 @@ list(APPEND _matlab_required_variables Matlab_MEX_EXTENSION)
 list(APPEND _matlab_required_variables Matlab_ROOT_DIR)
 
 # component Mex Compiler
-list(FIND Matlab_FIND_COMPONENTS MEX_COMPILER _matlab_find_mex_compiler)
-if(_matlab_find_mex_compiler GREATER -1)
+if("MEX_COMPILER" IN_LIST Matlab_FIND_COMPONENTS)
   find_program(
     Matlab_MEX_COMPILER
     "mex"
@@ -1628,11 +1629,9 @@ if(_matlab_find_mex_compiler GREATER -1)
     set(Matlab_MEX_COMPILER_FOUND TRUE)
   endif()
 endif()
-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)
+if("MAIN_PROGRAM" IN_LIST Matlab_FIND_COMPONENTS)
   find_program(
     Matlab_MAIN_PROGRAM
     matlab
@@ -1644,7 +1643,6 @@ if(_matlab_find_matlab_program GREATER -1)
     set(Matlab_MAIN_PROGRAM_FOUND TRUE)
   endif()
 endif()
-unset(_matlab_find_matlab_program)
 
 # The MX library is required
 _Matlab_find_library(
@@ -1792,3 +1790,5 @@ if(Matlab_INCLUDE_DIRS AND Matlab_LIBRARIES)
     Matlab_MEX_EXTENSION
   )
 endif()
+
+cmake_policy(POP)