mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-01 20:00:51 -05:00
FindSWIG: Add version range support
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
FindSWIG-version-range
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
* :module:`FindSWIG` module gains the capability to manage a version range.
|
||||||
+35
-6
@@ -7,11 +7,16 @@ FindSWIG
|
|||||||
|
|
||||||
Find the Simplified Wrapper and Interface Generator (SWIG_) executable.
|
Find the Simplified Wrapper and Interface Generator (SWIG_) executable.
|
||||||
|
|
||||||
|
|
||||||
This module finds an installed SWIG and determines its version. If a
|
This module finds an installed SWIG and determines its version. If a
|
||||||
``COMPONENTS`` or ``OPTIONAL_COMPONENTS`` argument is given to ``find_package``,
|
``COMPONENTS`` or ``OPTIONAL_COMPONENTS`` argument is given to the
|
||||||
it will also determine supported target languages. The module sents the
|
:command:`find_package` command, it will also determine supported target
|
||||||
following variables:
|
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``
|
``SWIG_FOUND``
|
||||||
Whether SWIG and any required components were found on the system.
|
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)
|
if(SWIG_EXECUTABLE)
|
||||||
execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
|
execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
|
||||||
@@ -105,6 +133,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
|||||||
find_package_handle_standard_args(
|
find_package_handle_standard_args(
|
||||||
SWIG HANDLE_COMPONENTS
|
SWIG HANDLE_COMPONENTS
|
||||||
REQUIRED_VARS SWIG_EXECUTABLE SWIG_DIR
|
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)
|
mark_as_advanced(SWIG_DIR SWIG_VERSION SWIG_EXECUTABLE)
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ include(RunCMake)
|
|||||||
|
|
||||||
run_cmake(components)
|
run_cmake(components)
|
||||||
run_cmake(missing-components)
|
run_cmake(missing-components)
|
||||||
|
run_cmake(version-range)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
cmake_minimum_required (VERSION 3.18...3.19)
|
||||||
|
|
||||||
|
find_package (SWIG)
|
||||||
|
if (NOT SWIG_FOUND)
|
||||||
|
message (FATAL_ERROR "Failed to find SWIG")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# clean-up SWIG variables
|
||||||
|
unset (SWIG_EXECUTABLE CACHE)
|
||||||
|
unset (SWIG_DIR CACHE)
|
||||||
|
|
||||||
|
## Specify a range including current SWIG version
|
||||||
|
string (REGEX MATCH "^([0-9]+)" upper_version "${SWIG_VERSION}")
|
||||||
|
math (EXPR upper_version "${upper_version} + 1")
|
||||||
|
|
||||||
|
find_package (SWIG 1.0...${upper_version}.0)
|
||||||
|
if (NOT SWIG_FOUND)
|
||||||
|
message (FATAL_ERROR "Failed to find SWIG with version range 1.0...${upper_version}.0")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# clean-up SWIG variables
|
||||||
|
unset (SWIG_EXECUTABLE CACHE)
|
||||||
|
unset (SWIG_DIR CACHE)
|
||||||
|
|
||||||
|
## Specify a range excluding current SWIG version
|
||||||
|
set (range 1.0...<${SWIG_VERSION})
|
||||||
|
find_package (SWIG ${range})
|
||||||
|
if (SWIG_FOUND)
|
||||||
|
message (FATAL_ERROR "Unexpectedly find SWIG with version range ${range}")
|
||||||
|
endif()
|
||||||
Reference in New Issue
Block a user