From fd2a81afb1934efce56075ea54e0a7e45da2ed3b Mon Sep 17 00:00:00 2001 From: niedlich <119812620+hyperpastel@users.noreply.github.com> Date: Wed, 23 Apr 2025 11:41:26 +0200 Subject: [PATCH] Improved CMake integration of LLVM (#2103) Added the paths for the CMake config files for LLVM 19 and higher to ``CMAKE_PREFIX_PATH``, so that they will also be searched automatically. --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3c0d6a73..680e08c8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,6 +144,20 @@ if(C3_WITH_LLVM) find_package(LLVM REQUIRED CONFIG) find_package(LLD REQUIRED CONFIG) else() + # Add paths for LLVM CMake files of version 19 and higher as they follow a new installation + # layout and are now in /usr/lib/llvm/*/lib/cmake/llvm/ rather than /usr/lib/cmake/llvm/ + # + # Because of CMAKE_FIND_PACKAGE_SORT_ORDER CMAKE_FIND_PACKAGE_SORT_DIRECTION, + # the newest version will always be found first. + message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") + if (DEFINED LLVM_DIR) + message(STATUS "Looking for LLVM CMake files in user-specified directory ${LLVM_DIR}") + else() + file (GLOB LLVM_CMAKE_PATHS "/usr/lib/llvm/*/lib/cmake/llvm/") + list (APPEND CMAKE_PREFIX_PATH ${LLVM_CMAKE_PATHS} "/usr/lib/") + message(STATUS "No LLVM_DIR specified, searching default directories ${CMAKE_PREFIX_PATH}") + endif() + if (NOT C3_LLVM_VERSION STREQUAL "auto") find_package(LLVM ${C3_LLVM_VERSION} REQUIRED CONFIG) else()