Default order for elements found via CMAKE_PREFIX_PATH (and in general any cmake path)
Currently CMAKE_PREFIX_PATH is used to locate a list of subfolders each containing an external component that can be loaded using FIND_PAKAGE. The order of such components is implementation-dependent but it could be useful to specify a specific order.
A typical case is having multiple version of the same package:
libs\libA-1.0
\libB-1.2
\libB-1.4
\libB-1.6
By requesting FIND_PACKAGE(libB CONFIG)
CMAKE will probably return the first library found (version 1.2).
It would be useful if CMAKE could return the latest version, without explicitly specifying it using FIND_PACKAGE(libB 1.6 CONFIG)
This could be accomplished if it could be possible to specify a sorting for elements found in each path of CMAKE_PREFIX_PATH , e.g
SET(CMAKE_PREFIX_PATH_SORT_ORDER [Default | Natural |Last_Modified|Name] ) #proposed
SET(CMAKE_PREFIX_PATH_SORT_DIRECTION [Asc|Dec] ) #proposed
In most of the cases by specifying SET(CMAKE_PREFIX_PATH_SORT_ORDER Natural)
and SET(CMAKE_PREFIX_PATH_SORT_DIRECTION Dec )
it could be possible to recover the latest package version.
The same principle could be applied for similar path lists (e.g. CMAKE_***_PATH).
This isssue is also present at http://stackoverflow.com/questions/39292459/how-to-request-the-greatest-version-with-find-package-in-cmake