FindSVMTorch.cmake
Go to the documentation of this file.
1 ##############################################################################
2 # @file FindSVMTorch.cmake
3 # @brief Find SVMTorch II package.
4 #
5 # @par Input varibales:
6 # <table border="0">
7 # <tr>
8 # @tp @b SVMTorch_DIR @endtp
9 # <td>The SVMTorch package files are searched primarily under the specified
10 # root directory. This variable can be alternatively set as environment
11 # variable.</td>
12 # </tr>
13 # <tr>
14 # @tp @b SVMTorch_FIND_COMPONENTS @endtp
15 # <td>@c COMPONENTS of SVMTorch to look for: @c train, @c test, @c lib. (default: @c train, @c test)</td>
16 # </tr>
17 # <tr>
18 # @tp @b SVMTorch_FIND_OPTIONAL_COMPONENTS @endtp
19 # <td>@c OPTIONAL_COMPONENTS of SVMTorch to look for: @c train, @c test, @c lib. (default: @c lib)</td>
20 # </tr>
21 # </table>
22 #
23 # @par Output variables:
24 # <table border="0">
25 # <tr>
26 # @tp @b SVMTorch_FOUND @endtp
27 # <td>Whether the package was found and the following CMake variables are valid.</td>
28 # </tr>
29 # <tr>
30 # @tp @b SVMTorch_INCLUDE_DIR @endtp
31 # <td>The directory containing the include files.</td>
32 # </tr>
33 # <tr>
34 # @tp @b SVMTorch_LIBRARY @endtp
35 # <td>Found object files (.o).</td>
36 # </tr>
37 # <tr>
38 # @tp @b SVMTorch_train_EXECUTABLE @endtp
39 # <td>Absolute path of found @c SVMTorch executable.</td>
40 # </tr>
41 # <tr>
42 # @tp @b SVMTorch_test_EXECUTABLE @endtp
43 # <td>Absolute path of found @c SVMTest executable.</td>
44 # </tr>
45 # <tr>
46 # @tp @b svmtorch.SVMTorch @endtp
47 # <td>Import target of @c SVMTorch executable.</td>
48 # </tr>
49 # <tr>
50 # @tp @b svmtorch.SVMTest @endtp
51 # <td>Import target of @c SVMTest executable.</td>
52 # </tr>
53 # </table>
54 #
55 # @ingroup CMakeFindModules
56 ##############################################################################
57 
58 #=============================================================================
59 # Copyright 2011-2012 University of Pennsylvania
60 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com>
61 #
62 # Distributed under the OSI-approved BSD License (the "License");
63 # see accompanying file Copyright.txt for details.
64 #
65 # This software is distributed WITHOUT ANY WARRANTY; without even the
66 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
67 # See the License for more information.
68 #=============================================================================
69 # (To distribute this file outside of CMake, substitute the full
70 # License text for the above reference.)
71 
72 # ----------------------------------------------------------------------------
73 # initialize search
74 if (NOT SVMTorch_DIR)
75  set (SVMTorch_DIR "$ENV{SVMTorch_DIR}" CACHE PATH "Installation prefix of SVMTorch." FORCE)
76 endif ()
77 
79  set (SVMTorch_FIND_COMPONENTS train test)
80  set (SVMTorch_FIND_OPTIONAL_COMPONENTS lib)
81 endif ()
82 
83 set (_SVMTorch_COMPONENTS ${SVMTorch_FIND_COMPONENTS} ${SVMTorch_FIND_OPTIONAL_COMPONENTS})
84 
85 foreach (_SVMTorch_C IN LISTS _SVMTorch_COMPONENTS)
86  if (NOT _SVMTorch_C MATCHES "^(train|test|lib)$")
87  message (FATAL_ERROR "Invalid SVMTorch component: ${_SVMTorch_C}")
88  endif ()
89 endforeach ()
90 unset (_SVMTorch_C)
91 
92 #--------------------------------------------------------------
93 # find executables
94 if (_SVMTorch_COMPONENTS MATCHES train)
95  if (SVMTorch_DIR)
96  find_program (
97  SVMTorch_train_EXECUTABLE
98  NAMES SVMTorch
99  HINTS ${SVMTorch_DIR}
100  DOC "The SVMTorch executable."
101  NO_DEFAULT_PATH
102  )
103  else ()
104  find_program (
105  SVMTorch_train_EXECUTABLE
106  NAMES SVMTorch
107  DOC "The SVMTorch executable."
108  )
109  endif ()
110  mark_as_advanced (SVMTorch_train_EXECUTABLE)
111  if (SVMTorch_train_EXECUTABLE)
112  add_executable (svmtorch.SVMTorch IMPORTED)
113  set_target_properties (svmtorch.SVMTorch PROPERTIES IMPORTED_LOCATION "${SVMTorch_train_EXECUTABLE}")
114  endif ()
115 endif ()
116 
117 if (_SVMTorch_COMPONENTS MATCHES test)
118  if (SVMTorch_DIR)
119  find_program (
120  SVMTorch_test_EXECUTABLE
121  NAMES SVMTest
122  HINTS ${SVMTorch_DIR}
123  DOC "The SVMTest executable."
124  NO_DEFAULT_PATH
125  )
126  else ()
127  find_program (
128  SVMTorch_test_EXECUTABLE
129  NAMES SVMTest
130  DOC "The SVMTest executable."
131  )
132  endif ()
133  mark_as_advanced (SVMTorch_test_EXECUTABLE)
134  if (SVMTorch_test_EXECUTABLE)
135  add_executable (svmtorch.SVMTest IMPORTED)
136  set_target_properties (svmtorch.SVMTest PROPERTIES IMPORTED_LOCATION "${SVMTorch_test_EXECUTABLE}")
137  endif ()
138 endif ()
139 
140 #--------------------------------------------------------------
141 # derive SVMTorch_DIR if not set yet
142 if (NOT SVMTorch_DIR)
143  if (SVMTorch_train_EXECUTABLE)
144  get_filename_component (SVMTorch_DIR "${SVMTorch_train_EXECUTABLE}" PATH)
145  elseif (SVMTorch_test_EXECUTABLE)
146  get_filename_component (SVMTorch_DIR "${SVMTorch_test_EXECUTABLE}" PATH)
147  endif ()
148  set (SVMTorch_DIR "${SVMTorch_DIR}" CACHE PATH "Installation prefix of SVMTorch." FORCE)
149 endif ()
150 
151 #--------------------------------------------------------------
152 # find header files and built object files
153 set (SVMTorch_LIBRARY)
154 if (_SVMTorch_COMPONENTS MATCHES lib)
155  if (SVMTorch_DIR)
156  find_path (
157  SVMTorch_INCLUDE_DIR
158  NAMES IOTorch.h
159  HINTS "${SVMTorch_DIR}"
160  DOC "Directory containing the header files of SVMTorch (i.e., IOTorch.h)."
161  NO_DEFAULT_PATH
162  )
163  file (GLOB SVMTorch_OBJ_FILES "${SVMTorch_DIR}/*.o")
164  foreach (_SVMTorch_OBJ_FILE IN LISTS SVMTorch_OBJ_FILES)
165  if (NOT _SVMTorch_OBJ_FILE MATCHES "convert.o$|SVMTorch.o$|SVMTest.o$")
166  list (APPEND SVMTorch_LIBRARY "${_SVMTorch_OBJ_FILE}")
167  endif ()
168  endforeach ()
169  unset (_SVMTorch_OBJ_FILE)
170  mark_as_advanced (SVMTorch_INCLUDE_DIR)
171  else ()
172  find_path (
173  SVMTorch_INCLUDE_DIR
174  NAMES IOTorch.h
175  DOC "Directory containing the header files of SVMTorch (i.e., IOTorch.h)."
176  )
177  mark_as_advanced (SVMTorch_INCLUDE_DIR)
178  endif ()
179 endif ()
180 
181 # ----------------------------------------------------------------------------
182 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
183 # if all listed variables are found or TRUE
184 include (FindPackageHandleStandardArgs)
185 
186 set (SVMTorch_REQUIRED_VARS)
187 if (SVMTorch_FIND_COMPONENTS MATCHES train)
188  list (APPEND SVMTorch_REQUIRED_VARS SVMTorch_train_EXECUTABLE)
189 endif ()
190 if (SVMTorch_FIND_COMPONENTS MATCHES test)
191  list (APPEND SVMTorch_REQUIRED_VARS SVMTorch_test_EXECUTABLE)
192 endif ()
193 if (SVMTorch_FIND_COMPONENTS MATCHES lib)
194  list (APPEND SVMTorch_REQUIRED_VARS SVMTorch_INCLUDE_DIR)
195  list (APPEND SVMTorch_REQUIRED_VARS SVMTorch_LIBRARY)
196 endif ()
197 
198 find_package_handle_standard_args (SVMTorch DEFAULT_MSG ${SVMTorch_REQUIRED_VARS})
199 
200 
201 unset (_SVMTorch_COMPONENTS)
function set_target_properties(in ARGN)
Set target property.
cmake SVMTorch_FIND_OPTIONAL_COMPONENTS
cmake SVMTorch_DIR
function add_executable(in TARGET_UID, in ARGN)
Add executable target.
cmake _SVMTorch_COMPONENTS
cmake SVMTorch_FIND_COMPONENTS
function get_filename_component(inout ARGN)
Fixes CMake&#39;s get_filename_component() command.