Difference between revisions of "CMakeUserFindLibSVM"

From KitwarePublic
Jump to navigationJump to search
Line 3: Line 3:
[[File:FindLibSVM.cmake]]
[[File:FindLibSVM.cmake]]
-----
-----
# -- Try to find LibSVM
# - Find LibSVM
  #
# LibSVM is a Library for Support Vector Machines
  #  LibSVM is a Library for Support Vector Machines
# available at http://www.csie.ntu.edu.tw/~cjlin/libsvm/
  # available at http://www.csie.ntu.edu.tw/~cjlin/libsvm/
#
  #
# The module defines the following variables:
  # ------------------------------------------------------------------
#  LIBSVM_FOUND - the system has LibSVM
  #
#  LIBSVM_INCLUDE_DIR - where to find svm.h
  #  -- Library usage example :
#  LIBSVM_INCLUDE_DIRS - libsvm includes
  #
#  LIBSVM_LIBRARY - where to find the LibSVM library
  #  find_package (LibSVM 2.9.0)
#  LIBSVM_LIBRARIES - aditional libraries
  #  if (LIBSVM_FOUND)
LIBSVM_MAJOR_VERSION - major version
  #    include_directories (${LIBSVM_INCLUDE_DIRS})
LIBSVM_MINOR_VERSION - minor version
  #    add_executable (foo foo.cpp)
LIBSVM_PATCH_VERSION - patch version
  #    target_link_libraries (foo ${LIBSVM_LIBRARIES})
LIBSVM_VERSION_STRING - version (ex. 2.9.0)
  #  endif ()
#  LIBSVM_ROOT_DIR - root dir (ex. /usr/local)
  #
  #  -- 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)
# Copyright 2005-2012 Kitware, Inc.
    include (CheckIncludeFile)
#
    check_include_file (math.h HAVE_MATH_H)
# Distributed under the OSI-approved BSD License (the "License");
  endif ()
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distributed this file outside of CMake, substitute the full
#  License text for the above reference.)




  # set LIBSVM_INCLUDE_DIR
# set LIBSVM_INCLUDE_DIR
  if (NOT 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"
)
    )
  endif ()




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




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




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




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




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


# link with math library on unix
if ( UNIX )
  list ( APPEND LIBSVM_LIBRARIES "-lm" )
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
# try to guess root dir from include dir
    elseif (LIBSVM_LIBRARY)
if ( LIBSVM_INCLUDE_DIR )
      string (REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_LIBRARY})
  string ( REGEX REPLACE "(.*)/include.*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_INCLUDE_DIR} )
    endif ()
# try to guess root dir from library dir
  endif ()
elseif ( LIBSVM_LIBRARY )
 
  string ( REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_LIBRARY} )
 
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
# handle REQUIRED and QUIET options
  include (FindPackageHandleStandardArgs)
include ( FindPackageHandleStandardArgs )
  find_package_handle_standard_args (LibSVM DEFAULT_MSG LIBSVM_LIBRARY
find_package_handle_standard_args ( LibSVM DEFAULT_MSG LIBSVM_LIBRARY
    _LIBSVM_VERSION_MATCH
  _LIBSVM_VERSION_MATCH
    HAVE_MATH_H
  LIBSVM_INCLUDE_DIR
    LIBSVM_INCLUDE_DIR
  LIBSVM_INCLUDE_DIRS
    LIBSVM_INCLUDE_DIRS
  LIBSVM_LIBRARIES
    LIBSVM_LIBRARIES
  LIBSVM_ROOT_DIR
    LIBSVM_ROOT_DIR
)
    LIBSVM_VERSION
  )




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


-----
-----

Revision as of 10:42, 20 December 2011

Back


File:FindLibSVM.cmake


  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

)


Back



CMake: [Welcome | Site Map]