Skip to content

Commit b720431

Browse files
sergeyvfxlgritz
authored andcommitted
build: Fix LLVM find package picking up system-wide libraries (AcademySoftwareFoundation#1866)
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 02a1508 commit b720431

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
@@ -97,10 +97,12 @@ string (REPLACE " " ";" LLVM_SYSTEM_LIBRARIES "${LLVM_SYSTEM_LIBRARIES}")
9797

9898
find_library ( LLVM_LIBRARY
9999
NAMES LLVM-${LLVM_VERSION} LLVM
100-
PATHS ${LLVM_LIB_DIR})
100+
PATHS ${LLVM_LIB_DIR}
101+
NO_DEFAULT_PATH)
101102
find_library ( LLVM_MCJIT_LIBRARY
102103
NAMES LLVMMCJIT
103-
PATHS ${LLVM_LIB_DIR})
104+
PATHS ${LLVM_LIB_DIR}
105+
NO_DEFAULT_PATH)
104106

105107
if (NOT LLVM_LIBRARY)
106108
# if no single library was found, use llvm-config to generate the list
@@ -118,8 +120,9 @@ execute_process (COMMAND ${LLVM_CONFIG} --shared-mode
118120
OUTPUT_STRIP_TRAILING_WHITESPACE)
119121
if (LLVM_VERSION VERSION_GREATER_EQUAL 9.0 AND (LLVM_SHARED_MODE STREQUAL "shared"))
120122
find_library ( _CLANG_CPP_LIBRARY
121-
NAMES "clang-cpp"
122-
PATHS ${LLVM_LIB_DIR})
123+
NAMES "clang-cpp"
124+
PATHS ${LLVM_LIB_DIR}
125+
NO_DEFAULT_PATH)
123126
if (_CLANG_CPP_LIBRARY)
124127
list (APPEND CLANG_LIBRARIES ${_CLANG_CPP_LIBRARY})
125128
endif ()
@@ -131,7 +134,8 @@ foreach (COMPONENT clangFrontend clangDriver clangSerialization
131134
clangSupport clangAPINotes)
132135
find_library ( _CLANG_${COMPONENT}_LIBRARY
133136
NAMES ${COMPONENT}
134-
PATHS ${LLVM_LIB_DIR})
137+
PATHS ${LLVM_LIB_DIR}
138+
NO_DEFAULT_PATH)
135139
if (_CLANG_${COMPONENT}_LIBRARY)
136140
list (APPEND CLANG_LIBRARIES ${_CLANG_${COMPONENT}_LIBRARY})
137141
endif ()

0 commit comments

Comments
 (0)