summaryrefslogtreecommitdiffstats
path: root/Modules/FindPackageHandleStandardArgs.cmake
diff options
context:
space:
mode:
authorRolf Eike Beer <eike@sf-mail.de>2014-10-03 16:49:00 (GMT)
committerRolf Eike Beer <eike@sf-mail.de>2014-10-07 21:14:45 (GMT)
commit4f9bf4468bd5bcd48be080fa0bc736ebb9df4769 (patch)
treefea00a2bab7f7b936c4910076e3ea6b0224dbca3 /Modules/FindPackageHandleStandardArgs.cmake
parent0e0cb710d03006920bef9d8746e0966a6e48e8fb (diff)
downloadCMake-4f9bf4468bd5bcd48be080fa0bc736ebb9df4769.zip
CMake-4f9bf4468bd5bcd48be080fa0bc736ebb9df4769.tar.gz
CMake-4f9bf4468bd5bcd48be080fa0bc736ebb9df4769.tar.bz2
FPHSA: when EXACT version match is requested only compare the components given
Given that you have a foobar that identifies itself as 1.2.3 from now on a find_package(foobar 1.2 EXACT) will succeed, as 1.2.3 will now be considered as being 1.2. Until now this was only the case for version 1.2.0.
Diffstat (limited to 'Modules/FindPackageHandleStandardArgs.cmake')
-rw-r--r--Modules/FindPackageHandleStandardArgs.cmake36
1 files changed, 32 insertions, 4 deletions
diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake
index e8d1dfb..f6e536b 100644
--- a/Modules/FindPackageHandleStandardArgs.cmake
+++ b/Modules/FindPackageHandleStandardArgs.cmake
@@ -290,12 +290,40 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
if(VERSION)
if(${_NAME}_FIND_VERSION_EXACT) # exact version required
- if (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
- set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
- set(VERSION_OK FALSE)
+ # count the dots in the version string
+ string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${VERSION}")
+ # add one dot because there is one dot more than there are components
+ string(LENGTH "${_VERSION_DOTS}." _VERSION_DOTS)
+ if (_VERSION_DOTS GREATER ${_NAME}_FIND_VERSION_COUNT)
+ # Because of the C++ implementation of find_package() ${_NAME}_FIND_VERSION_COUNT
+ # is at most 4 here. Therefore a simple lookup table is used.
+ if (${_NAME}_FIND_VERSION_COUNT EQUAL 1)
+ set(_VERSION_REGEX "[^.]*")
+ elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 2)
+ set(_VERSION_REGEX "[^.]*\\.[^.]*")
+ elseif (${_NAME}_FIND_VERSION_COUNT EQUAL 3)
+ set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*")
+ else ()
+ set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*")
+ endif ()
+ string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${VERSION}")
+ unset(_VERSION_REGEX)
+ if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _VERSION_HEAD)
+ set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
+ set(VERSION_OK FALSE)
+ else ()
+ set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
+ endif ()
+ unset(_VERSION_HEAD)
else ()
- set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
+ if (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
+ set(VERSION_MSG "Found unsuitable version \"${VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
+ set(VERSION_OK FALSE)
+ else ()
+ set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
+ endif ()
endif ()
+ unset(_VERSION_DOTS)
else() # minimum version specified:
if ("${${_NAME}_FIND_VERSION}" VERSION_GREATER "${VERSION}")