CMakeUserFindLibSVM: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
[[CMake_User_Contributed_Macros|Back]]
# - Find LibSVM
-----
# LibSVM is a Library for Support Vector Machines
[[File:FindLibSVM.cmake]]
# available at http://www.csie.ntu.edu.tw/~cjlin/libsvm/
-----
#
  # - Find LibSVM
# The module defines the following variables:
  # LibSVM is a Library for Support Vector Machines
#  LIBSVM_FOUND - the system has LibSVM
  # available at http://www.csie.ntu.edu.tw/~cjlin/libsvm/
#  LIBSVM_INCLUDE_DIR - where to find svm.h
  #
#  LIBSVM_INCLUDE_DIRS - libsvm includes
  # The module defines the following variables:
#  LIBSVM_LIBRARY - where to find the LibSVM library
  #  LIBSVM_FOUND - the system has LibSVM
#  LIBSVM_LIBRARIES - aditional libraries
  #  LIBSVM_INCLUDE_DIR - where to find svm.h
#  LIBSVM_MAJOR_VERSION - major version
  #  LIBSVM_INCLUDE_DIRS - libsvm includes
#  LIBSVM_MINOR_VERSION - minor version
  #  LIBSVM_LIBRARY - where to find the LibSVM library
#  LIBSVM_PATCH_VERSION - patch version
  #  LIBSVM_LIBRARIES - aditional libraries
#  LIBSVM_VERSION_STRING - version (ex. 2.9.0)
  #  LIBSVM_MAJOR_VERSION - major version
#  LIBSVM_ROOT_DIR - root dir (ex. /usr/local)
  #  LIBSVM_MINOR_VERSION - minor version
  #  LIBSVM_PATCH_VERSION - patch version
  #  LIBSVM_VERSION_STRING - version (ex. 2.9.0)
  #  LIBSVM_ROOT_DIR - root dir (ex. /usr/local)


  #=============================================================================
#=============================================================================
  # Copyright 2005-2012 Kitware, Inc.
# Copyright 2005-2012 Kitware, Inc.
  #
#
  # Distributed under the OSI-approved BSD License (the "License");
# Distributed under the OSI-approved BSD License (the "License");
  # see accompanying file Copyright.txt for details.
# see accompanying file Copyright.txt for details.
  #
#
  # This software is distributed WITHOUT ANY WARRANTY; without even the
# This software is distributed WITHOUT ANY WARRANTY; without even the
  # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  # See the License for more information.
# See the License for more information.
  #=============================================================================
#=============================================================================
  # (To distributed this file outside of CMake, substitute the full
# (To distributed this file outside of CMake, substitute the full
  #  License text for the above reference.)
#  License text for the above reference.)




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




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




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




  # check version
# check version
  set ( _LIBSVM_VERSION_MATCH TRUE )
set ( _LIBSVM_VERSION_MATCH TRUE )
  if ( LibSVM_FIND_VERSION AND LIBSVM_VERSION_STRING )
if ( LibSVM_FIND_VERSION AND LIBSVM_VERSION_STRING )
    if ( LibSVM_FIND_VERSION_EXACT )
  if ( LibSVM_FIND_VERSION_EXACT )
      if ( NOT ${LibSVM_FIND_VERSION} VERSION_EQUAL ${LIBSVM_VERSION_STRING} )
    if ( NOT ${LibSVM_FIND_VERSION} VERSION_EQUAL ${LIBSVM_VERSION_STRING} )
set ( _LIBSVM_VERSION_MATCH FALSE )
      set ( _LIBSVM_VERSION_MATCH FALSE )
      endif ()
    endif ()
    else ()
  else ()
      if ( ${LibSVM_FIND_VERSION} VERSION_GREATER ${LIBSVM_VERSION_STRING} )
    if ( ${LibSVM_FIND_VERSION} VERSION_GREATER ${LIBSVM_VERSION_STRING} )
set ( _LIBSVM_VERSION_MATCH FALSE )
      set ( _LIBSVM_VERSION_MATCH FALSE )
      endif ()
     endif ()
     endif ()
   endif ()
   endif ()
endif ()


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


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


# set LIBSVM_LIBRARIES
set ( LIBSVM_LIBRARIES ${LIBSVM_LIBRARY} )


  # set LIBSVM_LIBRARIES
# link with math library on unix
   set ( LIBSVM_LIBRARIES ${LIBSVM_LIBRARY} )
if ( UNIX )
   list ( APPEND LIBSVM_LIBRARIES "-lm" )
endif ()


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


# 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 ()


  # 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 ()


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


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


mark_as_advanced (
  LIBSVM_LIBRARY
  LIBSVM_LIBRARIES
  LIBSVM_INCLUDE_DIR
  LIBSVM_INCLUDE_DIRS
  LIBSVM_ROOT_DIR
  LIBSVM_VERSION_STRING
  LIBSVM_MAJOR_VERSION
  LIBSVM_MINOR_VERSION
  LIBSVM_PATCH_VERSION
)


  mark_as_advanced (
    LIBSVM_LIBRARY
    LIBSVM_LIBRARIES
    LIBSVM_INCLUDE_DIR
    LIBSVM_INCLUDE_DIRS
    LIBSVM_ROOT_DIR
    LIBSVM_VERSION_STRING
    LIBSVM_MAJOR_VERSION
    LIBSVM_MINOR_VERSION
    LIBSVM_PATCH_VERSION
  )
