You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.9 KiB

  1. #.rst:
  2. # FindSWIG
  3. # --------
  4. #
  5. # Find SWIG
  6. #
  7. # This module finds an installed SWIG. It sets the following variables:
  8. #
  9. # ::
  10. #
  11. # SWIG_FOUND - set to true if SWIG is found
  12. # SWIG_DIR - the directory where swig is installed
  13. # SWIG_EXECUTABLE - the path to the swig executable
  14. # SWIG_VERSION - the version number of the swig executable
  15. #
  16. #
  17. #
  18. # The minimum required version of SWIG can be specified using the
  19. # standard syntax, e.g. find_package(SWIG 1.1)
  20. #
  21. # All information is collected from the SWIG_EXECUTABLE so the version
  22. # to be found can be changed from the command line by means of setting
  23. # SWIG_EXECUTABLE
  24. #=============================================================================
  25. # Copyright 2004-2009 Kitware, Inc.
  26. # Copyright 2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
  27. # Copyright 2014 Sylvain Joubert <joubert.sy@gmail.com>
  28. #
  29. # Redistribution and use in source and binary forms, with or without
  30. # modification, are permitted provided that the following conditions
  31. # are met:
  32. #
  33. # * Redistributions of source code must retain the above copyright
  34. # notice, this list of conditions and the following disclaimer.
  35. #
  36. # * Redistributions in binary form must reproduce the above copyright
  37. # notice, this list of conditions and the following disclaimer in the
  38. # documentation and/or other materials provided with the distribution.
  39. #
  40. # * Neither the names of Kitware, Inc., the Insight Software Consortium,
  41. # nor the names of their contributors may be used to endorse or promote
  42. # products derived from this software without specific prior written
  43. # permission.
  44. #
  45. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  46. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  47. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  48. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  49. # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  50. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  51. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  52. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  53. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  54. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  55. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56. find_program(SWIG_EXECUTABLE NAMES swig4.0 swig3.0 swig2.0 swig)
  57. if(SWIG_EXECUTABLE)
  58. execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
  59. OUTPUT_VARIABLE SWIG_swiglib_output
  60. ERROR_VARIABLE SWIG_swiglib_error
  61. RESULT_VARIABLE SWIG_swiglib_result)
  62. if(SWIG_swiglib_result)
  63. if(SWIG_FIND_REQUIRED)
  64. message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  65. else()
  66. message(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
  67. endif()
  68. else()
  69. string(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
  70. find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output} NO_CMAKE_FIND_ROOT_PATH)
  71. if(SWIG_DIR)
  72. set(SWIG_USE_FILE UseSWIG)
  73. execute_process(COMMAND ${SWIG_EXECUTABLE} -version
  74. OUTPUT_VARIABLE SWIG_version_output
  75. ERROR_VARIABLE SWIG_version_output
  76. RESULT_VARIABLE SWIG_version_result)
  77. if(SWIG_version_result)
  78. message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
  79. else()
  80. string(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
  81. SWIG_version_output "${SWIG_version_output}")
  82. set(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
  83. endif()
  84. endif()
  85. endif()
  86. endif()
  87. include(FindPackageHandleStandardArgs)
  88. FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWIG REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
  89. VERSION_VAR SWIG_VERSION )
  90. mark_as_advanced(SWIG_DIR SWIG_VERSION)