From 4fa1ded456626f9c13f1f77212754d6349d12a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Gr=C3=BCninger?= Date: Tue, 27 Feb 2024 21:14:19 +0100 Subject: [PATCH] [cmake] Adjust for non-installed LLVM In LLVM 16 llvm-config got --src-root removed. Adjust include path for Clang include --- cmake/FindClang.cmake | 8 ++++++-- cmake/FindLLVM.cmake | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmake/FindClang.cmake b/cmake/FindClang.cmake index e438ea5c..b4f0b0a1 100644 --- a/cmake/FindClang.cmake +++ b/cmake/FindClang.cmake @@ -86,8 +86,12 @@ if(CLANG_FOUND) set(CLANG_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) # check whether llvm-config comes from an install prefix + set(LLVM_CONFIG_INCLUDE_FLAG "--src-root") + if (${LLVM_VERSION} VERSION_GREATER_EQUAL 16) + set(LLVM_CONFIG_INCLUDE_FLAG "--includedir") + endif() execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root + COMMAND ${LLVM_CONFIG_EXECUTABLE} ${LLVM_CONFIG_INCLUDE_FLAG} OUTPUT_VARIABLE _llvmSourceRoot OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -96,7 +100,7 @@ if(CLANG_FOUND) message(STATUS "Detected that llvm-config comes from a build-tree, adding more include directories for Clang") list(APPEND CLANG_INCLUDE_DIRS "${LLVM_INSTALL_PREFIX}/tools/clang/include" # build dir - "${_llvmSourceRoot}/tools/clang/include" # source dir + "${_llvmSourceRoot}/../../clang/include" # source dir ) endif() diff --git a/cmake/FindLLVM.cmake b/cmake/FindLLVM.cmake index da02e006..c625eeb5 100644 --- a/cmake/FindLLVM.cmake +++ b/cmake/FindLLVM.cmake @@ -131,8 +131,12 @@ if (LLVM_FOUND) endif() # potentially add include dir from binary dir for non-installed LLVM + set(LLVM_CONFIG_INCLUDE_FLAG "--src-root") + if (${LLVM_VERSION} VERSION_GREATER_EQUAL 16) + set(LLVM_CONFIG_INCLUDE_FLAG "--includedir") + endif() execute_process( - COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root + COMMAND ${LLVM_CONFIG_EXECUTABLE} ${LLVM_CONFIG_INCLUDE_FLAG} OUTPUT_VARIABLE _llvmSourceRoot OUTPUT_STRIP_TRAILING_WHITESPACE ) -- GitLab