From fbec7907a88d577a63b165accf231058a89bf744 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 22 Apr 2025 13:18:14 +0200 Subject: [PATCH] [CMake] Get Clang directory from `CLANG_INSTALL_PREFIX` If Clang was installed standalone (in particular, not in the LLVM tree), use the CLANG_INSTALL_PREFIX variable to indicate where it is. Actually, we can always use `CLANG_INSTALL_PREFIX`. It's defined by `ClangConfig.cmake`. To make sure that this works, `find_package(Clang)` has to be called in `core/clingutils/CMakeLists.txt`. --- core/clingutils/CMakeLists.txt | 2 +- interpreter/CMakeLists.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/clingutils/CMakeLists.txt b/core/clingutils/CMakeLists.txt index 493c89e89141d..99342dc4b16df 100644 --- a/core/clingutils/CMakeLists.txt +++ b/core/clingutils/CMakeLists.txt @@ -85,7 +85,7 @@ if (builtin_clang) set(CLANG_RESOURCE_DIR_STEM ${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}/clang) set(CLANG_RESOURCE_DIR_VERSION ${LLVM_VERSION_MAJOR}) else () - set(CLANG_RESOURCE_DIR_STEM ${LLVM_LIBRARY_DIR}/clang) + set(CLANG_RESOURCE_DIR_STEM ${CLANG_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}/clang) # A user can define a clang version to use, otherwise find it (but will error if more than one version is present) if (NOT DEFINED CLANG_RESOURCE_DIR_VERSION) if (NOT EXISTS ${CLANG_RESOURCE_DIR_STEM}) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 4f5a3d2adddda..a4fc805ce41b5 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -408,6 +408,9 @@ if (builtin_clang) else() find_package(Clang REQUIRED CONFIG) message(STATUS "Found Clang ${CLANG_PACKAGE_VERSION} in ${CLANG_CMAKE_DIR}") + + # Forward CLANG_INSTALL_PREFIX so it can be used by core/clingutils/CMakeLists.txt + set(CLANG_INSTALL_PREFIX ${CLANG_INSTALL_PREFIX} PARENT_SCOPE) endif() # Reset the compiler flags after compiling LLVM and Clang