Brad King wrote:
> On 10/03/2014 11:53 AM, Rolf Eike Beer wrote:
> > It looks like this line is the culprit:
> > if (NOT "${${_NAME}_FIND_VERSION}" VERSION_EQUAL "${VERSION}")
> >
> > I can solve this in CMake language, but the question is again if it may be
> > worth solving in the command itself? Meanwhile I'll prepare an
> > implementation in CMake code, we can replace that with anything better
> > anytime later.
> Yes, I think the command should be fixed to compare only as many
> components as are given on both sides, ignoring extra on one side.
> However, that will require a policy.
>
> Please fix it in the module by hand for now and look at adding a
> policy for this after the 3.1 release.
Yes, that was my plan. This is what I have now (diff -b for easier review):
diff --git a/Modules/FindPackageHandleStandardArgs.cmake
b/Modules/FindPackageHandleStandardArgs.cmake
index e8d1dfb..f8c990e 100644
--- a/Modules/FindPackageHandleStandardArgs.cmake
+++ b/Modules/FindPackageHandleStandardArgs.cmake
@@ -290,12 +290,38 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME
_FIRST_ARG)
if(VERSION)
if(${_NAME}_FIND_VERSION_EXACT) # exact version required
+ # 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)
+ # give an exact match if the first ${NAME}_FIND_VERSION_COUNT
components of the version string match
+ # this constructs the equivalent of
"(([^.]\\.){${${_NAME}_FIND_VERSION_COUNT}})"
+ unset(_VERSION_REGEX)
+ # foreach(RANGE) doesn't like it if stop is greater start
+ if (${${_NAME}_FIND_VERSION_COUNT} GREATER 1)
+ foreach (_NUM RANGE 2 ${${_NAME}_FIND_VERSION_COUNT})
+ set(_VERSION_REGEX "${_VERSION_REGEX}[^.]*\\.")
+ endforeach ()
+ 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 ()
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}")
Eike
--
signature.asc
Description: This is a digitally signed message part.
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers
