FindSWIG.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. SET(SWIG_FOUND FALSE)
  13. FIND_PROGRAM(SWIG_EXECUTABLE swig)
  14. IF(SWIG_EXECUTABLE)
  15. EXECUTE_PROCESS(COMMAND ${SWIG_EXECUTABLE} -swiglib
  16. OUTPUT_VARIABLE SWIG_swiglib_output
  17. ERROR_VARIABLE SWIG_swiglib_error
  18. RESULT_VARIABLE SWIG_swiglib_result)
  19. IF(SWIG_swiglib_result)
  20. IF(SWIG_FIND_REQUIRED)
  21. MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  22. ELSE(SWIG_FIND_REQUIRED)
  23. MESSAGE(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  24. ENDIF(SWIG_FIND_REQUIRED)
  25. ELSE(SWIG_swiglib_result)
  26. STRING(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
  27. # force the path to be computed each time in case SWIG_EXECUTABLE has changed.
  28. SET(SWIG_DIR SWIG_DIR-NOTFOUND)
  29. FIND_PATH(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output})
  30. IF(SWIG_DIR)
  31. SET(SWIG_FOUND 1)
  32. SET(SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake)
  33. EXECUTE_PROCESS(COMMAND ${SWIG_EXECUTABLE} -version
  34. OUTPUT_VARIABLE SWIG_version_output
  35. ERROR_VARIABLE SWIG_version_output
  36. RESULT_VARIABLE SWIG_version_result)
  37. IF(SWIG_version_result)
  38. MESSAGE(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
  39. ELSE(SWIG_version_result)
  40. STRING(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
  41. SWIG_version_output "${SWIG_version_output}")
  42. SET(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
  43. ENDIF(SWIG_version_result)
  44. ENDIF(SWIG_DIR)
  45. ENDIF(SWIG_swiglib_result)
  46. ENDIF(SWIG_EXECUTABLE)
  47. IF(NOT SWIG_FOUND)
  48. IF(NOT SWIG_FIND_QUIETLY)
  49. IF(SWIG_FIND_REQUIRED)
  50. MESSAGE(FATAL_ERROR "SWIG was not found. Please specify Swig executable location")
  51. ELSE(SWIG_FIND_REQUIRED)
  52. MESSAGE(STATUS "SWIG was not found. Please specify Swig executable location")
  53. ENDIF(SWIG_FIND_REQUIRED)
  54. ENDIF(NOT SWIG_FIND_QUIETLY)
  55. ENDIF(NOT SWIG_FOUND)