Skip to content

Commit d81a370

Browse files
authored
Merge pull request #23 from rust-lang/fix-llvm-enzyme-linkage4
Fix llvm enzyme linkage4
2 parents 1e4d198 + bfb0433 commit d81a370

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

enzyme/Enzyme/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,28 @@ if (${ENZYME_EXTERNAL_SHARED_LIB})
152152
# This would be the desired way to link against LLVM components,
153153
# however this function is bugged and does not work with `all`, see:
154154
# https://github.com/llvm/llvm-project/issues/46347
155-
#llvm_map_components_to_libnames(llvm_libs all)
155+
#llvm_map_components_to_libnames(llvm_libraries Passes)
156156
# Therefore, manually invoke llvm-config
157+
if (EXISTS "${LLVM_TOOLS_BINARY_DIR}/llvm-config")
158+
message(STATUS "Using llvm-config from ${LLVM_TOOLS_BINARY_DIR}")
159+
else()
160+
message(SEND_ERROR "llvm-config not found in ${LLVM_TOOLS_BINARY_DIR}")
161+
endif()
157162
execute_process(COMMAND ${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs all
158163
OUTPUT_VARIABLE llvm_libraries)
159164
string(STRIP "${llvm_libraries}" llvm_libraries)
165+
message(STATUS "Linking against LLVM libraries: ${llvm_libraries}")
160166
# In theory, adding --libs should also add all the -l flags,
161167
# but it isn't picked up correctly by clang, so we call target_link_libraries
162-
set_target_properties(Enzyme-${LLVM_VERSION_MAJOR} PROPERTIES
163-
LINK_FLAGS "`${LLVM_TOOLS_BINARY_DIR}/llvm-config --ldflags`")
164-
target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} ${llvm_libraries})
168+
execute_process(COMMAND ${LLVM_TOOLS_BINARY_DIR}/llvm-config --ldflags
169+
OUTPUT_VARIABLE llvm_ldflags)
170+
string(STRIP "${llvm_ldflags}" llvm_ldflags)
171+
message(STATUS "Linking against LLVM ldflags: ${llvm_ldflags}")
172+
set_target_properties(Enzyme-${LLVM_VERSION_MAJOR} PROPERTIES LINK_FLAGS ${llvm_ldflags})
173+
target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} PRIVATE ${llvm_libraries})
174+
175+
llvm_map_components_to_libnames(llvm_librariess Passes Support)
176+
target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} PRIVATE ${llvm_librariess})
165177
endif()
166178
install(TARGETS Enzyme-${LLVM_VERSION_MAJOR}
167179
EXPORT EnzymeTargets

0 commit comments

Comments
 (0)