CMakeUserFindLibSVM: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
No edit summary
Line 13: Line 13:
     #
     #
     #  find_package (LibSVM 2.9.0)
     #  find_package (LibSVM 2.9.0)
     #  if (LibSVM_FOUND)
     #  if (LIBSVM_FOUND)
     #    include_directories (${LibSVM_INCLUDE_DIRS})
     #    include_directories (${LIBSVM_INCLUDE_DIRS})
     #    add_executable (foo foo.cpp)
     #    add_executable (foo foo.cpp)
     #    target_link_libraries (foo ${LibSVM_LIBRARIES})
     #    target_link_libraries (foo ${LIBSVM_LIBRARIES})
     #  endif ()
     #  endif ()
     #
     #
     #  -- Show some debug information :
     #  -- Show some debug information :
     #
     #
     #  set (LibSVM_DEBUG TRUE)
     #  set (LIBSVM_DEBUG TRUE)
     #  find_package (LibSVM)
     #  find_package (LibSVM)
     #
     #
Line 28: Line 28:
     #  -- This module defines :
     #  -- This module defines :
     #
     #
     #  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_VERSION - library version
     #  LIBSVM_VERSION - library version
     #  LibSVM_MAJOR_VERSION
     #  LIBSVM_MAJOR_VERSION
     #  LibSVM_MINOR_VERSION
     #  LIBSVM_MINOR_VERSION
     #  LibSVM_SUBMINOR_VERSION
     #  LIBSVM_SUBMINOR_VERSION
     #
     #
     #  ------------------------------------------------------------------
     #  ------------------------------------------------------------------
