libLLVM.a doesn't exist, so fix how enzyme is linking LLVM
diff --git a/enzyme/Enzyme/CMakeLists.txt b/enzyme/Enzyme/CMakeLists.txt
index 629cecd..0fb1e3b 100644
--- a/enzyme/Enzyme/CMakeLists.txt
+++ b/enzyme/Enzyme/CMakeLists.txt
@@ -8,8 +8,10 @@
 
 get_target_property(TBL_LINKED_LIBS LLVMSupport INTERFACE_LINK_LIBRARIES)
 if (NOT TBL_LINKED_LIBS)
+message(STATUS "No TBL_LINKED_LIBS found")
 else()
-list(REMOVE_ITEM TBL_LINKED_LIBS "ZLIB::ZLIB")
+message(STATUS "TBL_LINKED_LIBS (test): ${TBL_LINKED_LIBS}")
+#list(REMOVE_ITEM TBL_LINKED_LIBS "ZLIB::ZLIB")
 set_property(TARGET LLVMSupport PROPERTY INTERFACE_LINK_LIBRARIES ${TBL_LINKED_LIBS})
 endif()
 
@@ -145,7 +147,36 @@
     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)
+
+    if (${LLVM_BUILD_LLVM_DYLIB})
+        target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} LLVM)
+    else()
+        # 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_libraries Passes)
+        # Therefore, manually invoke llvm-config
+        if (EXISTS "${LLVM_TOOLS_BINARY_DIR}/llvm-config")
+            message(STATUS "Using llvm-config from ${LLVM_TOOLS_BINARY_DIR}")
+        else()
+            message(SEND_ERROR "llvm-config not found in ${LLVM_TOOLS_BINARY_DIR}")
+        endif()
+        execute_process(COMMAND ${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs all
+                    OUTPUT_VARIABLE llvm_libraries)
+        string(STRIP "${llvm_libraries}" llvm_libraries)
+        message(STATUS "Linking against 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
+        execute_process(COMMAND ${LLVM_TOOLS_BINARY_DIR}/llvm-config --ldflags
+                    OUTPUT_VARIABLE llvm_ldflags)
+        string(STRIP "${llvm_ldflags}" llvm_ldflags)
+        message(STATUS "Linking against LLVM ldflags: ${llvm_ldflags}")
+        set_target_properties(Enzyme-${LLVM_VERSION_MAJOR} PROPERTIES LINK_FLAGS ${llvm_ldflags})
+        target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} ${llvm_libraries})
+        
+        llvm_map_components_to_libnames(llvm_librariess Passes Support)
+        target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} ${llvm_librariess})
+    endif()
     install(TARGETS Enzyme-${LLVM_VERSION_MAJOR}
         EXPORT EnzymeTargets
         LIBRARY DESTINATION lib COMPONENT shlib