-----
[[CMake_User_Contributed_Macros|Back]]


{{CMake/Template/Footer}}
{{CMake/Template/Footer}}
[[Category:FindModules]]
[[Category:FindModules]]

Revision as of 15:46, 20 December 2011

  1. - Find LibSVM
  2. LibSVM is a Library for Support Vector Machines
  3. available at http://www.csie.ntu.edu.tw/~cjlin/libsvm/
  4. The module defines the following variables:
  5. LIBSVM_FOUND - the system has LibSVM
  6. LIBSVM_INCLUDE_DIR - where to find svm.h
  7. LIBSVM_INCLUDE_DIRS - libsvm includes
  8. LIBSVM_LIBRARY - where to find the LibSVM library
  9. LIBSVM_LIBRARIES - aditional libraries
  10. LIBSVM_MAJOR_VERSION - major version
  11. LIBSVM_MINOR_VERSION - minor version
  12. LIBSVM_PATCH_VERSION - patch version
  13. LIBSVM_VERSION_STRING - version (ex. 2.9.0)
  14. LIBSVM_ROOT_DIR - root dir (ex. /usr/local)
  1. =============================================================================
  2. Copyright 2005-2012 Kitware, Inc.
  3. Distributed under the OSI-approved BSD License (the "License");
  4. see accompanying file Copyright.txt for details.
  5. This software is distributed WITHOUT ANY WARRANTY; without even the
  6. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  7. See the License for more information.
  8. =============================================================================
  9. (To distributed this file outside of CMake, substitute the full
  10. License text for the above reference.)


  1. set 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"

)


  1. set LIBSVM_INCLUDE_DIRS

if ( LIBSVM_INCLUDE_DIR )

 set ( LIBSVM_INCLUDE_DIRS ${LIBSVM_INCLUDE_DIR} )

endif ()


  1. version

set ( _VERSION_FILE ${LIBSVM_INCLUDE_DIR}/svm.h ) if ( EXISTS ${_VERSION_FILE} )

 # LIBSVM_VERSION_STRING macro defined in svm.h since version 2.8.9
 file ( STRINGS ${_VERSION_FILE} _VERSION_STRING REGEX ".*define[ ]+LIBSVM_VERSION[ ]+[0-9]+.*" )
 if ( _VERSION_STRING )
   string ( REGEX REPLACE ".*LIBSVM_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_PATCH_VERSION "${_VERSION_NUMBER} % 10" )
   set ( LIBSVM_VERSION_STRING "${LIBSVM_MAJOR_VERSION}.${LIBSVM_MINOR_VERSION}.${LIBSVM_PATCH_VERSION}" )
 endif ()

endif ()


  1. check version

set ( _LIBSVM_VERSION_MATCH TRUE ) if ( LibSVM_FIND_VERSION AND LIBSVM_VERSION_STRING )

 if ( LibSVM_FIND_VERSION_EXACT )
   if ( NOT ${LibSVM_FIND_VERSION} VERSION_EQUAL ${LIBSVM_VERSION_STRING} )
     set ( _LIBSVM_VERSION_MATCH FALSE )
   endif ()
 else ()
   if ( ${LibSVM_FIND_VERSION} VERSION_GREATER ${LIBSVM_VERSION_STRING} )
     set ( _LIBSVM_VERSION_MATCH FALSE )
   endif ()
 endif ()

endif ()


  1. set LIBSVM_LIBRARY

find_library ( LIBSVM_LIBRARY

 NAMES
   svm
 PATHS
   ${LIBSVM_ROOT_DIR}/lib
 DOC
   "LibSVM library location"

)


  1. set LIBSVM_LIBRARIES

set ( LIBSVM_LIBRARIES ${LIBSVM_LIBRARY} )

  1. link with math library on unix

if ( UNIX )

 list ( APPEND LIBSVM_LIBRARIES "-lm" )

endif ()


  1. try to guess root dir from include dir

if ( LIBSVM_INCLUDE_DIR )

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

elseif ( LIBSVM_LIBRARY )

 string ( REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_LIBRARY} )

endif ()


  1. handle REQUIRED and QUIET options

include ( FindPackageHandleStandardArgs ) find_package_handle_standard_args ( LibSVM DEFAULT_MSG LIBSVM_LIBRARY

 _LIBSVM_VERSION_MATCH
 LIBSVM_INCLUDE_DIR
 LIBSVM_INCLUDE_DIRS
 LIBSVM_LIBRARIES
 LIBSVM_ROOT_DIR

)


mark_as_advanced (

 LIBSVM_LIBRARY
 LIBSVM_LIBRARIES
 LIBSVM_INCLUDE_DIR
 LIBSVM_INCLUDE_DIRS
 LIBSVM_ROOT_DIR
 LIBSVM_VERSION_STRING
 LIBSVM_MAJOR_VERSION
 LIBSVM_MINOR_VERSION
 LIBSVM_PATCH_VERSION

)




CMake: [Welcome | Site Map]