From abc1ae538fee14af12bb5ffd35024d96da861961 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Mon, 25 Jul 2022 10:29:38 -0700 Subject: [PATCH] CMake: Search for Clang in CMAKE_LIBRARY_PATH, CMAKE_PREFIX_PATH, and CMAKE_FRAMEWORK_PATH On some systems (esp. systems that use unique hashed file-paths for library-versions like Nix), we can't expect LLVM and Clang to share lib/bin directories. The best we can do is find the matching clang libraries in the CMAKE_LIBRARY_PATH provided by the environment --- cmake/Findclang.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmake/Findclang.cmake b/cmake/Findclang.cmake index d2b898a74a..8fd1a202e1 100644 --- a/cmake/Findclang.cmake +++ b/cmake/Findclang.cmake @@ -9,7 +9,9 @@ find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h HINTS ${LLVM_INCLUDE_DIRS} - NO_DEFAULT_PATH # Only look for clang next to LLVM + # Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH } + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH ) if(${LLVM_LINK_MODE} STREQUAL "shared") @@ -21,14 +23,18 @@ if(${LLVM_LINK_MODE} STREQUAL "shared") clang-cpp NAMES_PER_DIR HINTS "${LLVM_LIBDIRS}" - NO_DEFAULT_PATH # Only look for Clang next to LLVM + # Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH } + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH ) else() macro(FIND_AND_ADD_CLANG_LIB _libname_) string(TOUPPER ${_libname_} _prettylibname_) find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR HINTS "${LLVM_LIBDIRS}" - NO_DEFAULT_PATH # Only look for Clang next to LLVM + # Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH } + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH ) if(CLANG_${_prettylibname_}_LIB) set(CLANG_LIBRARIES ${CLANG_LIBRARIES} ${CLANG_${_prettylibname_}_LIB})