2 # GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
3 # available at http://www.gnu.org/software/octave/
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
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 ...]]
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})
33 # DESTINATION ${PKG_OCTAVE_OCT_SITE_DIR}
37 #=============================================================================
38 # Copyright 2013, Julien Schueller
39 # All rights reserved.
41 # Redistribution and use in source and binary forms, with or without
42 # modification, are permitted provided that the following conditions are met:
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.
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 #=============================================================================
65 find_program(OCTAVE_CONFIG_EXECUTABLE
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)
75 execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --m-site-dir
76 OUTPUT_VARIABLE OCTAVE_M_SITE_DIR
77 OUTPUT_STRIP_TRAILING_WHITESPACE)
79 execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} --oct-site-dir
80 OUTPUT_VARIABLE OCTAVE_OCT_SITE_DIR
81 OUTPUT_STRIP_TRAILING_WHITESPACE)
83 execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p BINDIR
84 OUTPUT_VARIABLE OCTAVE_BIN_PATHS
85 OUTPUT_STRIP_TRAILING_WHITESPACE)
87 execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTINCLUDEDIR
88 OUTPUT_VARIABLE OCTAVE_INCLUDE_PATHS
89 OUTPUT_STRIP_TRAILING_WHITESPACE)
91 execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR
92 OUTPUT_VARIABLE OCTAVE_LIBRARIES_PATHS
93 OUTPUT_STRIP_TRAILING_WHITESPACE)
95 execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTFILEDIR
96 OUTPUT_VARIABLE OCTAVE_OCT_FILE_DIR
97 OUTPUT_STRIP_TRAILING_WHITESPACE)
99 execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -p OCTLIBDIR
100 OUTPUT_VARIABLE OCTAVE_OCT_LIB_DIR
101 OUTPUT_STRIP_TRAILING_WHITESPACE)
103 execute_process (COMMAND ${OCTAVE_CONFIG_EXECUTABLE} -v
104 OUTPUT_VARIABLE OCTAVE_VERSION_STRING
105 OUTPUT_STRIP_TRAILING_WHITESPACE)
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})
115 find_program(OCTAVE_EXECUTABLE
116 HINTS ${OCTAVE_BIN_PATHS}
120 find_program(OCTAVE_MKOCTFILE
121 HINTS ${OCTAVE_BIN_PATHS}
125 find_library(OCTAVE_OCTINTERP_LIBRARY
126 NAMES octinterp liboctinterp
127 HINTS ${OCTAVE_LIBRARIES_PATHS}
129 find_library(OCTAVE_OCTAVE_LIBRARY
130 NAMES octave liboctave
131 HINTS ${OCTAVE_LIBRARIES_PATHS}
133 find_library(OCTAVE_CRUFT_LIBRARY
135 HINTS ${OCTAVE_LIBRARIES_PATHS}
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})
144 find_path (OCTAVE_INCLUDE_DIR
146 PATHS "${OCTAVE_INCLUDE_PATHS}/.."
149 set (OCTAVE_INCLUDE_DIRS ${OCTAVE_INCLUDE_DIR} ${OCTAVE_INCLUDE_DIR}/octave)
152 macro (octave_add_oct FUNCTIONNAME)
155 set (_LINK_LIBRARIES)
157 set (_OCT_EXTENSION oct)
158 foreach (_ARG ${ARGN})
159 if (${_ARG} MATCHES SOURCES)
161 elseif (${_ARG} MATCHES LINK_LIBRARIES)
162 set (_CMD LINK_LIBRARIES)
163 elseif (${_ARG} MATCHES EXTENSION)
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})
175 add_library (${FUNCTIONNAME} SHARED ${_SOURCES})
176 target_link_libraries (${FUNCTIONNAME} ${OCTAVE_LIBRARIES} ${_LINK_LIBRARIES})
177 set_target_properties (${FUNCTIONNAME} PROPERTIES
179 SUFFIX ".${_OCT_EXTENSION}"
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)
189 find_package_handle_standard_args (Octave REQUIRED_VARS OCTAVE_EXECUTABLE OCTAVE_ROOT_DIR OCTAVE_INCLUDE_DIRS OCTAVE_LIBRARIES VERSION_VAR OCTAVE_VERSION_STRING)
196 OCTAVE_OCTINTERP_LIBRARY
197 OCTAVE_OCTAVE_LIBRARY
203 OCTAVE_VERSION_STRING