diff options
author | Brad King <brad.king@kitware.com> | 2014-10-08 14:48:14 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-10-08 14:48:14 (GMT) |
commit | b3cbb9e1888494a4d5b7cdc617ef2654d7c7ab98 (patch) | |
tree | 9fdbea7b33b2e23078523656253e53fa74840b09 /Modules | |
parent | ec941fc04bf4facc7ffe45142351126262fdddee (diff) | |
parent | ba907f7dc21163df29872a221dfeae18379319c6 (diff) | |
download | CMake-b3cbb9e1888494a4d5b7cdc617ef2654d7c7ab98.zip CMake-b3cbb9e1888494a4d5b7cdc617ef2654d7c7ab98.tar.gz CMake-b3cbb9e1888494a4d5b7cdc617ef2654d7c7ab98.tar.bz2 |
Merge topic 'FPHSA_exact_version'
ba907f7d FPHSA: fix when requested or found version is exactly 0
4f9bf446 FPHSA: when EXACT version match is requested only compare the components given
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindPackageHandleStandardArgs.cmake | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index e8d1dfb..23f3f05 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -284,18 +284,47 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # version handling: set(VERSION_MSG "") set(VERSION_OK TRUE) - set(VERSION ${${FPHSA_VERSION_VAR}} ) - if (${_NAME}_FIND_VERSION) + set(VERSION ${${FPHSA_VERSION_VAR}}) - if(VERSION) + # check with DEFINED here as the requested or found version may be "0" + if (DEFINED ${_NAME}_FIND_VERSION) + if(DEFINED ${FPHSA_VERSION_VAR}) 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}") |