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
8 # The minimum required version of SWIG can be specified using the
9 # standard syntax, e.g. find_package(SWIG 1.1)
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
16 #=============================================================================
17 # Copyright 2004-2009 Kitware, Inc.
18 # Copyright 2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
20 # Distributed under the OSI-approved BSD License (the "License");
21 # see accompanying file Copyright.txt for details.
23 # This software is distributed WITHOUT ANY WARRANTY; without even the
24 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 # See the License for more information.
26 #=============================================================================
27 # (To distribute this file outside of CMake, substitute the full
28 # License text for the above reference.)
30 find_program(SWIG_EXECUTABLE NAMES swig2.0 swig)
33 execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
34 OUTPUT_VARIABLE SWIG_swiglib_output
35 ERROR_VARIABLE SWIG_swiglib_error
36 RESULT_VARIABLE SWIG_swiglib_result)
38 if(SWIG_swiglib_result)
39 if(SWIG_FIND_REQUIRED)
40 message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
42 message(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
45 string(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
46 # force the path to be computed each time in case SWIG_EXECUTABLE has changed.
47 set(SWIG_DIR SWIG_DIR-NOTFOUND)
48 find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output})
50 set(SWIG_USE_FILE ${CMAKE_ROOT}/Modules/UseSWIG.cmake)
51 execute_process(COMMAND ${SWIG_EXECUTABLE} -version
52 OUTPUT_VARIABLE SWIG_version_output
53 ERROR_VARIABLE SWIG_version_output
54 RESULT_VARIABLE SWIG_version_result)
55 if(SWIG_version_result)
56 message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
58 string(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
59 SWIG_version_output "${SWIG_version_output}")
60 set(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
66 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
67 FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWIG REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
68 VERSION_VAR SWIG_VERSION )