cmake/Modules/FindSWIG.cmake

78 lines
2.9 KiB
CMake
Raw Normal View History

2014-08-03 19:52:23 +02:00
#.rst:
# FindSWIG
# --------
#
# Find SWIG
#
# This module finds an installed SWIG. It sets the following variables:
#
2014-08-03 19:52:23 +02:00
# ::
#
# SWIG_FOUND - set to true if SWIG is found
# SWIG_DIR - the directory where swig is installed
# SWIG_EXECUTABLE - the path to the swig executable
# SWIG_VERSION - the version number of the swig executable
2010-11-13 01:00:53 +02:00
#
#
2014-08-03 19:52:23 +02:00
#
# The minimum required version of SWIG can be specified using the
# standard syntax, e.g. find_package(SWIG 1.1)
#
# All information is collected from the SWIG_EXECUTABLE so the version
# to be found can be changed from the command line by means of setting
# SWIG_EXECUTABLE
2009-10-04 10:30:41 +03:00
#=============================================================================
# Copyright 2004-2009 Kitware, Inc.
2011-06-19 15:41:06 +03:00
# Copyright 2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
2009-10-04 10:30:41 +03:00
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
2010-11-13 01:00:53 +02:00
# (To distribute this file outside of CMake, substitute the full
2009-10-04 10:30:41 +03:00
# License text for the above reference.)
2013-03-16 19:13:01 +02:00
find_program(SWIG_EXECUTABLE NAMES swig2.0 swig)
2013-03-16 19:13:01 +02:00
if(SWIG_EXECUTABLE)
execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
OUTPUT_VARIABLE SWIG_swiglib_output
ERROR_VARIABLE SWIG_swiglib_error
RESULT_VARIABLE SWIG_swiglib_result)
2013-03-16 19:13:01 +02:00
if(SWIG_swiglib_result)
if(SWIG_FIND_REQUIRED)
message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
else()
message(STATUS "Command \"${SWIG_EXECUTABLE} -swiglib\" failed with output:\n${SWIG_swiglib_error}")
endif()
else()
string(REGEX REPLACE "[\n\r]+" ";" SWIG_swiglib_output ${SWIG_swiglib_output})
2014-08-03 19:52:23 +02:00
find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output} NO_CMAKE_FIND_ROOT_PATH)
2013-03-16 19:13:01 +02:00
if(SWIG_DIR)
2014-08-03 19:52:23 +02:00
set(SWIG_USE_FILE ${CMAKE_CURRENT_LIST_DIR}/UseSWIG.cmake)
2013-03-16 19:13:01 +02:00
execute_process(COMMAND ${SWIG_EXECUTABLE} -version
OUTPUT_VARIABLE SWIG_version_output
ERROR_VARIABLE SWIG_version_output
RESULT_VARIABLE SWIG_version_result)
2013-03-16 19:13:01 +02:00
if(SWIG_version_result)
message(SEND_ERROR "Command \"${SWIG_EXECUTABLE} -version\" failed with output:\n${SWIG_version_output}")
else()
string(REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
SWIG_version_output "${SWIG_version_output}")
2013-03-16 19:13:01 +02:00
set(SWIG_VERSION ${SWIG_version_output} CACHE STRING "Swig version" FORCE)
endif()
endif()
endif()
endif()
2013-03-16 19:13:01 +02:00
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
2010-11-13 01:00:53 +02:00
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SWIG REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
VERSION_VAR SWIG_VERSION )
2014-08-03 19:52:23 +02:00
mark_as_advanced(SWIG_DIR SWIG_VERSION)