1 ############################################################################## 2 # @file FindMATLAB.cmake 3 # @brief Find MATLAB installation. 5 # @par Input variables: 8 # @tp @b MATLAB_DIR @endtp 9 # <td>The installation directory of MATLAB. 10 # Can also be set as environment variable.</td> 13 # @tp @b MATLABDIR @endtp 14 # <td>Alternative environment variable for @p MATLAB_DIR.</td> 17 # @tp @b MATLAB_FIND_COMPONENTS @endtp 18 # <td>The @c COMPONENTS argument(s) of the find_package() command can 19 # be used to only look for specific MATLAB executables and libraries. 20 # Valid component values are "matlab", "mcc", "mexext", "mex", 21 # "libmex", "mx" or "libmx", "eng" or "libeng", 22 # "libmwmclmcr" or "mwmclmcr", and "libmwmclmcrrt" or "mwmclmcrrt".</td> 25 # @tp @b MATLAB_FIND_OPTIONAL_COMPONENTS @endtp 26 # <td>The @c OPTIONAL_COMPONENTS argument(s) of the find_package() command. 27 # See @c MATLAB_FIND_COMPONENTS.</td> 30 # @tp @b MATLAB_PATH_SUFFIXES @endtp 31 # <td>Path suffixes which are used to find the proper MATLAB libraries. 32 # By default, this find module tries to determine the path suffix 33 # from the CMake variables which describe the system. For example, 34 # on 64-bit Unix-based systems, the libraries are searched in 35 # @p MATLAB_DIR/bin/glnxa64. Set this variable before the 36 # find_package() command if this find module fails to 37 # determine the correct location of the MATLAB libraries within 38 # the root directory.</td> 42 # @par Output variables: 45 # @tp @b MATLAB_FOUND @endtp 46 # <td>Whether the package was found and the following CMake 47 # variables are valid.</td> 50 # @tp @b MATLAB_EXECUTABLE @endtp 51 # <td>The absolute path of the found matlab executable.</td> 54 # @tp @b MATLAB_VERSION_STRING @endtp 55 # <td>Version of the found matlab executable (e.g., 7.14.0).</td> 58 # @tp @b MATLAB_VERSION_MAJOR @endtp 59 # <td>Major version of the found matlab executable (e.g., 7).</td> 62 # @tp @b MATLAB_VERSION_MINOR @endtp 63 # <td>Minor version of the found matlab executable (e.g., 14).</td> 66 # @tp @b MATLAB_VERSION_PATCH @endtp 67 # <td>Patch of the found matlab executable (e.g., 0).</td> 70 # @tp @b MATLAB_RELEASE @endtp 71 # <td>Release version of the found matlab executable (e.g., R2012a).</td> 74 # @tp @b MATLAB_MCC_EXECUTABLE @endtp 75 # <td>The absolute path of the found MATLAB Compiler (mcc) executable.</td> 78 # @tp @b MATLAB_MEX_EXECUTABLE @endtp 79 # <td>The absolute path of the found MEX script (mex) executable.</td> 82 # @tp @b MATLAB_MEXEXT_EXECUTABLE @endtp 83 # <td>The absolute path of the found mexext script executable.</td> 86 # @tp @b MATLAB_INCLUDE_DIR @endtp 87 # <td>Package include directories.</td> 90 # @tp @b MATLAB_INCLUDES @endtp 91 # <td>Include directories including prerequisite libraries.</td> 94 # @tp @b MATLAB_LIBRARY_DIR @endtp 95 # <td>Directory containing the MATLAB libraries.</td> 98 # @tp @b MATLAB_mex_LIBRARY @endtp 99 # <td>The MEX library of MATLAB.</td> 102 # @tp @b MATLAB_mx_LIBRARY @endtp 103 # <td>The @c mx library of MATLAB.</td> 106 # @tp @b MATLAB_eng_LIBRARY @endtp 107 # <td>The MATLAB engine library.</td> 110 # @tp @b MATLAB_mwmclmcr_LIBRARY @endtp 111 # <td>The MATLAB Compiler library.</td> 114 # @tp @b MATLAB_mwmclmcrrt_LIBRARY @endtp 115 # <td>The MATLAB Compiler runtime library.</td> 118 # @tp @b MATLAB_LIBRARY @endtp 119 # <td>All MATLAB libraries excluding @c mwmclmcrrt.</td> 122 # @tp @b MATLAB_LIBRARIES @endtp 123 # <td>Package libraries and prerequisite libraries.</td> 127 # @ingroup CMakeFindModules 128 ############################################################################## 130 #============================================================================= 131 # Copyright 2011-2012 University of Pennsylvania 132 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com> 134 # Distributed under the OSI-approved BSD License (the "License"); 135 # see accompanying file Copyright.txt for details. 137 # This software is distributed WITHOUT ANY WARRANTY; without even the 138 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 139 # See the License for more information. 140 #============================================================================= 141 # (To distribute this file outside of CMake, substitute the full 142 # License text for the above reference.) 144 # ---------------------------------------------------------------------------- 147 if (NOT $ENV{MATLABDIR} STREQUAL
"")
148 set (MATLAB_DIR
"$ENV{MATLABDIR}" CACHE PATH
"Installation prefix for MATLAB." FORCE)
150 set (MATLAB_DIR
"$ENV{MATLAB_DIR}" CACHE PATH
"Installation prefix for MATLAB." FORCE)
156 if (CMAKE_GENERATOR MATCHES
"Visual Studio 6")
157 set (MATLAB_PATH_SUFFIXES
"extern/lib/win32/microsoft/msvc60")
158 elseif (CMAKE_GENERATOR MATCHES
"Visual Studio 7")
159 # assume people are generally using 7.1, 160 # if using 7.0 need to link to: extern/lib/win32/microsoft/msvc70 161 set (MATLAB_PATH_SUFFIXES
"extern/lib/win32/microsoft/msvc71")
162 elseif (CMAKE_GENERATOR MATCHES
"Visual Studio 8")
163 set (MATLAB_PATH_SUFFIXES
"extern/lib/win32/microsoft/msvc80")
164 elseif (CMAKE_GENERATOR MATCHES
"Visual Studio 9")
165 set (MATLAB_PATH_SUFFIXES
"extern/lib/win32/microsoft/msvc90")
166 elseif (CMAKE_GENERATOR MATCHES
"Borland")
167 # assume people are generally using 5.4 168 # if using 5.0 need to link to: ../extern/lib/win32/microsoft/bcc50 169 # if using 5.1 need to link to: ../extern/lib/win32/microsoft/bcc51 170 set (MATLAB_PATH_SUFFIXES
"extern/lib/win32/microsoft/bcc54")
173 if (CMAKE_SIZE_OF_VOID_P EQUAL 4)
174 set (MATLAB_PATH_SUFFIXES "bin/maci" "runtime/maci")
176 set (MATLAB_PATH_SUFFIXES "bin/maci64" "runtime/maci64")
179 if (CMAKE_SIZE_OF_VOID_P EQUAL 4)
180 set (MATLAB_PATH_SUFFIXES "bin/glnx86" "runtime/glnx86")
182 set (MATLAB_PATH_SUFFIXES "bin/glnxa64" "runtime/glnxa64")
192 if (MATLAB_FIND_COMPONENTS OR MATLAB_FIND_OPTIONAL_COMPONENTS)
193 foreach (_MATLAB_COMPONENT IN LISTS MATLAB_FIND_COMPONENTS)
194 string (TOLOWER "${_MATLAB_COMPONENT}
" _MATLAB_COMPONENT) 195 if (_MATLAB_COMPONENT MATCHES "^(matlab|mcc|mexext|mex)$
") 196 list (APPEND _MATLAB_EXECUTABLE_NAMES ${_MATLAB_COMPONENT}) 197 elseif (_MATLAB_COMPONENT MATCHES "^(lib)?(mex|mx|eng|mwmclmcr|mwmclmcrrt)$
") 198 list (APPEND _MATLAB_LIBRARY_NAMES ${CMAKE_MATCH_2}) 200 message (FATAL_ERROR "Unknown MATLAB component: ${_MATLAB_COMPONENT}
") 203 foreach (_MATLAB_COMPONENT IN LISTS MATLAB_FIND_OPTIONAL_COMPONENTS) 204 string (TOLOWER "${_MATLAB_COMPONENT}
" _MATLAB_COMPONENT) 205 if (_MATLAB_COMPONENT MATCHES "^(matlab|mcc|mexext|mex)$
") 206 list (APPEND _MATLAB_OPTIONAL_EXECUTABLE_NAMES ${_MATLAB_COMPONENT}) 207 elseif (_MATLAB_COMPONENT MATCHES "^(lib)?(mex|mx|eng|mwmclmcrrt)$
") 208 list (APPEND _MATLAB_OPTIONAL_LIBRARY_NAMES ${CMAKE_MATCH_2}) 210 message (FATAL_ERROR "Unknown MATLAB component: ${_MATLAB_COMPONENT}
") 214 set (_MATLAB_EXECUTABLE_NAMES matlab) 215 set (_MATLAB_OPTIONAL_EXECUTABLE_NAMES mcc mex mexext) 216 set (_MATLAB_LIBRARY_NAMES mwmclmcrrt) 217 set (_MATLAB_OPTIONAL_LIBRARY_NAMES mex mx eng) 220 # ---------------------------------------------------------------------------- 221 # find MATLAB executables 222 if (_MATLAB_EXECUTABLE_NAMES OR _MATLAB_OPTIONAL_EXECUTABLE_NAMES) 225 foreach (_MATLAB_EXE IN LISTS _MATLAB_EXECUTABLE_NAMES _MATLAB_OPTIONAL_EXECUTABLE_NAMES) 226 if (_MATLAB_EXE MATCHES "matlab
") 230 HINTS "${MATLAB_DIR}/bin
" 231 DOC "The MATLAB application (matlab).
" 233 mark_as_advanced (MATLAB_EXECUTABLE) 235 string (TOUPPER "${_MATLAB_EXE}
" _MATLAB_EXE_U) 236 if (WIN32 AND _MATLAB_EXE MATCHES "mex
") 237 list (APPEND _MATLAB_EXE "${_MATLAB_EXE}.bat
") 240 MATLAB_${_MATLAB_EXE_U}_EXECUTABLE 242 HINTS "${MATLAB_DIR}/bin
" 243 DOC "The MATLAB application ${_MATLAB_EXE}.
" 245 mark_as_advanced (MATLAB_${_MATLAB_EXE_U}_EXECUTABLE) 251 foreach (_MATLAB_EXE IN LISTS _MATLAB_EXECUTABLE_NAMES _MATLAB_OPTIONAL_EXECUTABLE_NAMES) 252 if (_MATLAB_EXE MATCHES "matlab
") 256 DOC "The MATLAB application (matlab).
" 258 mark_as_advanced (MATLAB_EXECUTABLE) 260 string (TOUPPER "${_MATLAB_EXE}
" _MATLAB_EXE_U) 262 MATLAB_${_MATLAB_EXE_U}_EXECUTABLE 263 NAMES "${_MATLAB_EXE}
" 264 DOC "The MATLAB application ${_MATLAB_EXE}.
" 266 mark_as_advanced (MATLAB_${_MATLAB_EXE_U}_EXECUTABLE) 273 # ---------------------------------------------------------------------------- 275 if (NOT MATLAB_DIR AND MATLAB_EXECUTABLE) 276 string (REGEX REPLACE "/bin(/[a-z0-9]+)?/(matlab|MATLAB)(\\.exe|\\.EXE)?$|/[^/]+\\.app/.*$
" "" _MATLAB_PREFIX "${MATLAB_EXECUTABLE}
") 278 string (REGEX REPLACE "^(.+\\.app)/.*$
" "\\1
" _MATLAB_PREFIX "${MATLAB_EXECUTABLE}
") 280 set (MATLAB_DIR "${_MATLAB_PREFIX}
" CACHE PATH "Installation prefix
for MATLAB.
" FORCE) 283 # ---------------------------------------------------------------------------- 284 # determine MATLAB version 285 if (COMMAND basis_get_matlab_version) 286 basis_get_matlab_version () 289 # ---------------------------------------------------------------------------- 291 if (_MATLAB_LIBRARY_NAMES OR _MATLAB_OPTIONAL_LIBRARY_NAMES) 297 HINTS "${MATLAB_DIR}/
extern/include
" 298 DOC "Include directory
for MATLAB libraries.
" 302 foreach (_MATLAB_LIB IN LISTS _MATLAB_LIBRARY_NAMES _MATLAB_OPTIONAL_LIBRARY_NAMES) 304 MATLAB_${_MATLAB_LIB}_LIBRARY 305 NAMES "${_MATLAB_LIB}
" "lib${_MATLAB_LIB}
" 306 HINTS "${MATLAB_DIR}
" 307 PATH_SUFFIXES ${MATLAB_PATH_SUFFIXES} 308 DOC "MATLAB ${_MATLAB_LIB} link library.
" 318 HINTS ENV C_INCLUDE_PATH ENV CXX_INCLUDE_PATH 319 DOC "Include directory
for MATLAB libraries.
" 322 foreach (_MATLAB_LIB IN LISTS _MATLAB_LIBRARY_NAMES _MATLAB_OPTIONAL_LIBRARY_NAMES) 324 MATLAB_${_MATLAB_LIB}_LIBRARY 325 NAMES "${_MATLAB_LIB}
" 326 HINTS ENV LD_LIBRARY_PATH 327 DOC "MATLAB ${_MATLAB_LIB} link library.
" 332 # mark variables as advanced 333 mark_as_advanced (MATLAB_INCLUDE_DIR) 334 foreach (_MATLAB_LIB IN LISTS _MATLAB_LIBRARY_NAMES _MATLAB_OPTIONAL_LIBRARY_NAMES) 335 mark_as_advanced (MATLAB_${_MATLAB_LIB}_LIBRARY) 337 # list of all libraries 339 foreach (_MATLAB_LIB IN LISTS _MATLAB_LIBRARY_NAMES _MATLAB_OPTIONAL_LIBRARY_NAMES) 340 if (MATLAB_${_MATLAB_LIB}_LIBRARY) 341 list (APPEND MATLAB_LIBRARY "${MATLAB_${_MATLAB_LIB}_LIBRARY}
") 344 # prerequisite libraries 345 set (MATLAB_INCLUDES "${MATLAB_INCLUDE_DIR}
") 346 set (MATLAB_LIBRARIES "${MATLAB_LIBRARY}
") 347 # aliases / backwards compatibility 352 # ---------------------------------------------------------------------------- 354 if (NOT MATLAB_DIR AND MATLAB_INCLUDE_DIR) 355 string (REGEX REPLACE "/
extern/include/?
" "" _MATLAB_PREFIX "${MATLAB_INCLUDE_DIR}
") 356 set (MATLAB_DIR "${_MATLAB_PREFIX}
" CACHE PATH "Installation prefix
for MATLAB.
" FORCE) 359 # ---------------------------------------------------------------------------- 360 # set MATLAB_LIBRARY_DIR 361 set (MATLAB_LIBRARY_DIR) 362 foreach (_MATLAB_LIB IN LISTS MATLAB_LIBRARY) 363 get_filename_component (MATLAB_LIBRARY_DIR "${_MATLAB_LIB}
" PATH) 364 if (MATLAB_LIBRARY_DIR) 369 # ---------------------------------------------------------------------------- 370 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE 371 # if all listed variables are found or TRUE 372 include (FindPackageHandleStandardArgs) 374 set (_MATLAB_REQUIRED_VARS) 376 foreach (_MATLAB_EXE IN LISTS _MATLAB_EXECUTABLE_NAMES) 377 if (_MATLAB_EXE MATCHES "matlab
") 378 list (APPEND _MATLAB_REQUIRED_VARS MATLAB_EXECUTABLE) 380 string (TOUPPER "${_MATLAB_EXE}
" _MATLAB_EXECUTABLE) 381 list (APPEND _MATLAB_REQUIRED_VARS MATLAB_${_MATLAB_EXECUTABLE}_EXECUTABLE) 385 if (_MATLAB_LIBRARY_NAMES) 386 list (APPEND _MATLAB_REQUIRED_VARS MATLAB_INCLUDE_DIR) 387 foreach (_MATLAB_LIB IN LISTS _MATLAB_LIBRARY_NAMES) 388 list (APPEND _MATLAB_REQUIRED_VARS MATLAB_${_MATLAB_LIB}_LIBRARY) 392 if (_MATLAB_REQUIRED_VARS) 393 find_package_handle_standard_args ( 398 MATLAB_DIR # for status message "Found MATLAB: ...
" 399 ${_MATLAB_REQUIRED_VARS} 402 set (MATLAB_FOUND TRUE) 405 # ---------------------------------------------------------------------------- 406 # unset private variables 407 unset (_MATLAB_REQUIRED_VARS) 408 unset (_MATLAB_EXECUTABLE_NAMES) 409 unset (_MATLAB_LIBRARY_NAMES) 410 unset (_MATLAB_PREFIX)
cmake _MATLAB_OPTIONAL_EXECUTABLE_NAMES
cmake MATLAB_PATH_SUFFIXES
cmake _MATLAB_EXECUTABLE_NAMES
cmake _MATLAB_OPTIONAL_LIBRARY_NAMES
cmake _MATLAB_LIBRARY_NAMES