diff --git a/enzyme/Enzyme/CMakeLists.txt b/enzyme/Enzyme/CMakeLists.txt index 629cecdc578..513b47d0d04 100644 --- a/enzyme/Enzyme/CMakeLists.txt +++ b/enzyme/Enzyme/CMakeLists.txt @@ -145,7 +145,20 @@ if (${ENZYME_EXTERNAL_SHARED_LIB}) add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasDeclarationsIncGen) add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasTAIncGen) add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasDiffUseIncGen) - target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} LLVM) + + # This would be the desired way to link against LLVM components, + # however this function is bugged and does not work with `all`, see: + # https://github.com/llvm/llvm-project/issues/46347 + #llvm_map_components_to_libnames(llvm_libs all) + # Therefore, manually invoke llvm-config + execute_process(COMMAND ${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs all + OUTPUT_VARIABLE llvm_libraries) + string(STRIP "${llvm_libraries}" llvm_libraries) + # In theory, adding --libs should also add all the -l flags, + # but it isn't picked up correctly by clang, so we call target_link_libraries + set_target_properties(Enzyme-${LLVM_VERSION_MAJOR} PROPERTIES + LINK_FLAGS "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --ldflags`") + target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} ${llvm_libraries}) install(TARGETS Enzyme-${LLVM_VERSION_MAJOR} EXPORT EnzymeTargets LIBRARY DESTINATION lib COMPONENT shlib