Difference between revisions of "CMakeUserFindLibSVM"

From KitwarePublic
Jump to navigationJump to search
Line 3: Line 3:
[[File:FindLibSVM.cmake]]
[[File:FindLibSVM.cmake]]
-----
-----
# - 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:
# The module defines the following variables:
#  LIBSVM_FOUND - the system has LibSVM
#  LIBSVM_FOUND - the system has LibSVM
#  LIBSVM_INCLUDE_DIR - where to find svm.h
#  LIBSVM_INCLUDE_DIR - where to find svm.h
#  LIBSVM_INCLUDE_DIRS - libsvm includes
#  LIBSVM_INCLUDE_DIRS - libsvm includes
#  LIBSVM_LIBRARY - where to find the LibSVM library
#  LIBSVM_LIBRARY - where to find the LibSVM library
#  LIBSVM_LIBRARIES - aditional libraries
#  LIBSVM_LIBRARIES - aditional libraries
#  LIBSVM_MAJOR_VERSION - major version
#  LIBSVM_MAJOR_VERSION - major version
#  LIBSVM_MINOR_VERSION - minor version
#  LIBSVM_MINOR_VERSION - minor version
#  LIBSVM_PATCH_VERSION - patch version
#  LIBSVM_PATCH_VERSION - patch version
#  LIBSVM_VERSION_STRING - version (ex. 2.9.0)
#  LIBSVM_VERSION_STRING - version (ex. 2.9.0)
#  LIBSVM_ROOT_DIR - root dir (ex. /usr/local)
#  LIBSVM_ROOT_DIR - root dir (ex. /usr/local)
 
#=============================================================================
#=============================================================================
# Copyright 2005-2012 Kitware, Inc.
# Copyright (C) 2010-2013, Julien Schueller
#
# All rights reserved.
# Distributed under the OSI-approved BSD License (the "License");
#  
# see accompanying file Copyright.txt for details.
# Redistribution and use in source and binary forms, with or without
#
# modification, are permitted provided that the following conditions are met:
# This software is distributed WITHOUT ANY WARRANTY; without even the
#
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# 1. Redistributions of source code must retain the above copyright notice, this
# See the License for more information.
#    list of conditions and the following disclaimer.
#=============================================================================
# 2. Redistributions in binary form must reproduce the above copyright notice,
# (To distributed this file outside of CMake, substitute the full
#    this list of conditions and the following disclaimer in the documentation
#  License text for the above reference.)
#    and/or other materials provided with the distribution.  
#
# set LIBSVM_INCLUDE_DIR
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
find_path ( LIBSVM_INCLUDE_DIR
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  NAMES
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    svm.h
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  PATHS
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    ${LIBSVM_ROOT_DIR}/include
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  PATH_SUFFIXES
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    libsvm
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    libsvm-2.0/libsvm
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  DOC
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    "LibSVM include directory"
 
)
# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# set LIBSVM_INCLUDE_DIRS
# either expressed or implied, of the FreeBSD Project.
if ( LIBSVM_INCLUDE_DIR )
#=============================================================================
  set ( LIBSVM_INCLUDE_DIRS ${LIBSVM_INCLUDE_DIR} )
 
endif ()
# set LIBSVM_INCLUDE_DIR
find_path ( LIBSVM_INCLUDE_DIR
# version
  NAMES
set ( _VERSION_FILE ${LIBSVM_INCLUDE_DIR}/svm.h )
    svm.h
if ( EXISTS ${_VERSION_FILE} )
  PATHS
  # LIBSVM_VERSION_STRING macro defined in svm.h since version 2.8.9
    ${LIBSVM_ROOT_DIR}/include
  file ( STRINGS ${_VERSION_FILE} _VERSION_STRING REGEX ".*define[ ]+LIBSVM_VERSION[ ]+[0-9]+.*" )
  PATH_SUFFIXES
  if ( _VERSION_STRING )
    libsvm
    string ( REGEX REPLACE ".*LIBSVM_VERSION[ ]+([0-9]+)" "\\1" _VERSION_NUMBER "${_VERSION_STRING}" )
    libsvm-2.0/libsvm
    math ( EXPR LIBSVM_MAJOR_VERSION "${_VERSION_NUMBER} / 100" )
  DOC
    math ( EXPR LIBSVM_MINOR_VERSION "(${_VERSION_NUMBER} % 100 ) / 10" )
    "LibSVM include directory"
    math ( EXPR LIBSVM_PATCH_VERSION "${_VERSION_NUMBER} % 10" )
)
    set ( LIBSVM_VERSION_STRING "${LIBSVM_MAJOR_VERSION}.${LIBSVM_MINOR_VERSION}.${LIBSVM_PATCH_VERSION}" )
 
  endif ()
 
endif ()
# set LIBSVM_INCLUDE_DIRS
if ( LIBSVM_INCLUDE_DIR )
# check version
  set ( LIBSVM_INCLUDE_DIRS ${LIBSVM_INCLUDE_DIR} )
set ( _LIBSVM_VERSION_MATCH TRUE )
endif ()
if ( LibSVM_FIND_VERSION AND LIBSVM_VERSION_STRING )
 
  if ( LibSVM_FIND_VERSION_EXACT )
 
    if ( NOT ${LibSVM_FIND_VERSION} VERSION_EQUAL ${LIBSVM_VERSION_STRING} )
