FindSWIG.cmake 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # - Find SWIG
  2. # This module finds an installed SWIG. It sets the following variables:
  3. # SWIG_FOUND - set to true if SWIG is found
  4. # SWIG_DIR - the directory where swig is installed
  5. # SWIG_EXECUTABLE - the path to the swig executable
  6. # SWIG_VERSION - the version number of the swig executable
  7. #
  8. # The minimum required version of SWIG can be specified using the
  9. # standard syntax, e.g. FIND_PACKAGE(SWIG 1.1)
  10. #
  11. # All information is collected from the SWIG_EXECUTABLE so the
  12. # version to be found can be changed from the command line by
  13. # means of setting SWIG_EXECUTABLE
  14. #
  15. #=============================================================================
  16. # Copyright 2004-2009 Kitware, Inc.
  17. #
  18. # Distributed under the OSI-approved BSD License (the "License");
  19. # see accompanying file Copyright.txt for details.
  20. #
  21. # This software is distributed WITHOUT ANY WARRANTY; without even the
  22. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  23. # See the License for more information.
  24. #=============================================================================
  25. # (To distribute this file outside of CMake, substitute the full
  26. # License text for the above reference.)
  27. FIND_PROGRAM(SWIG_EXECUTABLE swig)
  28. IF(SWIG_EXECUTABLE)
  29. EXECUTE_PROCESS(COMMAND ${SWIG_EXECUTABLE} -swiglib
  30. OUTPUT_VARIABLE SWIG_swiglib_output
  31. ERROR_VARIABLE SWIG_swiglib_error
  32. RESULT_VARIABLE SWIG_swiglib_result)
  33. IF(SWIG_swiglib_result)
  34. IF(SWIG_FIND_REQUIRED)
  35. MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  36. ELSE(SWIG_FIND_REQUIRED)
  37. MESSAGE(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  38. ENDIF(SWIG_FIND_REQUIRED)
  39. ELSE(SWIG_swiglib_result)
  40. STRING(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
  41. # force the path to be computed each time in case SWIG_EXECUTABLE has changed.
  42. SET(SWIG_DIR SWIG_DIR-NOTFOUND)
  43. FIND_PATH(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output})
  44. IF(SWIG_DIR)
  45. SET(SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake)
  46. EXECUTE_PROCESS(COMMAND ${SWIG_EXECUTABLE} -version
  47. OUTPUT_VARIABLE SWIG_version_output
  48. ERROR_VARIABLE SWIG_version_output
  49. RESULT_VARIABLE SWIG_version_result)
  50. IF(SWIG_version_result)
  51. MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
  52. ELSE(SWIG_version_result)
  53. STRING(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
  54. SWIG_version_output "${SWIG_version_output}")
  55. SET(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
  56. ENDIF(SWIG_version_result)
  57. ENDIF(SWIG_DIR)
  58. ENDIF(SWIG_swiglib_result)
  59. ENDIF(SWIG_EXECUTABLE)
  60. INCLUDE(FindPackageHandleStandardArgs)
  61. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWIG REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
  62. VERSION_VAR SWIG_VERSION )