cmake/Help/variable/CMAKE_FIND_PACKAGE_SORT_ORDER.rst

42 lines
1.3 KiB
ReStructuredText
Raw Normal View History

2016-10-30 18:24:19 +01:00
CMAKE_FIND_PACKAGE_SORT_ORDER
-----------------------------
2021-09-14 00:13:48 +02:00
.. versionadded:: 3.7
2024-11-11 15:18:55 +01:00
The default order for sorting directories which match a search path containing
a glob expression found using :command:`find_package`. It can assume one of
the following values:
2016-10-30 18:24:19 +01:00
``NONE``
2024-11-11 15:18:55 +01:00
Default. No attempt is done to sort directories.
2016-10-30 18:24:19 +01:00
The first valid package found will be selected.
``NAME``
2024-11-11 15:18:55 +01:00
Sort directories lexicographically before searching.
2016-10-30 18:24:19 +01:00
``NATURAL``
2024-11-11 15:18:55 +01:00
Sort directories using natural order (see ``strverscmp(3)`` manual),
2016-10-30 18:24:19 +01:00
i.e. such that contiguous digits are compared as whole numbers.
Natural sorting can be employed to return the highest version when multiple
2024-11-11 15:18:55 +01:00
versions of the same library are available to be found by
:command:`find_package`. For example suppose that the following libraries
have package configuration files on disk, in a directory of the same name,
with all such directories residing in the same parent directory:
2016-10-30 18:24:19 +01:00
* libX-1.1.0
* libX-1.2.9
* libX-1.2.10
By setting ``NATURAL`` order we can select the one with the highest
version number ``libX-1.2.10``.
.. code-block:: cmake
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
find_package(libX CONFIG)
The sort direction can be controlled using the
:variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION` variable
2024-11-11 15:18:55 +01:00
(by default descending, e.g. lib-B will be tested before lib-A).