Skip to content

Adding support for FIND_PACKAGE_SORT_{ORDER, DIRECTION}

Pierluigi Taddei requested to merge pigei/cmake:master into master

When multiple package with the same name have been found in the same location sorting option can be used to force a specific version to be loaded (e.g libA_1.10.0 instead of libA_1.2.0) Currently sorting by NAME and by NATURAL order have been implemented.

When cmFindPackageCommand is created it looks for the two variables FIND_PACKAGE_SORT_ORDER and FIND_PACKAGE_SORT_DIRECTION. These can have the following values:

FIND_PACKAGE_SORT_ORDER : NONE, NAME, NATURAL
FIND_PACKAGE_SORT_DIRECTION : ASC, DEC

Currently sorting by Name and by Natural order have been implemented.

Natural ordering makes use of strverscmp now implemented in cmSystemTools

For example suppose that the lib folder contains:

\libs
  \libA_1.2.0
  \libA_1.10.0

the following CMAKE script can be used to detect the greatest version for libA:

SET(CMAKE_PREFIX_PATH "\libs")

SET(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
FIND_PACKAGE(libA CONFIG)

Merge request reports