File: FindlibSVM.cmake

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (183 lines) | stat: -rw-r--r-- 4,949 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#  -- Try to find LibSVM
#
#  LibSVM is a Library for Support Vector Machines
#  available at http://www.csie.ntu.edu.tw/~cjlin/libsvm/
#
#  ------------------------------------------------------------------
#
#  -- Library usage example :
#
#  find_package (LibSVM 2.9.0)
#  if (LIBSVM_FOUND)
#     include_directories (${LIBSVM_INCLUDE_DIRS})
#     add_executable (foo foo.cpp)
#     target_link_libraries (foo ${LIBSVM_LIBRARIES})
#  endif ()
#
#  -- Show some debug information :
#
#  set (LIBSVM_DEBUG TRUE)
#  find_package (LibSVM)
#
#  -------------------------------------------------------------------
#
#  -- This module defines :
#
#  LIBSVM_FOUND - the system has LibSVM
#  LIBSVM_INCLUDE_DIR - where to find svm.h
#  LIBSVM_INCLUDE_DIRS libsvm includes
#  LIBSVM_LIBRARY - where to find the LibSVM library
#  LIBSVM_LIBRARIES - aditional libraries
#  LIBSVM_VERSION - version
#  LIBSVM_MAJOR_VERSION - major version
#  LIBSVM_MINOR_VERSION - minor version
#  LIBSVM_SUBMINOR_VERSION - subminor version
#  LIBSVM_ROOT_DIR - root dir (ex. /usr/local)
#
#  ------------------------------------------------------------------
#
#  Copyright (c) 2010 Julien Schueller <schueller at phimeca dot com>
#
#  Redistribution and use is allowed according to the terms of the New
#  BSD license.
#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

# check for math header
if (NOT HAVE_MATH_H)
  include (CheckIncludeFile)
  check_include_file (math.h HAVE_MATH_H)
endif ()


# set LIBSVM_INCLUDE_DIR
if (NOT LIBSVM_INCLUDE_DIR)
  find_path (LIBSVM_INCLUDE_DIR
    NAMES
      svm.h
    PATHS
      ${LIBSVM_ROOT_DIR}/include
    PATH_SUFFIXES
      libsvm
      libsvm-2.0/libsvm
    DOC
      "LibSVM include directory"
  )
endif ()


# set LIBSVM_INCLUDE_DIR
if (NOT LIBSVM_INCLUDE_DIRS)
  set (LIBSVM_INCLUDE_DIRS ${LIBSVM_INCLUDE_DIR})
endif ()


# version
if (NOT LIBSVM_VERSION)
  set (LIBSVM_MAJOR_VERSION 0)
  set (LIBSVM_MINOR_VERSION 0)
  set (LIBSVM_SUBMINOR_VERSION 0)
  if (LIBSVM_INCLUDE_DIR)
    # LIBSVM_VERSION macro defined in svm.h since version 2.8.9
    file (STRINGS "${LIBSVM_INCLUDE_DIR}/svm.h" _VERSION_STRING REGEX ".*LIBSVM_VERSION.*")
    if (_VERSION_STRING)
      string (REGEX REPLACE ".*_VERSION[ ]+([0-9]+)" "\\1" _VERSION_NUMBER "${_VERSION_STRING}")
      math (EXPR LIBSVM_MAJOR_VERSION "${_VERSION_NUMBER} / 100")
      math (EXPR LIBSVM_MINOR_VERSION "(${_VERSION_NUMBER} % 100 ) / 10")
      math (EXPR LIBSVM_SUBMINOR_VERSION "${_VERSION_NUMBER} % 10")
    endif ()
  endif ()
  set (LIBSVM_VERSION "${LIBSVM_MAJOR_VERSION}.${LIBSVM_MINOR_VERSION}.${LIBSVM_SUBMINOR_VERSION}")
endif ()



# check version
set (_LIBSVM_VERSION_MATCH TRUE)
set (_REQUIRED_VERSION "${LibSVM_FIND_VERSION_MAJOR}.${LibSVM_FIND_VERSION_MINOR}.${LibSVM_FIND_VERSION_PATCH}")
if (LibSVM_FIND_VERSION AND _VERSION_STRING)
  if (LibSVM_FIND_VERSION_EXACT)
    if ("${_REQUIRED_VERSION}" VERSION_EQUAL "${LIBSVM_VERSION}")
    else()
      set (_LIBSVM_VERSION_MATCH FALSE)
    endif ()
  else ()
    if ("${_REQUIRED_VERSION}" VERSION_GREATER "${LIBSVM_VERSION}")
      set (_LIBSVM_VERSION_MATCH FALSE)
    endif ()
  endif ()
endif ()


# set LIBSVM_LIBRARY
if(NOT LIBSVM_LIBRARY)
  find_library (LIBSVM_LIBRARY
    NAMES
      svm
    PATHS
      ${LIBSVM_ROOT_DIR}/lib
    DOC
      "LibSVM library location"
  )
endif ()


# set LIBSVM_LIBRARIES
if (NOT LIBSVM_LIBRARIES)
  set (LIBSVM_LIBRARIES ${LIBSVM_LIBRARY})

  # link with math library on unix
  if (UNIX)
    list (APPEND LIBSVM_LIBRARIES "-lm")
  endif ()
endif ()


# root dir
if (NOT LIBSVM_ROOT_DIR)
  # try to guess root dir from include dir
  if (LIBSVM_INCLUDE_DIR)
    string (REGEX REPLACE "(.*)/include.*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_INCLUDE_DIR})

  # try to guess root dir from library dir
  elseif (LIBSVM_LIBRARY)
    string (REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_LIBRARY})
  endif ()
endif ()


# debug
if (LIBSVM_DEBUG)
  message (STATUS "LIBSVM_LIBRARY: ${LIBSVM_LIBRARY}")
  message (STATUS "LIBSVM_LIBRARIES: ${LIBSVM_LIBRARIES}")
  message (STATUS "LIBSVM_INCLUDE_DIR: ${LIBSVM_INCLUDE_DIR}")
  message (STATUS "LIBSVM_INCLUDE_DIRS: ${LIBSVM_INCLUDE_DIRS}")
  message (STATUS "LIBSVM_ROOT_DIR: ${LIBSVM_ROOT_DIR}")
  message (STATUS "LIBSVM_VERSION: ${LIBSVM_VERSION}")
  message (STATUS "LIBSVM_MAJOR_VERSION: ${LIBSVM_MAJOR_VERSION}")
  message (STATUS "LIBSVM_MINOR_VERSION: ${LIBSVM_MINOR_VERSION}")
  message (STATUS "LIBSVM_SUBMINOR_VERSION: ${LIBSVM_SUBMINOR_VERSION}")
endif ()


# handle REQUIRED and QUIET options
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (LibSVM DEFAULT_MSG LIBSVM_LIBRARY
  _LIBSVM_VERSION_MATCH
  HAVE_MATH_H
  LIBSVM_INCLUDE_DIR
  LIBSVM_INCLUDE_DIRS
  LIBSVM_LIBRARIES
  LIBSVM_ROOT_DIR
  LIBSVM_VERSION
)


mark_as_advanced (
  LIBSVM_LIBRARY
  LIBSVM_LIBRARIES
  LIBSVM_INCLUDE_DIR
  LIBSVM_INCLUDE_DIRS
  LIBSVM_ROOT_DIR
  LIBSVM_VERSION
)