blob: e10080d63e49f1273f44cf93187769fe289250e0 [file] [log] [blame]
Piotr Krysik6e9efb02016-04-08 22:54:22 +02001#######################################################################
2# Find the library for SWIG
3#
4# The goal here is to intercept calls to "FIND_PACKAGE(SWIG)" in order
5# to do a global version check locally after passing on the "find" to
6# SWIG-provided scripts.
7########################################################################
8
9# make this file non-reentrant within the current context
10
11if(__INCLUDED_FIND_SWIG_CMAKE)
12 return()
13endif()
14set(__INCLUDED_FIND_SWIG_CMAKE TRUE)
15
16# some status messages
17
18message(STATUS "")
19message(STATUS "Checking for module SWIG")
20
21#
22# First check to see if SWIG installed its own CMake file, or if the
23# one provided by CMake finds SWIG.
24#
25
26# save the current MODULE path
27
28set(SAVED_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
29
30# clear the current MODULE path; uses system paths only
31
32unset(CMAKE_MODULE_PATH)
33
34# try to find SWIG via the provided parameters,
35# handle REQUIRED internally later
36
37unset(SWIG_FOUND)
38
39# was the version specified?
40
41unset(LOCAL_SWIG_FIND_VERSION)
42if(SWIG_FIND_VERSION)
43 set(LOCAL_SWIG_FIND_VERSION ${SWIG_FIND_VERSION})
44endif(SWIG_FIND_VERSION)
45
46# was EXACT specified?
47
48unset(LOCAL_SWIG_FIND_VERSION_EXACT)
49if(SWIG_FIND_VERSION_EXACT)
50 set(LOCAL_SWIG_FIND_VERSION_EXACT "EXACT")
51endif(SWIG_FIND_VERSION_EXACT)
52
53# was REQUIRED specified?
54
55unset(LOCAL_SWIG_FIND_REQUIRED)
56if(SWIG_FIND_REQUIRED)
57 set(LOCAL_SWIG_FIND_REQUIRED "REQUIRED")
58endif(SWIG_FIND_REQUIRED)
59
60# try to find SWIG using the provided parameters, quietly;
61#
62# this call will error out internally (and not quietly) if:
63# 1: EXACT is specified and the version found does not match the requested version;
64# 2: REQUIRED is set and SWIG was not found;
65#
66# this call will return SWIG_FOUND == FALSE if REQUIRED is not set, and:
67# 1: SWIG was not found;
68# 2: The version found is less than the requested version.
69
70find_package(
71 SWIG
72 ${LOCAL_SWIG_FIND_VERSION}
73 ${LOCAL_SWIG_FIND_VERSION_EXACT}
74 ${LOCAL_SWIG_FIND_REQUIRED}
75 QUIET
76)
77
78# restore CMAKE_MODULE_PATH
79
80set(CMAKE_MODULE_PATH ${SAVED_CMAKE_MODULE_PATH})
81
82# specific version checks
83
84set(SWIG_VERSION_CHECK FALSE)
85if(SWIG_FOUND)
86
87 # SWIG was found; make sure the version meets GR's needs
88 message(STATUS "Found SWIG version ${SWIG_VERSION}.")
89 if("${SWIG_VERSION}" VERSION_GREATER "1.3.30")
90 if(NOT "${SWIG_VERSION}" VERSION_EQUAL "3.0.3" AND
91 NOT "${SWIG_VERSION}" VERSION_EQUAL "3.0.4")
92 set(SWIG_VERSION_CHECK TRUE)
93 else()
94 message(STATUS "SWIG versions 3.0.3 and 3.0.4 fail to work with GNU Radio.")
95 endif()
96 else()
97 message(STATUS "Minimum SWIG version required is 1.3.31 for GNU Radio.")
98 endif()
99
100else()
101
102 # SWIG was either not found, or is less than the requested version
103 if(SWIG_VERSION)
104 # SWIG_VERSION is set, but SWIG_FOUND is false; probably a version mismatch
105 message(STATUS "Found SWIG version ${SWIG_VERSION}.")
106 message(STATUS "Requested SWIG version is at least ${SWIG_FIND_VERSION}.")
107 endif()
108endif()
109
110# did the version check fail?
111
112if(NOT SWIG_VERSION_CHECK)
113
114 # yes: clear various variables and set FOUND to FALSE
115 message(STATUS "Disabling SWIG because version check failed.")
116 unset(SWIG_VERSION CACHE)
117 unset(SWIG_DIR CACHE)
118 unset(SWIG_EXECUTABLE CACHE)
119 set(SWIG_FOUND FALSE CACHE BOOL "Set to TRUE if a compatible version of SWIG is found" FORCE)
120
121endif()
122
123# check to see if SWIG variables were set
124
125if(SWIG_FOUND AND SWIG_DIR AND SWIG_EXECUTABLE)
126
127 # yes: even if set SWIG_FOUND==TRUE, then these have already been
128 # done, but done quietly. It does not hurt to redo them here.
129
130 include(FindPackageHandleStandardArgs)
131 find_package_handle_standard_args(SWIG DEFAULT_MSG SWIG_EXECUTABLE SWIG_DIR)
132 mark_as_advanced(SWIG_EXECUTABLE SWIG_DIR)
133
134elseif(SWIG_FIND_REQUIRED)
135
136 if(SWIG_FIND_VERSION)
137 message(FATAL_ERROR "The found SWIG version (${SWIG_VERSION}) is not compatible with the version required (${SWIG_FIND_VERSION}).")
138 else()
139 message(FATAL_ERROR "SWIG is required, but was not found.")
140 endif()
141endif()
Piotr Krysik70c25a12017-01-03 08:01:23 +0100142