summaryrefslogtreecommitdiff
path: root/Modules/FindSWIG.cmake
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-09-30 19:18:34 +0200
committerMarc Chevrier <marc.chevrier@gmail.com>2020-10-01 12:00:29 +0200
commit1d300ee2a9f51e08d4006191e2d50fd5771af202 (patch)
treec475aca47b7269dd7fcd1c523866b1c5de301c37 /Modules/FindSWIG.cmake
parent47b569a85852f716b05ede538e9940392407316c (diff)
downloadcmake-1d300ee2a9f51e08d4006191e2d50fd5771af202.tar.gz
FindSWIG: Add version range support
Diffstat (limited to 'Modules/FindSWIG.cmake')
-rw-r--r--Modules/FindSWIG.cmake41
1 files changed, 35 insertions, 6 deletions
diff --git a/Modules/FindSWIG.cmake b/Modules/FindSWIG.cmake
index 2fded4985b..f7322895e0 100644
--- a/Modules/FindSWIG.cmake
+++ b/Modules/FindSWIG.cmake
@@ -7,11 +7,16 @@ FindSWIG
Find the Simplified Wrapper and Interface Generator (SWIG_) executable.
-
This module finds an installed SWIG and determines its version. If a
-``COMPONENTS`` or ``OPTIONAL_COMPONENTS`` argument is given to ``find_package``,
-it will also determine supported target languages. The module sents the
-following variables:
+``COMPONENTS`` or ``OPTIONAL_COMPONENTS`` argument is given to the
+:command:`find_package` command, it will also determine supported target
+languages.
+
+When a version is requested, it can be specified as a simple value or as a
+range. For a detailed description of version range usage and capabilities,
+refer to the :command:`find_package` command.
+
+The module defines the following variables:
``SWIG_FOUND``
Whether SWIG and any required components were found on the system.
@@ -50,7 +55,30 @@ optional Fortran support:
#]=======================================================================]
-find_program(SWIG_EXECUTABLE NAMES swig4.0 swig3.0 swig2.0 swig)
+# compute list of possible names
+if (SWIG_FIND_VERSION_RANGE)
+ set (_SWIG_NAMES)
+ foreach (_SWIG_MAJOR IN ITEMS 4 3 2)
+ if (_SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MIN_MAJOR
+ AND ((SWIG_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND _SWIG_MAJOR VERSION_LESS_EQUAL SWIG_FIND_VERSION_MAX)
+ OR (SWIG_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND _SWIG_MAJOR VERSION_LESS SWIG_FIND_VERSION_MAX)))
+ list (APPEND _SWIG_NAMES swig${_SWIG_MAJOR}.0)
+ endif()
+ endforeach()
+elseif(SWIG_FIND_VERSION)
+ if (SWIG_FIND_VERSION_EXACT)
+ set(_SWIG_NAMES swig${SWIG_FIND_VERSION_MAJOR}.0)
+ else()
+ foreach (_SWIG_MAJOR IN ITEMS 4 3 2)
+ if (_SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MAJOR)
+ list (APPEND _SWIG_NAMES swig${_SWIG_MAJOR}.0)
+ endif()
+ endif()
+else()
+ set (_SWIG_NAMES swig4.0 swig3.0 swig2.0)
+endif()
+
+find_program(SWIG_EXECUTABLE NAMES ${_SWIG_NAMES} swig)
if(SWIG_EXECUTABLE)
execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
@@ -105,6 +133,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(
SWIG HANDLE_COMPONENTS
REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
- VERSION_VAR SWIG_VERSION)
+ VERSION_VAR SWIG_VERSION
+ HANDLE_VERSION_RANGE)
mark_as_advanced(SWIG_DIR SWIG_VERSION SWIG_EXECUTABLE)