# version
      set ( _LIBSVM_VERSION_MATCH FALSE )
set ( _VERSION_FILE ${LIBSVM_INCLUDE_DIR}/svm.h )
    endif ()
if ( EXISTS ${_VERSION_FILE} )
  else ()
  # LIBSVM_VERSION_STRING macro defined in svm.h since version 2.8.9
    if ( ${LibSVM_FIND_VERSION} VERSION_GREATER ${LIBSVM_VERSION_STRING} )
  file ( STRINGS ${_VERSION_FILE} _VERSION_STRING REGEX ".*define[ ]+LIBSVM_VERSION[ ]+[0-9]+.*" )
      set ( _LIBSVM_VERSION_MATCH FALSE )
  if ( _VERSION_STRING )
    endif ()
    string ( REGEX REPLACE ".*LIBSVM_VERSION[ ]+([0-9]+)" "\\1" _VERSION_NUMBER "${_VERSION_STRING}" )
  endif ()
    math ( EXPR LIBSVM_MAJOR_VERSION "${_VERSION_NUMBER} / 100" )
endif ()
    math ( EXPR LIBSVM_MINOR_VERSION "(${_VERSION_NUMBER} % 100 ) / 10" )
    math ( EXPR LIBSVM_PATCH_VERSION "${_VERSION_NUMBER} % 10" )
# set LIBSVM_LIBRARY
    set ( LIBSVM_VERSION_STRING "${LIBSVM_MAJOR_VERSION}.${LIBSVM_MINOR_VERSION}.${LIBSVM_PATCH_VERSION}" )
find_library ( LIBSVM_LIBRARY
  endif ()
  NAMES
endif ()
    svm
 
  PATHS
 
    ${LIBSVM_ROOT_DIR}/lib
# check version
  DOC
set ( _LIBSVM_VERSION_MATCH TRUE )
    "LibSVM library location"
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_LIBRARIES
      set ( _LIBSVM_VERSION_MATCH FALSE )
set ( LIBSVM_LIBRARIES ${LIBSVM_LIBRARY} )
    endif ()
  else ()
# link with math library on unix
    if ( LIBSVM_VERSION_STRING  VERSION_LESS LibSVM_FIND_VERSION )
if ( UNIX )
      set ( _LIBSVM_VERSION_MATCH FALSE )
  list ( APPEND LIBSVM_LIBRARIES "-lm" )
    endif ()
endif ()
  endif ()
endif ()
# try to guess root dir from include dir
 
if ( LIBSVM_INCLUDE_DIR )
 
  string ( REGEX REPLACE "(.*)/include.*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_INCLUDE_DIR} )
# set LIBSVM_LIBRARY
# try to guess root dir from library dir
find_library ( LIBSVM_LIBRARY
elseif ( LIBSVM_LIBRARY )
  NAMES
  string ( REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_LIBRARY} )
    svm
endif ()
  PATHS
    ${LIBSVM_ROOT_DIR}/lib
  DOC
# handle REQUIRED and QUIET options
    "LibSVM library location"
include ( FindPackageHandleStandardArgs )
)
find_package_handle_standard_args ( LibSVM DEFAULT_MSG LIBSVM_LIBRARY
 
  _LIBSVM_VERSION_MATCH
 
  LIBSVM_INCLUDE_DIR
# set LIBSVM_LIBRARIES
  LIBSVM_INCLUDE_DIRS
set ( LIBSVM_LIBRARIES ${LIBSVM_LIBRARY} )
  LIBSVM_LIBRARIES
 
  LIBSVM_ROOT_DIR
# link with math library on unix
)
if ( UNIX )
  list ( APPEND LIBSVM_LIBRARIES "-lm" )
mark_as_advanced (
endif ()
  LIBSVM_LIBRARY
 
  LIBSVM_LIBRARIES
 
  LIBSVM_INCLUDE_DIR
# try to guess root dir from include dir
  LIBSVM_INCLUDE_DIRS
if ( LIBSVM_INCLUDE_DIR )
  LIBSVM_ROOT_DIR
  string ( REGEX REPLACE "(.*)/include.*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_INCLUDE_DIR} )
  LIBSVM_VERSION_STRING
# try to guess root dir from library dir
  LIBSVM_MAJOR_VERSION
elseif ( LIBSVM_LIBRARY )
  LIBSVM_MINOR_VERSION
  string ( REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" LIBSVM_ROOT_DIR ${LIBSVM_LIBRARY} )
  LIBSVM_PATCH_VERSION
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
)
 
 
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_User_Contributed_Macros|Back]]

Revision as of 09:49, 24 January 2013

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 (C) 2010-2013, Julien Schueller
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice, this
  7. list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  12. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  13. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  14. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  15. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  16. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  17. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  18. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  20. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1. The views and conclusions contained in the software and documentation are those
  2. of the authors and should not be interpreted as representing official policies,
  3. either expressed or implied, of the FreeBSD Project.
  4. =============================================================================
  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_VERSION_STRING  VERSION_LESS LibSVM_FIND_VERSION )
     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]