FindSWIG.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # Copyright 2011 Mathieu Malaterre <[email protected]>
  18. #
  19. # Distributed under the OSI-approved BSD License (the "License");
  20. # see accompanying file Copyright.txt for details.
  21. #
  22. # This software is distributed WITHOUT ANY WARRANTY; without even the
  23. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. # See the License for more information.
  25. #=============================================================================
  26. # (To distribute this file outside of CMake, substitute the full
  27. # License text for the above reference.)
  28. FIND_PROGRAM(SWIG_EXECUTABLE NAMES swig2.0 swig)
  29. IF(SWIG_EXECUTABLE)
  30. EXECUTE_PROCESS(COMMAND ${SWIG_EXECUTABLE} -swiglib
  31. OUTPUT_VARIABLE SWIG_swiglib_output
  32. ERROR_VARIABLE SWIG_swiglib_error
  33. RESULT_VARIABLE SWIG_swiglib_result)
  34. IF(SWIG_swiglib_result)
  35. IF(SWIG_FIND_REQUIRED)
  36. MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  37. ELSE(SWIG_FIND_REQUIRED)
  38. MESSAGE(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  39. ENDIF(SWIG_FIND_REQUIRED)
  40. ELSE(SWIG_swiglib_result)
  41. STRING(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
  42. # force the path to be computed each time in case SWIG_EXECUTABLE has changed.
  43. SET(SWIG_DIR SWIG_DIR-NOTFOUND)
  44. FIND_PATH(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output})
  45. IF(SWIG_DIR)
  46. SET(SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake)
  47. EXECUTE_PROCESS(COMMAND ${SWIG_EXECUTABLE} -version
  48. OUTPUT_VARIABLE SWIG_version_output
  49. ERROR_VARIABLE SWIG_version_output
  50. RESULT_VARIABLE SWIG_version_result)
  51. IF(SWIG_version_result)
  52. MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
  53. ELSE(SWIG_version_result)
  54. STRING(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
  55. SWIG_version_output "${SWIG_version_output}")
  56. SET(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
  57. ENDIF(SWIG_version_result)
  58. ENDIF(SWIG_DIR)
  59. ENDIF(SWIG_swiglib_result)
  60. ENDIF(SWIG_EXECUTABLE)
  61. INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  62. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWIG REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
  63. VERSION_VAR SWIG_VERSION )