Difference between revisions of "CMakeUserFindLibSVM"

From KitwarePublic
Jump to navigationJump to search
Line 3: Line 3:
[[CMake_User_Contributed_Macros|Back]]
[[CMake_User_Contributed_Macros|Back]]
-----
-----
 
    #  -- Try to find LibSVM
     # - Find LibSVM
     #
    #  LibSVM is a Library for Support Vector Machines
    #  available at http://www.csie.ntu.edu.tw/~cjlin/libsvm/
    #
    #  ------------------------------------------------------------------
     #
     #
     #  -- Library usage example :
     #  -- Library usage example :
Line 20: Line 24:
     #  find_package (LibSVM)
     #  find_package (LibSVM)
     #
     #
     # -------------------------------------------------------------------
     # -------------------------------------------------------------------
     #
     #
     #  This module defines :
     #  -- This module defines :
     #
     #
     #  LibSVM_FOUND - the system has LibSVM
     #  LibSVM_FOUND - the system has LibSVM

Revision as of 09:18, 2 March 2010

File:FindLibSVM.cmake

Back


   #  -- 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 - library version
   #  LibSVM_MAJOR_VERSION
   #  LibSVM_MINOR_VERSION
   #  LibSVM_SUBMINOR_VERSION
   #
   #  ------------------------------------------------------------------
   #
   #  Copyright (c) 2010 Julien Schueller <schueller@phimeca.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
       PATH
         /usr/include
         /usr/local/include
         /opt/local/include
         /sw/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)
     # version defined in svm.h since version 2.9
     set (LibSVM_MAJOR_VERSION 0)
     set (LibSVM_MINOR_VERSION 0)
     set (LibSVM_SUBMINOR_VERSION 0)
     if (LibSVM_INCLUDE_DIR)
       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)
     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
         /usr/lib
         /usr/local/lib
         /opt/local/lib
         /sw/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 ()
   
   
   # 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_VERSION
   )
   set (LibSVM_FOUND ${LIBSVM_FOUND})
   
   
   mark_as_advanced (
     LibSVM_LIBRARY
     LibSVM_LIBRARIES
     LibSVM_INCLUDE_DIR
     LibSVM_INCLUDE_DIRS
     LibSVM_VERSION
     LibSVM_MAJOR_VERSION
     LibSVM_MINOR_VERSION
     LibSVM_SUBMINOR_VERSION
   )
   
   
   # 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_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 ()

Back



CMake: [Welcome | Site Map]