1 | # - This module looks for Matlab and associated development libraries |
---|
2 | # Defines: |
---|
3 | # MATLAB_INCLUDE_DIR: include path for mex.h, engine.h |
---|
4 | # MATLAB_LIBRARIES: required libraries: libmex, etc |
---|
5 | # MATLAB_MEX_LIBRARY: path to libmex.lib |
---|
6 | # MATLAB_MX_LIBRARY: path to libmx.lib |
---|
7 | # MATLAB_ENG_LIBRARY: path to libeng.lib |
---|
8 | # MATLAB_MEX_VERSION_FILE: path to mexversion.rc or mexversion.c |
---|
9 | # MATLAB_MEX_SUFFIX: filename suffix for mex-files (e.g. '.mexglx' or '.mexw64') |
---|
10 | |
---|
11 | # This version modified by RW Penney, November 2008 |
---|
12 | # $Revision: 27 $, $Date: 2008-12-22 11:47:45 +0000 (Mon, 22 Dec 2008) $ |
---|
13 | |
---|
14 | |
---|
15 | SET(MATLAB_FOUND 0) |
---|
16 | |
---|
17 | IF(WIN32) |
---|
18 | |
---|
19 | FILE(GLOB _auto_matlab_prefixes "C:/Program Files/MATLAB*" "C:/Program Files/MATLAB*/R20*" "D:/Program Files/MATLAB*/R20*" "C:/Devel/MATLAB*/R20*") # used machines Aug 2009 |
---|
20 | |
---|
21 | IF(CMAKE_SIZEOF_VOID_P EQUAL 4) |
---|
22 | # Regular x86 |
---|
23 | SET(MATLAB_MEX_SUFFIX mexw32) |
---|
24 | SET(_extern_arch "win32") |
---|
25 | ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4) |
---|
26 | SET(MATLAB_MEX_SUFFIX mexw64) |
---|
27 | SET(_extern_arch "win64") |
---|
28 | ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4) |
---|
29 | |
---|
30 | # Search for available compilers: |
---|
31 | # (This would be neater using 'ELSEIF', but that isn't available until cmake-2.4.4) |
---|
32 | IF(${CMAKE_GENERATOR} MATCHES "Visual Studio 6") |
---|
33 | SET(_matlab_path_suffixes "extern/lib/${_extern_arch}/microsoft/msvc60" |
---|
34 | "extern/lib/${_extern_arch}/microsoft") |
---|
35 | ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio 6") |
---|
36 | IF(${CMAKE_GENERATOR} MATCHES "Visual Studio 7") |
---|
37 | SET(_matlab_path_suffixes "extern/lib/${_extern_arch}/microsoft/msvc70" |
---|
38 | "extern/lib/${_extern_arch}/microsoft") |
---|
39 | ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio 7") |
---|
40 | IF(${CMAKE_GENERATOR} MATCHES "Visual Studio [891]*") |
---|
41 | SET(_matlab_path_suffixes "extern/lib/${_extern_arch}/microsoft/msvc71" |
---|
42 | "extern/lib/${_extern_arch}/microsoft") |
---|
43 | ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio [891]*") |
---|
44 | IF(${CMAKE_GENERATOR} MATCHES "Borland") |
---|
45 | SET(_matlab_path_suffixes "extern/lib/win32/microsoft/bcc54") |
---|
46 | ENDIF(${CMAKE_GENERATOR} MATCHES "Borland") |
---|
47 | IF(NOT _matlab_path_suffixes) |
---|
48 | MESSAGE(FATAL_ERROR "Generator not compatible: ${CMAKE_GENERATOR}") |
---|
49 | ENDIF(NOT _matlab_path_suffixes) |
---|
50 | |
---|
51 | SET(_libmex_name "libmex") |
---|
52 | SET(_libmx_name "libmx") |
---|
53 | SET(_libeng_name "libeng") |
---|
54 | |
---|
55 | ELSE(WIN32) |
---|
56 | |
---|
57 | IF(NOT MATLAB_ROOT) |
---|
58 | IF($ENV{MATLAB_ROOT}) |
---|
59 | SET(MATLAB_ROOT $ENV{MATLAB_ROOT}) |
---|
60 | ELSE($ENV{MATLAB_ROOT}) |
---|
61 | SET(MATLAB_ROOT "$ENV{HOME}/bin/matlab*") |
---|
62 | ENDIF($ENV{MATLAB_ROOT}) |
---|
63 | ENDIF(NOT MATLAB_ROOT) |
---|
64 | |
---|
65 | FILE(GLOB _auto_matlab_prefixes "/usr/local/matlab*" "/opt/matlab*" "~/bin" ${MATLAB_ROOT}) |
---|
66 | IF(APPLE) |
---|
67 | FILE(GLOB _auto_matlab_prefixes "/Applications/MATLAB*") |
---|
68 | ENDIF(APPLE) |
---|
69 | |
---|
70 | IF(CMAKE_SIZEOF_VOID_P EQUAL 4) |
---|
71 | # Regular x86 |
---|
72 | SET(_matlab_path_suffixes "bin/glnx86") |
---|
73 | SET(MATLAB_MEX_SUFFIX mexglx) |
---|
74 | ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4) |
---|
75 | SET(_matlab_path_suffixes "bin/glnxa64") |
---|
76 | SET(MATLAB_MEX_SUFFIX mexa64) |
---|
77 | ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4) |
---|
78 | |
---|
79 | IF(APPLE) |
---|
80 | SET(_matlab_path_suffixes "bin/maci") |
---|
81 | SET(MATLAB_MEX_SUFFIX mexmaci) |
---|
82 | ENDIF(APPLE) |
---|
83 | |
---|
84 | SET(_libmex_name "mex") |
---|
85 | SET(_libmx_name "mx") |
---|
86 | SET(_libeng_name "eng") |
---|
87 | |
---|
88 | ENDIF(WIN32) |
---|
89 | |
---|
90 | |
---|
91 | SET(_matlab_path_prefixes |
---|
92 | ${MATLAB_PATH_PREFIXES} |
---|
93 | ${_auto_matlab_prefixes} |
---|
94 | ${MATLAB_ROOT} |
---|
95 | ) |
---|
96 | |
---|
97 | # Search for include-files & libraries using architecture-dependent paths: |
---|
98 | FOREACH(_matlab_prefix ${_matlab_path_prefixes}) |
---|
99 | MESSAGE("searching ${_matlab_prefix}") |
---|
100 | IF(NOT MATLAB_INCLUDE_DIR) |
---|
101 | FIND_PATH(MATLAB_INCLUDE_DIR "mex.h" |
---|
102 | ${_matlab_prefix}/extern/include) |
---|
103 | |
---|
104 | IF(MATLAB_INCLUDE_DIR) |
---|
105 | SET(MATLAB_ROOT ${_matlab_prefix} |
---|
106 | CACHE PATH "Matlab installation directory") |
---|
107 | IF(WIN32) |
---|
108 | SET(MATLAB_MEX_VERSIONFILE "${_matlab_prefix}/extern/include/mexversion.rc") |
---|
109 | ELSE(WIN32) |
---|
110 | SET(MATLAB_MEX_VERSIONFILE "${_matlab_prefix}/extern/src/mexversion.c") |
---|
111 | ENDIF(WIN32) |
---|
112 | ENDIF(MATLAB_INCLUDE_DIR) |
---|
113 | ENDIF(NOT MATLAB_INCLUDE_DIR) |
---|
114 | |
---|
115 | FOREACH(_matlab_path_suffix ${_matlab_path_suffixes}) |
---|
116 | SET(_matlab_libdir ${_matlab_prefix}/${_matlab_path_suffix}) |
---|
117 | MESSAGE("Searching ${_matlab_prefix} ... ${_matlab_libdir}") |
---|
118 | IF(NOT MATLAB_MEX_LIBRARY) |
---|
119 | FIND_LIBRARY(MATLAB_MEX_LIBRARY ${_libmex_name} ${_matlab_libdir}) |
---|
120 | FIND_LIBRARY(MATLAB_MX_LIBRARY ${_libmx_name} ${_matlab_libdir}) |
---|
121 | FIND_LIBRARY(MATLAB_ENG_LIBRARY ${_libeng_name} ${_matlab_libdir}) |
---|
122 | ENDIF(NOT MATLAB_MEX_LIBRARY) |
---|
123 | ENDFOREACH(_matlab_path_suffix) |
---|
124 | ENDFOREACH(_matlab_prefix) |
---|
125 | |
---|
126 | # APPLE has system libmx.dylib which is prefrred over the matlab one -- hard code Matlab |
---|
127 | IF(APPLE) |
---|
128 | SET(MATLAB_MX_LIBRARY "${_matlab_libdir}/libmx.dylib") |
---|
129 | ENDIF(APPLE) |
---|
130 | |
---|
131 | SET(MATLAB_LIBRARIES |
---|
132 | ${MATLAB_MEX_LIBRARY} |
---|
133 | ${MATLAB_MX_LIBRARY} |
---|
134 | ${MATLAB_ENG_LIBRARY} |
---|
135 | ) |
---|
136 | |
---|
137 | IF(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES) |
---|
138 | SET(MATLAB_FOUND 1) |
---|
139 | MESSAGE(STATUS "Found Matlab arch ${MATLAB_MEX_SUFFIX} at ${MATLAB_INCLUDE_DIR}") |
---|
140 | IF(APPLE) |
---|
141 | MESSAGE(STATUS "MX at ${MATLAB_MX_LIBRARY}") |
---|
142 | ENDIF(APPLE) |
---|
143 | |
---|
144 | ELSE(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES) |
---|
145 | MESSAGE(STATUS "Matlab not found") |
---|
146 | ENDIF(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES) |
---|
147 | |
---|
148 | MARK_AS_ADVANCED( |
---|
149 | MATLAB_LIBRARIES |
---|
150 | MATLAB_MEX_LIBRARY |
---|
151 | MATLAB_MX_LIBRARY |
---|
152 | MATLAB_ENG_LIBRARY |
---|
153 | MATLAB_INCLUDE_DIR |
---|
154 | MATLAB_MEX_SUFFIX |
---|
155 | MATLAB_MEX_VERSIONFILE |
---|
156 | MATLAB_FOUND |
---|
157 | ) |
---|
158 | |
---|
159 | # vim: set ts=2 sw=2 et: |
---|