Skip to content

Fix llvm enzyme linkage4 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions enzyme/Enzyme/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,28 @@ if (${ENZYME_EXTERNAL_SHARED_LIB})
# 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)
#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
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})
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} PRIVATE ${llvm_libraries})

llvm_map_components_to_libnames(llvm_librariess Passes Support)
target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} PRIVATE ${llvm_librariess})
endif()
install(TARGETS Enzyme-${LLVM_VERSION_MAJOR}
EXPORT EnzymeTargets
Expand Down
Loading