Skip to content

Commit 4f13e93

Browse files
authored
Merge pull request #21 from EnzymeAD/fix-llvm-enzyme-linkage
libLLVM.a doesn't exist, so fix how enzyme is linking LLVM
2 parents 861f325 + 42c6cf4 commit 4f13e93

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

enzyme/Enzyme/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,20 @@ if (${ENZYME_EXTERNAL_SHARED_LIB})
145145
add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasDeclarationsIncGen)
146146
add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasTAIncGen)
147147
add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasDiffUseIncGen)
148-
target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} LLVM)
148+
149+
# This would be the desired way to link against LLVM components,
150+
# however this function is bugged and does not work with `all`, see:
151+
# https://github.com/llvm/llvm-project/issues/46347
152+
#llvm_map_components_to_libnames(llvm_libs all)
153+
# Therefore, manually invoke llvm-config
154+
execute_process(COMMAND ${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs all
155+
OUTPUT_VARIABLE llvm_libraries)
156+
string(STRIP "${llvm_libraries}" llvm_libraries)
157+
# In theory, adding --libs should also add all the -l flags,
158+
# but it isn't picked up correctly by clang, so we call target_link_libraries
159+
set_target_properties(Enzyme-${LLVM_VERSION_MAJOR} PROPERTIES
160+
LINK_FLAGS "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --ldflags`")
161+
target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} ${llvm_libraries})
149162
install(TARGETS Enzyme-${LLVM_VERSION_MAJOR}
150163
EXPORT EnzymeTargets
151164
LIBRARY DESTINATION lib COMPONENT shlib

0 commit comments

Comments
 (0)