Skip to content

Commit 0366d4d

Browse files
committed
Fix LLVM find package picking up system-wide libraries
This change fixes LLVM find package ignoring the library path provided by LLVM_CONFIG and picking up a system-wide library instead. This happens when a custom LLVM is compiled statically, and there is a system-wide LLVM of the version which OSL expects. The solution is to pass NO_DEFAULT_PATH to the find_library so that the function only considers paths explicitly coming from the LLVM's configuration executable. It is a bit unclear what is the expected behavior of this module when LLVM_CONFIG is not available. It is possible to limit possible side effects of this change by only ignoring default paths if the LLVM CONFIG executable is found. In practice this issue happened in Blender's build environment where HIP is used for OpenImageDenoiser: HIP toolchain pulls in LLVM system wide. While it is not an issue on itself (as it is only a compile time dependency for HIP support in OIDN) in conflicts with the logic in the OSL's find_package(LLVM). Signed-off-by: Sergey Sharybin <sergey@blender.org>
1 parent df49a40 commit 0366d4d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/cmake/modules/FindLLVM.cmake

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ string (REPLACE " " ";" LLVM_SYSTEM_LIBRARIES "${LLVM_SYSTEM_LIBRARIES}")
7878

7979
find_library ( LLVM_LIBRARY
8080
NAMES LLVM-${LLVM_VERSION} LLVM
81-
PATHS ${LLVM_LIB_DIR})
81+
PATHS ${LLVM_LIB_DIR}
82+
NO_DEFAULT_PATH)
8283
find_library ( LLVM_MCJIT_LIBRARY
8384
NAMES LLVMMCJIT
84-
PATHS ${LLVM_LIB_DIR})
85+
PATHS ${LLVM_LIB_DIR}
86+
NO_DEFAULT_PATH)
8587

8688
if (NOT LLVM_LIBRARY)
8789
# if no single library was found, use llvm-config to generate the list
@@ -99,8 +101,9 @@ execute_process (COMMAND ${LLVM_CONFIG} --shared-mode
99101
OUTPUT_STRIP_TRAILING_WHITESPACE)
100102
if (LLVM_VERSION VERSION_GREATER_EQUAL 9.0 AND (LLVM_SHARED_MODE STREQUAL "shared"))
101103
find_library ( _CLANG_CPP_LIBRARY
102-
NAMES "clang-cpp"
103-
PATHS ${LLVM_LIB_DIR})
104+
NAMES "clang-cpp"
105+
PATHS ${LLVM_LIB_DIR}
106+
NO_DEFAULT_PATH)
104107
if (_CLANG_CPP_LIBRARY)
105108
list (APPEND CLANG_LIBRARIES ${_CLANG_CPP_LIBRARY})
106109
endif ()
@@ -112,7 +115,8 @@ foreach (COMPONENT clangFrontend clangDriver clangSerialization
112115
clangSupport clangAPINotes)
113116
find_library ( _CLANG_${COMPONENT}_LIBRARY
114117
NAMES ${COMPONENT}
115-
PATHS ${LLVM_LIB_DIR})
118+
PATHS ${LLVM_LIB_DIR}
119+
NO_DEFAULT_PATH)
116120
if (_CLANG_${COMPONENT}_LIBRARY)
117121
list (APPEND CLANG_LIBRARIES ${_CLANG_${COMPONENT}_LIBRARY})
118122
endif ()

0 commit comments

Comments
 (0)