diff options
Diffstat (limited to 'Modules/FindMatlab.cmake')
-rw-r--r-- | Modules/FindMatlab.cmake | 87 |
1 files changed, 34 insertions, 53 deletions
diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 6c80506..89f1757 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -1098,14 +1098,27 @@ function(matlab_add_mex) endif() if(NOT Matlab_VERSION_STRING VERSION_LESS "9.1") # For 9.1 (R2016b) and newer, add version source file + # Compilers officially supported by Matlab 9.1 (R2016b): + # MinGW 4.9, MSVC 2012, Intel C++ 2013, Xcode 6, GCC 4.9 + # These compilers definitely support the -w flag to suppress warnings. + # Other compilers (Clang) may support the -w flag and can be added here. + set(_Matlab_silenceable_compilers AppleClang Clang GNU Intel IntelLLVM MSVC) + # Add the correct version file depending on which languages are enabled in the project if(CMAKE_C_COMPILER_LOADED) # If C is enabled, use the .c file as it will work fine also with C++ set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/c_mexapi_version.c") + # Silence warnings for version source file + if("${CMAKE_C_COMPILER_ID}" IN_LIST _Matlab_silenceable_compilers) + set_source_files_properties("${MEX_VERSION_FILE}" PROPERTIES COMPILE_OPTIONS -w) + endif() elseif(CMAKE_CXX_COMPILER_LOADED) # If C is not enabled, check if CXX is enabled and use the .cpp file # to avoid that the .c file is silently ignored set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/cpp_mexapi_version.cpp") + if("${CMAKE_CXX_COMPILER_ID}" IN_LIST _Matlab_silenceable_compilers) + set_source_files_properties("${MEX_VERSION_FILE}" PROPERTIES COMPILE_OPTIONS -w) + endif() else() # If neither C or CXX is enabled, warn because we cannot add the source. # TODO: add support for fortran mex files @@ -1624,62 +1637,29 @@ list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots) set(Matlab_VERSION_STRING "NOTFOUND") set(Matlab_Or_MCR "UNKNOWN") if(_numbers_of_matlab_roots GREATER 0) - if(Matlab_FIND_VERSION_EXACT) - set(_list_index -1) - foreach(_matlab_root_index RANGE 1 ${_numbers_of_matlab_roots} 3) - list(GET _matlab_possible_roots ${_matlab_root_index} _matlab_root_version) - # only the major.minor version is used - string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*" "\\1" _matlab_root_version "${_matlab_root_version}") - if(_matlab_root_version VERSION_EQUAL Matlab_FIND_VERSION) - set(_list_index ${_matlab_root_index}) - break() - endif() - endforeach() - - if(_list_index LESS 0) - set(_list_index 1) + set(_list_index -1) + foreach(_matlab_root_index RANGE 1 ${_numbers_of_matlab_roots} 3) + list(GET _matlab_possible_roots ${_matlab_root_index} _matlab_root_version) + find_package_check_version(${_matlab_root_version} _matlab_version_ok HANDLE_VERSION_RANGE) + if(_matlab_version_ok) + set(_list_index ${_matlab_root_index}) + break() endif() + endforeach() - math(EXPR _matlab_or_mcr_index "${_list_index} - 1") - math(EXPR _matlab_root_dir_index "${_list_index} + 1") - - list(GET _matlab_possible_roots ${_matlab_or_mcr_index} Matlab_Or_MCR) - list(GET _matlab_possible_roots ${_list_index} Matlab_VERSION_STRING) - list(GET _matlab_possible_roots ${_matlab_root_dir_index} Matlab_ROOT_DIR) - elseif(DEFINED Matlab_FIND_VERSION) - set(_list_index -1) - foreach(_matlab_root_index RANGE 1 ${_numbers_of_matlab_roots} 3) - list(GET _matlab_possible_roots ${_matlab_root_index} _matlab_root_version) - if(_matlab_root_version VERSION_GREATER_EQUAL Matlab_FIND_VERSION) - set(_list_index ${_matlab_root_index}) - break() - endif() - endforeach() - - if(_list_index LESS 0) - set(_list_index 1) - endif() + if(_list_index LESS 0) + set(_list_index 1) + endif() - math(EXPR _matlab_or_mcr_index "${_list_index} - 1") - math(EXPR _matlab_root_dir_index "${_list_index} + 1") - list(GET _matlab_possible_roots ${_matlab_or_mcr_index} Matlab_Or_MCR) - list(GET _matlab_possible_roots ${_list_index} Matlab_VERSION_STRING) - list(GET _matlab_possible_roots ${_matlab_root_dir_index} Matlab_ROOT_DIR) - # adding a warning in case of ambiguity - if(_numbers_of_matlab_roots GREATER 3 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 this is not the desired behavior, use the EXACT keyword or provide the -DMatlab_ROOT_DIR=... on the command line") - endif() - else() - list(GET _matlab_possible_roots 0 Matlab_Or_MCR) - list(GET _matlab_possible_roots 1 Matlab_VERSION_STRING) - list(GET _matlab_possible_roots 2 Matlab_ROOT_DIR) - - # adding a warning in case of ambiguity - if(_numbers_of_matlab_roots GREATER 3 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 this is not the desired behavior, use the EXACT keyword or provide the -DMatlab_ROOT_DIR=... on the command line") - endif() + math(EXPR _matlab_or_mcr_index "${_list_index} - 1") + math(EXPR _matlab_root_dir_index "${_list_index} + 1") + list(GET _matlab_possible_roots ${_matlab_or_mcr_index} Matlab_Or_MCR) + list(GET _matlab_possible_roots ${_list_index} Matlab_VERSION_STRING) + list(GET _matlab_possible_roots ${_matlab_root_dir_index} Matlab_ROOT_DIR) + # adding a warning in case of ambiguity + if(_numbers_of_matlab_roots GREATER 3 AND NOT Matlab_FIND_VERSION_EXACT 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 this is not the desired behavior, use the EXACT keyword or provide the -DMatlab_ROOT_DIR=... on the command line") endif() endif() @@ -2030,6 +2010,7 @@ find_package_handle_standard_args( FOUND_VAR Matlab_FOUND REQUIRED_VARS ${_matlab_required_variables} VERSION_VAR Matlab_VERSION + HANDLE_VERSION_RANGE HANDLE_COMPONENTS) unset(_matlab_required_variables) |