[cmake-developers] Improving the version selection behavior of EXACT

Brad King brad.king at kitware.com
Fri Oct 3 14:34:38 EDT 2014


On 10/03/2014 12:47 PM, Rolf Eike Beer wrote:
> +          # 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 ()

Since _FIND_VERSION_COUNT is always [0-4], I think a hand-coded lookup
table may be simpler and faster.

> +          string(REGEX REPLACE "^(${_VERSION_REGEX}[^.]*)\\..*" "\\1" _VERSION_HEAD "${VERSION}")

Perhaps use something like

 if(VERSION MATCHES "^(${_VERSION_REGEX}[^.]*)\\..*")
   set(_VERSION_HEAD "${CMAKE_MATCH_1}")
 else()
   message(... bad VERSION in call to fphsa...)
 endif()

in case something fails to match for some reason.

Thanks,
-Brad




More information about the cmake-developers mailing list