[Linux] Prefer higher versioned clang compilers to lower versions (#6824)

If the user does not specify which compiler to use via cache variables in
the CMake invocation, we perform a search for which version to use.
Previously this was done using a glob search on some pre-defined paths, and
then sorting the results using `list(SORT ... COMPARE NATURAL)`. Sorting in
this manner results in lower versions being moved to the head of the list.
The first result in the list was then used. Consequently, if the user has
`clang-11` and `clang-12` installed, `clang-11` was chosen.

This reverses the sort order so that the highest installed version is
chosen.

Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
Chris Burel
2022-01-14 09:00:26 -08:00
committed by GitHub
parent e1572ce5c9
commit 4392c8963c
@@ -19,7 +19,7 @@ if(NOT CMAKE_C_COMPILER AND NOT CMAKE_CXX_COMPILER AND NOT "$ENV{CC}" AND NOT "$
file(GLOB clang_versions ${path_search})
if(clang_versions)
# Find and pick the highest installed version
list(SORT clang_versions COMPARE NATURAL)
list(SORT clang_versions COMPARE NATURAL ORDER DESCENDING)
list(GET clang_versions 0 clang_higher_version_path)
string(REGEX MATCH "clang-([0-9.]*)" clang_higher_version ${clang_higher_version_path})
if(CMAKE_MATCH_1)