1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

FindSWIG: Fix syntax error

Add some tests to cover all cases regarding version handling

Fixes: #21264
This commit is contained in:
Marc Chevrier
2020-10-02 16:17:36 +02:00
parent 3ec0f9d620
commit 127436192d
4 changed files with 31 additions and 1 deletions

View File

@@ -56,8 +56,8 @@ optional Fortran support:
#]=======================================================================]
# compute list of possible names
unset (_SWIG_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)
@@ -73,10 +73,15 @@ elseif(SWIG_FIND_VERSION)
if (_SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MAJOR)
list (APPEND _SWIG_NAMES swig${_SWIG_MAJOR}.0)
endif()
endforeach()
endif()
else()
set (_SWIG_NAMES swig4.0 swig3.0 swig2.0)
endif()
if (NOT _SWIG_NAMES)
# try to find any version
set (_SWIG_NAMES swig4.0 swig3.0 swig2.0)
endif()
find_program(SWIG_EXECUTABLE NAMES ${_SWIG_NAMES} swig)

View File

@@ -2,4 +2,6 @@ include(RunCMake)
run_cmake(components)
run_cmake(missing-components)
run_cmake(version)
run_cmake(version-exact)
run_cmake(version-range)

View File

@@ -0,0 +1,17 @@
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)
set (version ${SWIG_VERSION})
find_package (SWIG ${SWIG_VERSION} EXACT)
if (NOT SWIG_FOUND)
message (FATAL_ERROR "Failed to find SWIG with version ${version} EXACT")
endif()

View File

@@ -0,0 +1,6 @@
cmake_minimum_required (VERSION 3.18...3.19)
find_package (SWIG 1.0)
if (NOT SWIG_FOUND)
message (FATAL_ERROR "Failed to find SWIG with version 1.0")
endif()