CompilerSettings_linux.cmake 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. if(NOT CMAKE_C_COMPILER AND NOT CMAKE_CXX_COMPILER AND NOT "$ENV{CC}" AND NOT "$ENV{CXX}")
  9. set(path_search
  10. /bin
  11. /usr/bin
  12. /usr/local/bin
  13. /sbin
  14. /usr/sbin
  15. /usr/local/sbin
  16. )
  17. list(TRANSFORM path_search APPEND "/clang-[0-9]*")
  18. file(GLOB clang_versions ${path_search})
  19. if(clang_versions)
  20. # Find and pick the highest installed version
  21. list(SORT clang_versions COMPARE NATURAL)
  22. list(GET clang_versions 0 clang_higher_version_path)
  23. string(REGEX MATCH "clang-([0-9.]*)" clang_higher_version ${clang_higher_version_path})
  24. if(CMAKE_MATCH_1)
  25. set(CMAKE_C_COMPILER clang-${CMAKE_MATCH_1})
  26. set(CMAKE_CXX_COMPILER clang++-${CMAKE_MATCH_1})
  27. else()
  28. message(FATAL_ERROR "Clang not found, please install clang")
  29. endif()
  30. else()
  31. message(FATAL_ERROR "Clang not found, please install clang")
  32. endif()
  33. endif()