FindSWIG.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindSWIG
  5. --------
  6. Find Simplified Wrapper and Interface Generator (SWIG)
  7. This module finds an installed SWIG. It sets the following variables:
  8. ::
  9. SWIG_FOUND - set to "True" if SWIG is found
  10. SWIG_DIR - the directory where swig is installed
  11. SWIG_EXECUTABLE - the path to the swig executable
  12. SWIG_VERSION - the version number of the swig executable
  13. The minimum required version of SWIG can be specified using the
  14. standard syntax, e.g. :command:`find_package(SWIG 1.1)`
  15. All information is collected from the ``SWIG_EXECUTABLE``, so the version
  16. to be found can be changed from the command line by means of setting
  17. ``SWIG_EXECUTABLE``
  18. #]=======================================================================]
  19. find_program(SWIG_EXECUTABLE NAMES swig4.0 swig3.0 swig2.0 swig)
  20. if(SWIG_EXECUTABLE)
  21. execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
  22. OUTPUT_VARIABLE SWIG_swiglib_output
  23. ERROR_VARIABLE SWIG_swiglib_error
  24. RESULT_VARIABLE SWIG_swiglib_result)
  25. if(SWIG_swiglib_result)
  26. if(SWIG_FIND_REQUIRED)
  27. message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  28. else()
  29. message(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  30. endif()
  31. else()
  32. string(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
  33. find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output} NO_CMAKE_FIND_ROOT_PATH)
  34. if(SWIG_DIR)
  35. set(SWIG_USE_FILE ${CMAKE_CURRENT_LIST_DIR}/UseSWIG.cmake)
  36. execute_process(COMMAND ${SWIG_EXECUTABLE} -version
  37. OUTPUT_VARIABLE SWIG_version_output
  38. ERROR_VARIABLE SWIG_version_output
  39. RESULT_VARIABLE SWIG_version_result)
  40. if(SWIG_version_result)
  41. message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
  42. else()
  43. string(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
  44. SWIG_version_output "${SWIG_version_output}")
  45. set(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
  46. endif()
  47. endif()
  48. endif()
  49. endif()
  50. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  51. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWIG REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
  52. VERSION_VAR SWIG_VERSION )
  53. mark_as_advanced(SWIG_DIR SWIG_VERSION SWIG_EXECUTABLE)