FindSWIG.cmake 2.2 KB

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