FindSWIG.cmake 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # All informations are collected from the SWIG_EXECUTABLE so the
  9. # version to be found can be changed from the command line by
  10. # means of setting SWIG_EXECUTABLE
  11. #
  12. #=============================================================================
  13. # Copyright 2004-2009 Kitware, Inc.
  14. #
  15. # Distributed under the OSI-approved BSD License (the "License");
  16. # see accompanying file Copyright.txt for details.
  17. #
  18. # This software is distributed WITHOUT ANY WARRANTY; without even the
  19. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. # See the License for more information.
  21. #=============================================================================
  22. # (To distributed this file outside of CMake, substitute the full
  23. # License text for the above reference.)
  24. SET(SWIG_FOUND FALSE)
  25. FIND_PROGRAM(SWIG_EXECUTABLE swig)
  26. IF(SWIG_EXECUTABLE)
  27. EXECUTE_PROCESS(COMMAND ${SWIG_EXECUTABLE} -swiglib
  28. OUTPUT_VARIABLE SWIG_swiglib_output
  29. ERROR_VARIABLE SWIG_swiglib_error
  30. RESULT_VARIABLE SWIG_swiglib_result)
  31. IF(SWIG_swiglib_result)
  32. IF(SWIG_FIND_REQUIRED)
  33. MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  34. ELSE(SWIG_FIND_REQUIRED)
  35. MESSAGE(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  36. ENDIF(SWIG_FIND_REQUIRED)
  37. ELSE(SWIG_swiglib_result)
  38. STRING(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
  39. # force the path to be computed each time in case SWIG_EXECUTABLE has changed.
  40. SET(SWIG_DIR SWIG_DIR-NOTFOUND)
  41. FIND_PATH(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output})
  42. IF(SWIG_DIR)
  43. SET(SWIG_FOUND 1)
  44. SET(SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake)
  45. EXECUTE_PROCESS(COMMAND ${SWIG_EXECUTABLE} -version
  46. OUTPUT_VARIABLE SWIG_version_output
  47. ERROR_VARIABLE SWIG_version_output
  48. RESULT_VARIABLE SWIG_version_result)
  49. IF(SWIG_version_result)
  50. MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
  51. ELSE(SWIG_version_result)
  52. STRING(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
  53. SWIG_version_output "${SWIG_version_output}")
  54. SET(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
  55. ENDIF(SWIG_version_result)
  56. ENDIF(SWIG_DIR)
  57. ENDIF(SWIG_swiglib_result)
  58. ENDIF(SWIG_EXECUTABLE)
  59. IF(NOT SWIG_FOUND)
  60. IF(NOT SWIG_FIND_QUIETLY)
  61. IF(SWIG_FIND_REQUIRED)
  62. MESSAGE(FATAL_ERROR "SWIG was not found. Please specify Swig executable location")
  63. ELSE(SWIG_FIND_REQUIRED)
  64. MESSAGE(STATUS "SWIG was not found. Please specify Swig executable location")
  65. ENDIF(SWIG_FIND_REQUIRED)
  66. ENDIF(NOT SWIG_FIND_QUIETLY)
  67. ENDIF(NOT SWIG_FOUND)