4392c8963c
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>
35 lines
1.2 KiB
CMake
35 lines
1.2 KiB
CMake
#
|
|
# Copyright (c) Contributors to the Open 3D Engine Project.
|
|
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
#
|
|
#
|
|
|
|
if(NOT CMAKE_C_COMPILER AND NOT CMAKE_CXX_COMPILER AND NOT "$ENV{CC}" AND NOT "$ENV{CXX}")
|
|
set(path_search
|
|
/bin
|
|
/usr/bin
|
|
/usr/local/bin
|
|
/sbin
|
|
/usr/sbin
|
|
/usr/local/sbin
|
|
)
|
|
list(TRANSFORM path_search APPEND "/clang-[0-9]*")
|
|
file(GLOB clang_versions ${path_search})
|
|
if(clang_versions)
|
|
# Find and pick the highest installed version
|
|
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)
|
|
set(CMAKE_C_COMPILER clang-${CMAKE_MATCH_1})
|
|
set(CMAKE_CXX_COMPILER clang++-${CMAKE_MATCH_1})
|
|
else()
|
|
message(FATAL_ERROR "Clang not found, please install clang")
|
|
endif()
|
|
else()
|
|
message(FATAL_ERROR "Clang not found, please install clang")
|
|
endif()
|
|
endif()
|