1 ############################################################################## 3 # @brief Find Weka (http://www.cs.waikato.ac.nz/ml/weka/) package. 5 # @par Input variables: 8 # @tp @b Weka_DIR @endtp 9 # <td>The Weka package files are searched under the specified root 10 # directory. If they are not found there, the default search paths 11 # are considered. This variable can also be set as environment variable.</td> 14 # @tp @b WEKA_DIR @endtp 15 # <td>Alternative environment variable for @c Weka_DIR.</td> 18 # @tp @b Weka_PACKAGES_DIR @endtp 19 # <td>Directory where additional Weka packages are installed. If they are 20 # not found there or if this variable is not set, this module will look 21 # in the standard installation directories. This variable can also be set 22 # as environment variable.</td> 25 # @tp @b WEKA_PACKAGES_DIR @endtp 26 # <td>Alternative environment variable for @c Weka_PACKAGES_DIR.</td> 29 # @tp <b>Weka_<package>_DIR</b> @endtp 30 # <td>The path of the given Weka package, i.e., the directory containing the 31 # <tt><package>.jar</tt> file or a subdirectory named <tt>weka</tt> 32 # with the uncompressed <tt>.class</tt> files of the package.</td> 35 # @tp @b Weka_FIND_COMPONENTS @endtp 36 # <td>The @c COMPONENTS argument(s) of the find_package() command can 37 # be used to also look for additionally installed Weka packages.</td> 40 # @tp @b Weka_FIND_OPTIONAL_COMPONENTS @endtp 41 # <td>The @c OPTIONAL_COMPONENTS argument(s) of the find_package() command can 42 # be used to also look for additionally installed Weka packages.</td> 45 # @tp @b Weka_ADDITIONAL_VERSIONS @endtp 46 # <td>List of version numbers that should be taken into account when 47 # searching for Weka.</td> 51 # @par Output variables: 54 # @tp @b Weka_FOUND @endtp 55 # <td>Whether the package was found and the following CMake variables are valid.</td> 58 # @tp @b Weka_HAS_PACKAGE_MANAGER @endtp 59 # <td>Whether the found version of Weka has a package manager.</td> 62 # @tp @b Weka_CLASSPATH @endtp 63 # <td>The path of the found <tt>weka.jar</tt> file.</td> 66 # @tp @b Weka_PACKAGES_CLASSPATH @endtp 67 # <td>The @c CLASSPATH of all found additional Weka packages (non-cached).</td> 70 # @tp @b Weka_CLASSPATHS @endtp 71 # <td>Combination of both @c Weka_CLASSPATH and @c Weka_PACKAGES_CLASSPATH.</td> 75 # @ingroup CMakeFindModules 76 ############################################################################## 78 #============================================================================= 79 # Copyright 2011-2012 University of Pennsylvania 80 # Copyright 2013-2016 Andreas Schuh <andreas.schuh.84@gmail.com> 82 # Distributed under the OSI-approved BSD License (the "License"); 83 # see accompanying file Copyright.txt for details. 85 # This software is distributed WITHOUT ANY WARRANTY; without even the 86 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 87 # See the License for more information. 88 #============================================================================= 89 # (To distribute this file outside of CMake, substitute the full 90 # License text for the above reference.) 92 # ============================================================================ 94 # ============================================================================ 96 # ---------------------------------------------------------------------------- 97 # @brief Determine if this Weka version has a package manager. 99 # @returns This macro sets the Weka_HAS_PACKAGE_MANAGER variable. 101 if (Weka_VERSION_MAJOR AND Weka_VERSION_MINOR)
102 if (Weka_VERSION_MAJOR EQUAL 3)
103 if (Weka_VERSION_MINOR GREATER 7 OR (Weka_VERSION_MINOR EQUAL 7 AND Weka_VERSION_PATCH GREATER 1))
104 set (Weka_HAS_PACKAGE_MANAGER TRUE)
106 set (Weka_HAS_PACKAGE_MANAGER FALSE)
108 elseif (Weka_VERSION_MAJOR GREATER 2)
109 set (Weka_HAS_PACKAGE_MANAGER TRUE)
111 set (Weka_HAS_PACKAGE_MANAGER FALSE)
114 set (Weka_HAS_PACKAGE_MANAGER TRUE)
118 # ---------------------------------------------------------------------------- 119 ## @brief Get list of Weka packages. 121 # @param [out] PACKAGES Name of variable storing the list of packages. 122 # @param [in] WHICH Argument to -list-packages option of Weka package 123 # manager, i.e., "all", "available", or "installed". 125 string (TOLOWER
"${WHICH}" WHICH) # ignore
case of argument
127 if (NOT JAVA_EXECUTABLE)
128 set (JAVA_EXECUTABLE java)
130 if (Weka_VERSION_MAJOR AND Weka_VERSION_MINOR)
131 if (Weka_VERSION_MAJOR EQUAL 3)
132 if (Weka_VERSION_MINOR GREATER 7 OR (Weka_VERSION_MINOR EQUAL 7 AND Weka_VERSION_PATCH GREATER 1))
133 set (HAS_PACKAGE_MANAGER TRUE)
135 set (HAS_PACKAGE_MANAGER FALSE)
137 elseif (Weka_VERSION_MAJOR GREATER 2)
138 set (HAS_PACKAGE_MANAGER TRUE)
140 set (HAS_PACKAGE_MANAGER FALSE)
143 set (HAS_PACKAGE_MANAGER TRUE)
145 if (HAS_PACKAGE_MANAGER)
149 -classpath
"${Weka_CLASSPATH}" 150 weka.core.WekaPackageManager
151 -list-packages
"${WHICH}" 152 RESULT_VARIABLE STATUS
157 string (REPLACE
";" "," STDOUT "${STDOUT}")
158 string (REPLACE
"\n" ";" STDOUT "${STDOUT}")
159 foreach (LINE IN LISTS
STDOUT)
160 if (LINE MATCHES
"^(-+|[0-9]+(\\.[0-9]+(\\.[0-9]+)))[ \t]+[0-9]+(\\.[0-9]+(\\.[0-9]+))[ \t]+([a-zA-Z_-]+):")
161 list (APPEND PKGS
"${CMAKE_MATCH_6}")
165 message (WARNING "Failed to retrieve list of ${WHICH} Weka packages! The command\n
" 166 "\
"${JAVA_EXECUTABLE}\" -classpath \"${Weka_CLASSPATH}\" weka.core.WekaPackageManager -list-packages ${WHICH}\n" 167 "failed with the error:\n${STDERR}")
170 message (WARNING "Cannot retrieve list of Weka packages because Weka_CLASSPATH
is not set!")
173 set (${PACKAGES}
"${PKGS}" PARENT_SCOPE)
176 # ---------------------------------------------------------------------------- 177 ## @brief Get Weka version. 179 # @param [out] VERSION Version string of Weka or 0.0.0. 180 # @param [out] MAJOR Major version of Weka or 0. 181 # @param [out] MINOR Minor version of Weka or 0. 182 # @param [out] PATCH Patch number of Weka or 0. 184 set (VERSION_STRING
"0.0.0")
188 if (NOT JAVA_EXECUTABLE)
189 set (JAVA_EXECUTABLE java)
193 COMMAND "${JAVA_EXECUTABLE}" -classpath
"${Weka_CLASSPATH}" weka.core.Version
195 OUTPUT_VARIABLE STDOUT
198 if (STDOUT MATCHES
"^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
199 set (VERSION_STRING
"${CMAKE_MATCH_0}")
204 message (WARNING
"Failed to version of Weka installation. The command\n" 205 "\"${JAVA_EXECUTABLE}\" -classpath \"${Weka_CLASSPATH}\" weka.core.Version\n" 206 "failed with the error:\n${STDERR}")
209 set (${
VERSION}
"${VERSION_STRING}" PARENT_SCOPE)
210 set (${MAJOR}
"${VERSION_MAJOR}" PARENT_SCOPE)
211 set (${MINOR}
"${VERSION_MINOR}" PARENT_SCOPE)
212 set (${PATCH}
"${VERSION_PATCH}" PARENT_SCOPE)
215 # ============================================================================ 217 # ============================================================================ 219 # ---------------------------------------------------------------------------- 222 if (NOT $ENV{WEKAHOME} STREQUAL
"")
223 set (Weka_DIR
"$ENV{WEKAHOME}" CACHE PATH
"Installation directory of Weka." FORCE)
224 elseif (NOT $ENV{Weka_DIR} STREQUAL
"")
225 set (Weka_DIR
"$ENV{Weka_DIR}" CACHE PATH
"Installation directory of Weka." FORCE)
227 set (Weka_DIR
"$ENV{WEKA_DIR}" CACHE PATH
"Installation directory of Weka." FORCE)
232 if (CMAKE_HOST_APPLE)
233 # TODO seach /Applications/weka-3-7-6.app/Contents and 234 # $ENV{HOME}/Applications/weka-3-7-6.app/Contents 235 # directories for all requested/known Weka versions 237 string (REPLACE
":" ";" Weka_ENV_CLASSPATH
"$ENV{CLASSPATH}")
238 foreach (Weka_CLSDIR IN LISTS Weka_ENV_CLASSPATH)
239 if (Weka_CLSDIR MATCHES
"\\.jar")
242 list (APPEND Weka_HINTS
"${Weka_CLSDIR}")
244 unset (Weka_ENV_CLASSPATH)
246 #----------------------------------------------------------------------------- 249 if (Weka_CLASSPATH AND NOT Weka_CLASSPATH MATCHES
"^${Weka_DIR}/")
250 set_property (CACHE Weka_CLASSPATH PROPERTY
VALUE "Weka_CLASSPATH-NOTFOUND")
258 "Contents/Resources/Java" 260 DOC
"The Java library of the Weka package (weka.jar)." 269 "Contents/Resources/Java" 271 DOC
"The Java library of the Weka package (weka.jar)." 275 if (EXISTS
"${Weka_DIR}/../WekaManual.pdf") # weka.jar
is in weka/ subdirectory
277 elseif (Weka_DIR MATCHES
"/Contents/Resources/Java$")
278 string (REGEX REPLACE
"/Contents/Resources/Java$" "" Weka_DIR
"${Weka_DIR}")
280 set (Weka_DIR
"${Weka_DIR}" CACHE PATH
"Installation directory of Weka." FORCE)
283 mark_as_advanced (Weka_CLASSPATH)
285 #------------------------------------------------------------- 286 # determine Weka version 287 weka_get_version (Weka_VERSION_STRING Weka_VERSION_MAJOR Weka_VERSION_MINOR Weka_VERSION_PATCH)
290 #------------------------------------------------------------- 292 if (Weka_HAS_PACKAGE_MANAGER)
294 if (IS_DIRECTORY
"${Weka_DIR}/packages")
295 set (
Weka_PACKAGES_DIR "${Weka_DIR}/packages" CACHE PATH
"Installation directory of Weka packages." FORCE)
296 elseif (IS_DIRECTORY
"$ENV{HOME}/wekafiles/packages")
297 set (
Weka_PACKAGES_DIR "$ENV{HOME}/wekafiles/packages" CACHE PATH
"Installation directory of Weka packages." FORCE)
300 set (Weka_REQUIRED_PACKAGE_VARS)
301 if (Weka_FIND_COMPONENTS)
302 foreach (Weka_PKG IN LISTS Weka_FIND_COMPONENTS)
303 list (APPEND Weka_REQUIRED_PACKAGE_VARS "Weka_${Weka_PKG}_DIR
") 305 elseif (Weka_CLASSPATH) 306 weka_list_packages (Weka_FIND_COMPONENTS installed) 308 foreach (Weka_PKG IN LISTS Weka_FIND_COMPONENTS Weka_FIND_OPTIONAL_COMPONENTS) 309 set (Weka_${Weka_PKG}_DIR "Weka_${Weka_PKG}_DIR-NOTFOUND
" CACHE PATH "Directory of ${Weka_PKG} Weka package.
" FORCE) 310 mark_as_advanced (Weka_${Weka_PKG}_DIR) 313 set (Weka_${Weka_PKG}_CLASSPATH "${
Weka_PACKAGES_DIR}/${Weka_PKG}/${Weka_PKG}.jar
") 320 if (Weka_${Weka_PKG}_CLASSPATH) 321 list (APPEND Weka_PACKAGES_CLASSPATH "${Weka_${Weka_PKG}_CLASSPATH}
") 322 set (Weka_${Weka_PKG}_DIR "${
Weka_PACKAGES_DIR}/${Weka_PKG}
" CACHE PATH "Directory of ${Weka_PKG} Weka package.
" FORCE) 327 if (DEFINED Weka_PACKAGES_DIR) 328 get_property (Weka_PACKAGES_DIR_SET CACHE Weka_PACKAGES_DIR PROPERTY TYPE SET) 329 if (Weka_PACKAGES_DIR_SET) 330 set_property (CACHE Weka_PACKAGES_DIR PROPERTY TYPE INTERNAL) 331 set_property (CACHE Weka_PACKAGES_DIR PROPERTY VALUE Weka_PACKAGES_DIR-NOTFOUND) 333 unset (Weka_PACKAGES_DIR_SET) 335 if (Weka_FIND_COMPONENTS AND Weka_FIND_REQUIRED) 336 message (WARNING "This Weka version has no
package manager and consists only of the core weka.jar package."
337 " The components required may not be available with this Weka version. Make sure that you"
338 " have installed and selected the proper Weka version required by this software package."
339 " Further, check the Weka_DIR variable and set it accordingly if it points to the wrong"
340 " installation of Weka.")
344 # ----------------------------------------------------------------------------
346 set (Weka_CLASSPATHS)
348 list (APPEND Weka_CLASSPATHS "${Weka_CLASSPATH}")
350 if (Weka_PACKAGES_CLASSPATH)
351 list (APPEND Weka_CLASSPATHS ${Weka_PACKAGES_CLASSPATH})
354 # ----------------------------------------------------------------------------
356 if (BASIS_DEBUG AND COMMAND basis_dump_variables)
357 basis_dump_variables ("${CMAKE_CURRENT_BINARY_DIR}/FindWekaVariables.cmake")
360 # ----------------------------------------------------------------------------
361 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
362 # if all listed variables are found or TRUE
363 include (FindPackageHandleStandardArgs)
365 find_package_handle_standard_args (
367 REQUIRED_VARS Weka_CLASSPATH ${Weka_REQUIRED_PACKAGE_VARS}
368 VERSION_VAR ${Weka_VERSION_STRING}
372 unset (Weka_REQUIRED_PACKAGE_VARS)
const unsigned int VERSION_MAJOR
The major version number.
function is(in result, in expected, in name)
Test whether a given result is equal to the expected result.
string VERSION
Project version.
function weka_get_version(out VERSION, out MAJOR, out MINOR, out PATCH)
Get Weka version.
macro weka_has_package_manager()
const unsigned int VERSION_MINOR
The minor version number.
const unsigned int VERSION_PATCH
The patch number.
function get_filename_component(inout ARGN)
Fixes CMake's get_filename_component() command.
function weka_list_packages(out PACKAGES, in WHICH)
Get list of Weka packages.