Line 54: Line 54:
      
      
      
      
     # set LibSVM_INCLUDE_DIR
     # set LIBSVM_INCLUDE_DIR
     if (NOT LibSVM_INCLUDE_DIR)
     if (NOT LIBSVM_INCLUDE_DIR)
       find_path (LibSVM_INCLUDE_DIR
       find_path (LIBSVM_INCLUDE_DIR
         NAMES
         NAMES
           svm.h
           svm.h
Line 73: Line 73:
      
      
      
      
     # set LibSVM_INCLUDE_DIR
     # set LIBSVM_INCLUDE_DIR
     if (NOT LibSVM_INCLUDE_DIRS)
     if (NOT LIBSVM_INCLUDE_DIRS)
       set (LibSVM_INCLUDE_DIRS ${LibSVM_INCLUDE_DIR})
       set (LIBSVM_INCLUDE_DIRS ${LIBSVM_INCLUDE_DIR})
     endif ()
     endif ()
      
      
      
      
     # version
     # version
     if (NOT LibSVM_VERSION)
     if (NOT LIBSVM_VERSION)
       # version defined in svm.h since version 2.9
       # version defined in svm.h since version 2.9
       set (LibSVM_MAJOR_VERSION 0)
       set (LIBSVM_MAJOR_VERSION 0)
       set (LibSVM_MINOR_VERSION 0)
       set (LIBSVM_MINOR_VERSION 0)
       set (LibSVM_SUBMINOR_VERSION 0)
       set (LIBSVM_SUBMINOR_VERSION 0)
       if (LibSVM_INCLUDE_DIR)
       if (LIBSVM_INCLUDE_DIR)
         file (STRINGS "${LibSVM_INCLUDE_DIR}/svm.h" _VERSION_STRING
         file (STRINGS "${LIBSVM_INCLUDE_DIR}/svm.h" _VERSION_STRING
           REGEX ".*LIBSVM_VERSION.*")
           REGEX ".*LIBSVM_VERSION.*")
         if (_VERSION_STRING)
         if (_VERSION_STRING)
           string (REGEX REPLACE ".*_VERSION[ ]+([0-9]+)" "\\1" _VERSION_NUMBER "${_VERSION_STRING}")
           string (REGEX REPLACE ".*_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_SUBMINOR_VERSION "${_VERSION_NUMBER} % 10")
           math (EXPR LIBSVM_SUBMINOR_VERSION "${_VERSION_NUMBER} % 10")
         endif ()
         endif ()
       endif ()
       endif ()
       set (LibSVM_VERSION "${LibSVM_MAJOR_VERSION}.${LibSVM_MINOR_VERSION}.${LibSVM_SUBMINOR_VERSION}")
       set (LIBSVM_VERSION "${LIBSVM_MAJOR_VERSION}.${LIBSVM_MINOR_VERSION}.${LIBSVM_SUBMINOR_VERSION}")
     endif ()
     endif ()
      
      
Line 101: Line 101:
      
      
     # check version
     # check version
     set (_LibSVM_VERSION_MATCH TRUE)
     set (_LIBSVM_VERSION_MATCH TRUE)
     set (_REQUIRED_VERSION "${LibSVM_FIND_VERSION_MAJOR}.${LibSVM_FIND_VERSION_MINOR}.${LibSVM_FIND_VERSION_PATCH}")
     set (_REQUIRED_VERSION "${LIBSVM_FIND_VERSION_MAJOR}.${LIBSVM_FIND_VERSION_MINOR}.${LIBSVM_FIND_VERSION_PATCH}")
     if (LibSVM_FIND_VERSION)
     if (LIBSVM_FIND_VERSION)
       if (LibSVM_FIND_VERSION_EXACT)
       if (LIBSVM_FIND_VERSION_EXACT)
         if ("${_REQUIRED_VERSION}" VERSION_EQUAL "${LibSVM_VERSION}")
         if ("${_REQUIRED_VERSION}" VERSION_EQUAL "${LIBSVM_VERSION}")
         else()
         else()
           set (_LibSVM_VERSION_MATCH FALSE)
           set (_LIBSVM_VERSION_MATCH FALSE)
         endif ()
         endif ()
       else ()
       else ()
         if ("${_REQUIRED_VERSION}" VERSION_GREATER "${LibSVM_VERSION}")
         if ("${_REQUIRED_VERSION}" VERSION_GREATER "${LIBSVM_VERSION}")
           set (_LibSVM_VERSION_MATCH FALSE)
           set (_LIBSVM_VERSION_MATCH FALSE)
         endif ()
         endif ()
       endif ()
       endif ()
Line 117: Line 117:
      
      
      
      
     # set LibSVM_LIBRARY
     # set LIBSVM_LIBRARY
     if(NOT LibSVM_LIBRARY)
     if(NOT LIBSVM_LIBRARY)
       find_library (LibSVM_LIBRARY
       find_library (LIBSVM_LIBRARY
         NAMES
         NAMES
           svm
           svm
Line 133: Line 133:
      
      
      
      
     # set LibSVM_LIBRARIES
     # set LIBSVM_LIBRARIES
     if (NOT LibSVM_LIBRARIES)
     if (NOT LIBSVM_LIBRARIES)
       set (LibSVM_LIBRARIES ${LibSVM_LIBRARY})
       set (LIBSVM_LIBRARIES ${LIBSVM_LIBRARY})
      
      
       # link with math library on unix
       # link with math library on unix
       if (UNIX)
       if (UNIX)
         list (APPEND LibSVM_LIBRARIES "-lm")
         list (APPEND LIBSVM_LIBRARIES "-lm")
       endif ()
       endif ()
     endif ()
     endif ()
Line 146: Line 146:
     # 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
       HAVE_MATH_H
       LibSVM_INCLUDE_DIR
       LIBSVM_INCLUDE_DIR
       LibSVM_INCLUDE_DIRS
       LIBSVM_INCLUDE_DIRS
       LibSVM_LIBRARIES
       LIBSVM_LIBRARIES
       LibSVM_VERSION
       LIBSVM_VERSION
     )
     )
    set (LibSVM_FOUND ${LIBSVM_FOUND})
      
      
      
      
     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_VERSION
       LIBSVM_VERSION
       LibSVM_MAJOR_VERSION
       LIBSVM_MAJOR_VERSION
       LibSVM_MINOR_VERSION
       LIBSVM_MINOR_VERSION
       LibSVM_SUBMINOR_VERSION
       LIBSVM_SUBMINOR_VERSION
     )
     )
      
      
      
      
     # debug
     # debug
     if (LibSVM_DEBUG)
     if (LIBSVM_DEBUG)
       message (STATUS "LibSVM_LIBRARY: ${LibSVM_LIBRARY}")
       message (STATUS "LIBSVM_LIBRARY: ${LIBSVM_LIBRARY}")
       message (STATUS "LibSVM_LIBRARIES: ${LibSVM_LIBRARIES}")
       message (STATUS "LIBSVM_LIBRARIES: ${LIBSVM_LIBRARIES}")
       message (STATUS "LibSVM_INCLUDE_DIR: ${LibSVM_INCLUDE_DIR}")
       message (STATUS "LIBSVM_INCLUDE_DIR: ${LIBSVM_INCLUDE_DIR}")
       message (STATUS "LibSVM_INCLUDE_DIRS: ${LibSVM_INCLUDE_DIRS}")
       message (STATUS "LIBSVM_INCLUDE_DIRS: ${LIBSVM_INCLUDE_DIRS}")
       message (STATUS "LibSVM_VERSION: ${LibSVM_VERSION}")
       message (STATUS "LIBSVM_VERSION: ${LIBSVM_VERSION}")
       message (STATUS "LibSVM_MAJOR_VERSION: ${LibSVM_MAJOR_VERSION}")
       message (STATUS "LIBSVM_MAJOR_VERSION: ${LIBSVM_MAJOR_VERSION}")
       message (STATUS "LibSVM_MINOR_VERSION: ${LibSVM_MINOR_VERSION}")
       message (STATUS "LIBSVM_MINOR_VERSION: ${LIBSVM_MINOR_VERSION}")
       message (STATUS "LibSVM_SUBMINOR_VERSION: ${LibSVM_SUBMINOR_VERSION}")
       message (STATUS "LIBSVM_SUBMINOR_VERSION: ${LIBSVM_SUBMINOR_VERSION}")
     endif ()
     endif ()



Revision as of 15:50, 15 March 2010

Back


File:FindLibSVM.cmake


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