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