root/library/system/FindMatlab.cmake @ 621

Revision 592, 4.7 kB (checked in by smidl, 15 years ago)

extend paths where matlab is sought

  • Property svn:eol-style set to native
Line 
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
15SET(MATLAB_FOUND 0)
16
17IF(WIN32)
18
19  FILE(GLOB _auto_matlab_prefixes "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
55ELSE(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
67  IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
68    # Regular x86
69    SET(_matlab_path_suffixes "bin/glnx86")
70    SET(MATLAB_MEX_SUFFIX mexglx)
71  ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4)
72    SET(_matlab_path_suffixes "bin/glnxa64")
73    SET(MATLAB_MEX_SUFFIX mexa64)
74  ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)
75
76  SET(_libmex_name "mex")
77  SET(_libmx_name "mx")
78  SET(_libeng_name "eng")
79
80ENDIF(WIN32)
81
82
83SET(_matlab_path_prefixes
84  ${MATLAB_PATH_PREFIXES}
85  ${_auto_matlab_prefixes}
86  ${MATLAB_ROOT}
87)
88
89# Search for include-files & libraries using architecture-dependent paths:
90FOREACH(_matlab_prefix ${_matlab_path_prefixes})
91  MESSAGE("searching ${_matlab_prefix}")
92  IF(NOT MATLAB_INCLUDE_DIR)
93    FIND_PATH(MATLAB_INCLUDE_DIR "mex.h"
94      ${_matlab_prefix}/extern/include)
95
96    IF(MATLAB_INCLUDE_DIR)
97      SET(MATLAB_ROOT ${_matlab_prefix}
98        CACHE PATH "Matlab installation directory")
99      IF(WIN32)
100        SET(MATLAB_MEX_VERSIONFILE "${_matlab_prefix}/extern/include/mexversion.rc")
101      ELSE(WIN32)
102        SET(MATLAB_MEX_VERSIONFILE "${_matlab_prefix}/extern/src/mexversion.c")
103      ENDIF(WIN32)
104    ENDIF(MATLAB_INCLUDE_DIR)
105  ENDIF(NOT MATLAB_INCLUDE_DIR)
106
107  FOREACH(_matlab_path_suffix ${_matlab_path_suffixes})
108    SET(_matlab_libdir ${_matlab_prefix}/${_matlab_path_suffix})
109    MESSAGE("Searching ${_matlab_prefix} ... ${_matlab_libdir}")
110    IF(NOT MATLAB_MEX_LIBRARY)
111      FIND_LIBRARY(MATLAB_MEX_LIBRARY ${_libmex_name} ${_matlab_libdir})
112      FIND_LIBRARY(MATLAB_MX_LIBRARY ${_libmx_name} ${_matlab_libdir})
113      FIND_LIBRARY(MATLAB_ENG_LIBRARY ${_libeng_name} ${_matlab_libdir})
114    ENDIF(NOT MATLAB_MEX_LIBRARY)
115  ENDFOREACH(_matlab_path_suffix)
116ENDFOREACH(_matlab_prefix)
117
118SET(MATLAB_LIBRARIES
119  ${MATLAB_MEX_LIBRARY}
120  ${MATLAB_MX_LIBRARY}
121  ${MATLAB_ENG_LIBRARY}
122)
123
124IF(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES)
125  SET(MATLAB_FOUND 1)
126  MESSAGE(STATUS "Found Matlab arch ${MATLAB_MEX_SUFFIX} at ${MATLAB_INCLUDE_DIR}")
127ELSE(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES)
128  MESSAGE(STATUS "Matlab not found")
129ENDIF(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES)
130
131MARK_AS_ADVANCED(
132  MATLAB_LIBRARIES
133  MATLAB_MEX_LIBRARY
134  MATLAB_MX_LIBRARY
135  MATLAB_ENG_LIBRARY
136  MATLAB_INCLUDE_DIR
137  MATLAB_MEX_SUFFIX
138  MATLAB_MEX_VERSIONFILE
139  MATLAB_FOUND
140)
141
142# vim: set ts=2 sw=2 et:
Note: See TracBrowser for help on using the browser.