chiark / gitweb /
Use trusty
[nlopt.git] / cmake / FindOctave.cmake
1 # - Find Octave
2 # GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
3 # available at http://www.gnu.org/software/octave/
4 #
5 # This module defines: 
6 #  OCTAVE_EXECUTABLE           - octave interpreter
7 #  OCTAVE_INCLUDE_DIRS         - include path for mex.h, mexproto.h
8 #  OCTAVE_LIBRARIES            - required libraries: octinterp, octave, cruft
9 #  OCTAVE_OCTINTERP_LIBRARY    - path to the library octinterp
10 #  OCTAVE_OCTAVE_LIBRARY       - path to the library octave
11 #  OCTAVE_CRUFT_LIBRARY        - path to the library cruft
12 #  OCTAVE_VERSION_STRING       - octave version string
13 #  OCTAVE_MAJOR_VERSION        - major version
14 #  OCTAVE_MINOR_VERSION        - minor version
15 #  OCTAVE_PATCH_VERSION        - patch version
16 #  OCTAVE_OCT_FILE_DIR         - object files that will be dynamically loaded
17 #  OCTAVE_OCT_LIB_DIR          - oct libraries
18 #  OCTAVE_ROOT_DIR             - octave prefix
19 #  OCTAVE_M_SITE_DIR           - .m files site dir
20 #  OCTAVE_OCT_SITE_DIR         - .oct files site dir
21 #
22 # The macro octave_add_oct allows to create compiled modules.
23 # octave_add_oct (target_name
24 #         [SOURCES] source1 [source2 ...]
25 #         [LINK_LIBRARIES  lib1 [lib2 ...]]
26 #         [EXTENSION ext]
27 #)
28 #
29 # To install it, you can the use the variable OCTAVE_OCT_FILE_DIR as follow:
30 #  file (RELATIVE_PATH PKG_OCTAVE_OCT_SITE_DIR ${OCTAVE_ROOT_DIR} ${OCTAVE_OCT_SITE_DIR})
31 #  install (
32 #    TARGETS target_name
33 #    DESTINATION ${PKG_OCTAVE_OCT_SITE_DIR}
34 #)
35
36
37 #=============================================================================
38 # Copyright 2013, Julien Schueller
39 # All rights reserved.
40
41 # Redistribution and use in source and binary forms, with or without
42 # modification, are permitted provided that the following conditions are met: 
43
44 # 1. Redistributions of source code must retain the above copyright notice, this
45 #    list of conditions and the following disclaimer. 
46 # 2. Redistributions in binary form must reproduce the above copyright notice,
47 #    this list of conditions and the following disclaimer in the documentation
48 #    and/or other materials provided with the distribution. 
49 #
50 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
51 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
52 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
54 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
55 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
57 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 # The views and conclusions contained in the software and documentation are those
61 # of the authors and should not be interpreted as representing official policies, 
62 # either expressed or implied, of the FreeBSD Project.
63 #=============================================================================
64
65 find_program(OCTAVE_CONFIG_EXECUTABLE
66               NAMES octave-config
67           )
68
69
70 if (OCTAVE_CONFIG_EXECUTABLE)
71   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p PREFIX
72                     OUTPUT_VARIABLE OCTAVE_ROOT_DIR
73                     OUTPUT_STRIP_TRAILING_WHITESPACE)
74
75   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --m-site-dir
76                     OUTPUT_VARIABLE OCTAVE_M_SITE_DIR
77                     OUTPUT_STRIP_TRAILING_WHITESPACE)
78
79   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --oct-site-dir
80                     OUTPUT_VARIABLE OCTAVE_OCT_SITE_DIR
81                     OUTPUT_STRIP_TRAILING_WHITESPACE)
82
83   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p BINDIR
84                     OUTPUT_VARIABLE OCTAVE_BIN_PATHS
85                     OUTPUT_STRIP_TRAILING_WHITESPACE)
86
87   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR
88                     OUTPUT_VARIABLE OCTAVE_INCLUDE_PATHS
89                     OUTPUT_STRIP_TRAILING_WHITESPACE)
90
91   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR
92                     OUTPUT_VARIABLE OCTAVE_LIBRARIES_PATHS
93                     OUTPUT_STRIP_TRAILING_WHITESPACE)
94
95   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTFILEDIR
96                     OUTPUT_VARIABLE OCTAVE_OCT_FILE_DIR
97                     OUTPUT_STRIP_TRAILING_WHITESPACE)
98
99   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR
100                     OUTPUT_VARIABLE OCTAVE_OCT_LIB_DIR
101                     OUTPUT_STRIP_TRAILING_WHITESPACE)
102
103   execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -v
104                     OUTPUT_VARIABLE OCTAVE_VERSION_STRING
105                     OUTPUT_STRIP_TRAILING_WHITESPACE)
106
107   if (OCTAVE_VERSION_STRING)
108     string (REGEX REPLACE "([0-9]+)\\..*" "\\1" OCTAVE_MAJOR_VERSION ${OCTAVE_VERSION_STRING})
109     string (REGEX REPLACE "[0-9]+\\.([0-9]+).*" "\\1" OCTAVE_MINOR_VERSION ${OCTAVE_VERSION_STRING})
110     string (REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" OCTAVE_PATCH_VERSION ${OCTAVE_VERSION_STRING})
111   endif ()
112 endif ()
113
114
115 find_program(OCTAVE_EXECUTABLE
116               HINTS ${OCTAVE_BIN_PATHS}
117               NAMES octave
118           )
119
120 find_program(OCTAVE_MKOCTFILE
121               HINTS ${OCTAVE_BIN_PATHS}
122               NAMES mkoctfile
123           )
124         
125 find_library(OCTAVE_OCTINTERP_LIBRARY
126               NAMES octinterp liboctinterp
127               HINTS ${OCTAVE_LIBRARIES_PATHS}
128           )
129 find_library(OCTAVE_OCTAVE_LIBRARY
130               NAMES octave liboctave
131               HINTS ${OCTAVE_LIBRARIES_PATHS}
132           )
133 find_library(OCTAVE_CRUFT_LIBRARY
134               NAMES cruft libcruft
135               HINTS ${OCTAVE_LIBRARIES_PATHS}
136           )
137
138 set (OCTAVE_LIBRARIES ${OCTAVE_OCTINTERP_LIBRARY})
139 list (APPEND OCTAVE_LIBRARIES ${OCTAVE_OCTAVE_LIBRARY})
140 if (OCTAVE_CRUFT_LIBRARY)
141   list (APPEND OCTAVE_LIBRARIES ${OCTAVE_CRUFT_LIBRARY})
142 endif ()
143
144 find_path (OCTAVE_INCLUDE_DIR 
145             NAMES octave/oct.h
146             PATHS "${OCTAVE_INCLUDE_PATHS}/.."
147         )
148
149 set (OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR} ${OCTAVE_INCLUDE_DIR}/octave)
150
151
152 macro (octave_add_oct FUNCTIONNAME)
153   set (_CMD SOURCES)
154   set (_SOURCES)
155   set (_LINK_LIBRARIES)
156   set (_EXTENSION)
157   set (_OCT_EXTENSION oct)
158   foreach (_ARG ${ARGN})
159     if (${_ARG} MATCHES SOURCES)
160       set (_CMD SOURCES)
161     elseif (${_ARG} MATCHES LINK_LIBRARIES)
162       set (_CMD LINK_LIBRARIES)
163     elseif (${_ARG} MATCHES EXTENSION)
164       set (_CMD EXTENSION)
165     else ()
166       if (${_CMD} MATCHES SOURCES)
167         list (APPEND _SOURCES "${_ARG}")
168       elseif (${_CMD} MATCHES LINK_LIBRARIES)
169         list (APPEND _LINK_LIBRARIES "${_ARG}")
170       elseif (${_CMD} MATCHES EXTENSION)
171         set (_OCT_EXTENSION ${_ARG})
172       endif ()
173     endif ()
174   endforeach ()
175   add_library (${FUNCTIONNAME} SHARED ${_SOURCES})
176   target_link_libraries (${FUNCTIONNAME} ${OCTAVE_LIBRARIES} ${_LINK_LIBRARIES})
177   set_target_properties (${FUNCTIONNAME} PROPERTIES
178     PREFIX ""
179     SUFFIX  ".${_OCT_EXTENSION}"
180 )
181 endmacro ()
182
183
184 # handle REQUIRED and QUIET options
185 include (FindPackageHandleStandardArgs)
186 if (CMAKE_VERSION LESS 2.8.3)
187   find_package_handle_standard_args (Octave DEFAULT_MSG OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES OCTAVE_VERSION_STRING)
188 else ()
189   find_package_handle_standard_args (Octave REQUIRED_VARS OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES VERSION_VAR OCTAVE_VERSION_STRING)
190 endif ()
191
192
193 mark_as_advanced (
194   OCTAVE_OCT_FILE_DIR
195   OCTAVE_OCT_LIB_DIR
196   OCTAVE_OCTINTERP_LIBRARY
197   OCTAVE_OCTAVE_LIBRARY
198   OCTAVE_CRUFT_LIBRARY
199   OCTAVE_LIBRARIES
200   OCTAVE_INCLUDE_DIR
201   OCTAVE_INCLUDE_DIRS
202   OCTAVE_ROOT_DIR
203   OCTAVE_VERSION_STRING
204   OCTAVE_MAJOR_VERSION
205   OCTAVE_MINOR_VERSION
206   OCTAVE_PATCH_VERSION
207 )
208
209
210