Go to the documentation of this file.00001 ##############################################################################
00002 # @file FindMATLAB.cmake
00003 # @brief Find MATLAB installation.
00004 #
00005 # @par Input variables:
00006 # <table border="0">
00007 # <tr>
00008 # @tp @b MATLAB_DIR @endtp
00009 # <td>The installation directory of MATLAB.
00010 # Can also be set as environment variable.</td>
00011 # </tr>
00012 # <tr>
00013 # @tp @b MATLABDIR @endtp
00014 # <td>Alternative environment variable for @p MATLAB_DIR.</td>
00015 # </tr>
00016 # <tr>
00017 # @tp @b MATLAB_PATH_SUFFIXES @endtp
00018 # <td>Path suffixes which are used to find the proper MATLAB libraries.
00019 # By default, this find module tries to determine the path suffix
00020 # from the CMake variables which describe the system. For example,
00021 # on 64-bit Unix-based systems, the libraries are searched in
00022 # @p MATLAB_DIR/bin/glna64. Set this variable before the
00023 # find_package() command if this find module fails to
00024 # determine the correct location of the MATLAB libraries within
00025 # the root directory.</td>
00026 # </tr>
00027 # </table>
00028 #
00029 # @par Output variables:
00030 # <table border="0">
00031 # <tr>
00032 # @tp @b MATLAB_FOUND @endtp
00033 # <td>Whether the package was found and the following CMake
00034 # variables are valid.</td>
00035 # </tr>
00036 # <tr>
00037 # @tp @b MATLAB_EXECUTABLE @endtp
00038 # <td>The absolute path of the found matlab executable.</td>
00039 # </tr>
00040 # <tr>
00041 # @tp @b MATLAB_MCC_EXECUTABLE @endtp
00042 # <td>The absolute path of the found MATLAB Compiler (mcc) executable.</td>
00043 # </tr>
00044 # <tr>
00045 # @tp @b MATLAB_MEX_EXECUTABLE @endtp
00046 # <td>The absolute path of the found MEX script (mex) executable.</td>
00047 # </tr>
00048 # <tr>
00049 # @tp @b MATLAB_MEXEXT_EXECUTABLE @endtp
00050 # <td>The absolute path of the found mexext script executable.</td>
00051 # </tr>
00052 # <tr>
00053 # @tp @b MATLAB_INCLUDE_DIR @endtp
00054 # <td>Package include directories.</td>
00055 # </tr>
00056 # <tr>
00057 # @tp @b MATLAB_INCLUDES @endtp
00058 # <td>Include directories including prerequisite libraries.</td>
00059 # </tr>
00060 # <tr>
00061 # @tp @b MATLAB_mex_LIBRARY @endtp
00062 # <td>The MEX library of MATLAB.</td>
00063 # </tr>
00064 # <tr>
00065 # @tp @b MATLAB_mx_LIBRARY @endtp
00066 # <td>The @c mx library of MATLAB.</td>
00067 # </tr>
00068 # <tr>
00069 # @tp @b MATLAB_eng_LIBRARY @endtp
00070 # <td>The MATLAB engine library.</td>
00071 # </tr>
00072 # <tr>
00073 # @tp @b MATLAB_LIBRARY @endtp
00074 # <td>All MATLAB libraries.</td>
00075 # </tr>
00076 # <tr>
00077 # @tp @b MATLAB_LIBRARIES @endtp
00078 # <td>Package libraries and prerequisite libraries.</td>
00079 # </tr>
00080 # </table>
00081 #
00082 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br />
00083 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00084 #
00085 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00086 #
00087 # @ingroup CMakeFindModules
00088 ##############################################################################
00089
00090 # ----------------------------------------------------------------------------
00091 # initialize search
00092 if (NOT MATLAB_DIR)
00093 if (NOT $ENV{MATLABDIR} STREQUAL "")
00094 set (MATLAB_DIR "$ENV{MATLABDIR}" CACHE PATH "Installation prefix for MATLAB." FORCE)
00095 else ()
00096 set (MATLAB_DIR "$ENV{MATLAB_DIR}" CACHE PATH "Installation prefix for MATLAB." FORCE)
00097 endif ()
00098 endif ()
00099
00100 if (NOT MATLAB_PATH_SUFFIXES)
00101 if (WIN32)
00102 if (CMAKE_GENERATOR MATCHES "Visual Studio 6")
00103 set (MATLAB_PATH_SUFFIXES "extern/lib/win32/microsoft/msvc60")
00104 elseif (CMAKE_GENERATOR MATCHES "Visual Studio 7")
00105 # assume people are generally using 7.1,
00106 # if using 7.0 need to link to: extern/lib/win32/microsoft/msvc70
00107 set (MATLAB_PATH_SUFFIXES "extern/lib/win32/microsoft/msvc71")
00108 elseif (CMAKE_GENERATOR MATCHES "Visual Studio 8")
00109 set (MATLAB_PATH_SUFFIXES "extern/lib/win32/microsoft/msvc80")
00110 elseif (CMAKE_GENERATOR MATCHES "Visual Studio 9")
00111 set (MATLAB_PATH_SUFFIXES "extern/lib/win32/microsoft/msvc90")
00112 elseif (CMAKE_GENERATOR MATCHES "Borland")
00113 # assume people are generally using 5.4
00114 # if using 5.0 need to link to: ../extern/lib/win32/microsoft/bcc50
00115 # if using 5.1 need to link to: ../extern/lib/win32/microsoft/bcc51
00116 set (MATLAB_PATH_SUFFIXES "extern/lib/win32/microsoft/bcc54")
00117 endif ()
00118 else ()
00119 if (CMAKE_SIZE_OF_VOID_P EQUAL 4)
00120 set (MATLAB_PATH_SUFFIXES "bin/glnx86")
00121 else ()
00122 set (MATLAB_PATH_SUFFIXES "bin/glnxa64")
00123 endif ()
00124 endif ()
00125 endif ()
00126
00127 set (MATLAB_LIBRARY_NAMES "mex" "mx" "eng")
00128
00129 # ----------------------------------------------------------------------------
00130 # find MATLAB executables
00131 if (MATLAB_DIR)
00132 find_program (
00133 MATLAB_EXECUTABLE
00134 NAMES matlab
00135 HINTS "${MATLAB_DIR}"
00136 PATH_SUFFIXES "bin"
00137 DOC "The MATLAB application (matlab)."
00138 )
00139
00140 find_program (
00141 MATLAB_MCC_EXECUTABLE
00142 NAMES mcc
00143 HINTS "${MATLAB_DIR}"
00144 PATH_SUFFIXES "bin"
00145 DOC "The MATLAB Compiler (mcc)."
00146 )
00147
00148 find_program (
00149 MATLAB_MEX_EXECUTABLE
00150 NAMES mex
00151 HINTS "${MATLAB_DIR}"
00152 PATH_SUFFIXES "bin"
00153 DOC "The MEX-file generator of MATLAB (mex)."
00154 )
00155
00156 find_program (
00157 MATLAB_MEXEXT_EXECUTABLE
00158 NAMES mexext
00159 HINTS "${MATLAB_DIR}"
00160 PATH_SUFFIXES "bin"
00161 DOC "The MEXEXT script of MATLAB (mexext)."
00162 )
00163 else ()
00164 find_program (
00165 MATLAB_EXECUTABLE
00166 NAMES matlab
00167 DOC "The MATLAB application (matlab)."
00168 )
00169
00170 find_program (
00171 MATLAB_MCC_EXECUTABLE
00172 NAMES mcc
00173 DOC "The MATLAB Compiler (mcc)."
00174 )
00175
00176 find_program (
00177 MATLAB_MEX_EXECUTABLE
00178 NAMES mex
00179 DOC "The MEX-file generator of MATLAB (mex)."
00180 )
00181
00182 find_program (
00183 MATLAB_MEXEXT_EXECUTABLE
00184 NAMES mexext
00185 DOC "The MEXEXT script of MATLAB (mexext)."
00186 )
00187 endif ()
00188
00189 mark_as_advanced (MATLAB_EXECUTABLE)
00190 mark_as_advanced (MATLAB_MCC_EXECUTABLE)
00191 mark_as_advanced (MATLAB_MEX_EXECUTABLE)
00192 mark_as_advanced (MATLAB_MEXEXT_EXECUTABLE)
00193
00194 # ----------------------------------------------------------------------------
00195 # find paths/files
00196 if (MATLAB_DIR)
00197
00198 find_path (
00199 MATLAB_INCLUDE_DIR
00200 NAMES mex.h
00201 HINTS "${MATLAB_DIR}"
00202 PATH_SUFFIXES "extern/include"
00203 DOC "Include directory for MATLAB libraries."
00204 NO_DEFAULT_PATH
00205 )
00206
00207 foreach (LIB ${MATLAB_LIBRARY_NAMES})
00208 find_library (
00209 MATLAB_${LIB}_LIBRARY
00210 NAMES ${LIB} lib${LIB}
00211 HINTS "${MATLAB_DIR}"
00212 PATH_SUFFIXES ${MATLAB_PATH_SUFFIXES}
00213 DOC "MATLAB ${LIB} link library."
00214 NO_DEFAULT_PATH
00215 )
00216 endforeach ()
00217
00218 else ()
00219
00220 find_path (
00221 MATLAB_INCLUDE_DIR
00222 NAMES mex.h
00223 HINTS ENV C_INCLUDE_PATH ENV CXX_INCLUDE_PATH
00224 DOC "Include directory for MATLAB libraries."
00225 )
00226
00227 foreach (LIB ${MATLAB_LIBRARY_NAMES})
00228 find_library (
00229 MATLAB_${LIB}_LIBRARY
00230 NAMES ${LIB}
00231 HINTS ENV LD_LIBRARY_PATH
00232 DOC "MATLAB ${LIB} link library."
00233 )
00234 endforeach ()
00235
00236 endif ()
00237
00238 mark_as_advanced (MATLAB_INCLUDE_DIR)
00239 foreach (LIB ${MATLAB_LIBRARY_NAMES})
00240 mark_as_advanced (MATLAB_${LIB}_LIBRARY)
00241 endforeach ()
00242
00243 set (MATLAB_LIBRARY)
00244 foreach (LIB ${MATLAB_LIBRARY_NAMES})
00245 if (MATLAB_${LIB}_LIBRARY)
00246 list (APPEND MATLAB_LIBRARY "${MATLAB_${LIB}_LIBRARY}")
00247 endif ()
00248 endforeach ()
00249
00250 # ----------------------------------------------------------------------------
00251 # prerequisite libraries
00252 set (MATLAB_INCLUDES "${MATLAB_INCLUDE_DIR}")
00253 set (MATLAB_LIBRARIES "${MATLAB_LIBRARY}")
00254
00255 # ----------------------------------------------------------------------------
00256 # aliases / backwards compatibility
00257 set (MATLAB_INCLUDE_DIRS "${MATLAB_INCLUDES}")
00258
00259 # ----------------------------------------------------------------------------
00260 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
00261 # if all listed variables are found or TRUE
00262 include (FindPackageHandleStandardArgs)
00263
00264 set (MATLAB_LIBRARY_VARS)
00265 foreach (LIB ${MATLAB_LIBRARY_NAMES})
00266 list (APPEND MATLAB_LIBRARY_VARS "MATLAB_${LIB}_LIBRARY")
00267 endforeach ()
00268
00269 find_package_handle_standard_args (
00270 MATLAB
00271 # MESSAGE
00272 DEFAULT_MSG
00273 # VARIABLES
00274 MATLAB_EXECUTABLE
00275 MATLAB_INCLUDE_DIR
00276 ${MATLAB_LIBRARY_VARS}
00277 )
00278
00279 # ----------------------------------------------------------------------------
00280 # set MATLAB_DIR
00281 if (NOT MATLAB_DIR AND MATLAB_FOUND)
00282 string (REGEX REPLACE "extern/include/?" "" MATLAB_PREFIX "${MATLAB_INCLUDE_DIR}")
00283 set (MATLAB_DIR "${MATLAB_PREFIX}" CACHE PATH "Installation prefix for MATLAB." FORCE)
00284 unset (MATLAB_PREFIX)
00285 endif ()