|
8 | 8 |
|
9 | 9 | get_target_property(TBL_LINKED_LIBS LLVMSupport INTERFACE_LINK_LIBRARIES) |
10 | 10 | if (NOT TBL_LINKED_LIBS) |
| 11 | +message(STATUS "No TBL_LINKED_LIBS found") |
11 | 12 | else() |
12 | | -list(REMOVE_ITEM TBL_LINKED_LIBS "ZLIB::ZLIB") |
| 13 | +message(STATUS "TBL_LINKED_LIBS (test): ${TBL_LINKED_LIBS}") |
| 14 | +#list(REMOVE_ITEM TBL_LINKED_LIBS "ZLIB::ZLIB") |
13 | 15 | set_property(TARGET LLVMSupport PROPERTY INTERFACE_LINK_LIBRARIES ${TBL_LINKED_LIBS}) |
14 | 16 | endif() |
15 | 17 |
|
@@ -145,7 +147,36 @@ if (${ENZYME_EXTERNAL_SHARED_LIB}) |
145 | 147 | add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasDeclarationsIncGen) |
146 | 148 | add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasTAIncGen) |
147 | 149 | add_dependencies(Enzyme-${LLVM_VERSION_MAJOR} BlasDiffUseIncGen) |
148 | | - target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} LLVM) |
| 150 | + |
| 151 | + if (${LLVM_BUILD_LLVM_DYLIB}) |
| 152 | + target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} LLVM) |
| 153 | + else() |
| 154 | + # This would be the desired way to link against LLVM components, |
| 155 | + # however this function is bugged and does not work with `all`, see: |
| 156 | + # https://github.com/llvm/llvm-project/issues/46347 |
| 157 | + #llvm_map_components_to_libnames(llvm_libraries Passes) |
| 158 | + # Therefore, manually invoke llvm-config |
| 159 | + if (EXISTS "${LLVM_TOOLS_BINARY_DIR}/llvm-config") |
| 160 | + message(STATUS "Using llvm-config from ${LLVM_TOOLS_BINARY_DIR}") |
| 161 | + else() |
| 162 | + message(SEND_ERROR "llvm-config not found in ${LLVM_TOOLS_BINARY_DIR}") |
| 163 | + endif() |
| 164 | + execute_process(COMMAND ${LLVM_TOOLS_BINARY_DIR}/llvm-config --libs all |
| 165 | + OUTPUT_VARIABLE llvm_libraries) |
| 166 | + string(STRIP "${llvm_libraries}" llvm_libraries) |
| 167 | + message(STATUS "Linking against LLVM libraries: ${llvm_libraries}") |
| 168 | + # In theory, adding --libs should also add all the -l flags, |
| 169 | + # but it isn't picked up correctly by clang, so we call target_link_libraries |
| 170 | + execute_process(COMMAND ${LLVM_TOOLS_BINARY_DIR}/llvm-config --ldflags |
| 171 | + OUTPUT_VARIABLE llvm_ldflags) |
| 172 | + string(STRIP "${llvm_ldflags}" llvm_ldflags) |
| 173 | + message(STATUS "Linking against LLVM ldflags: ${llvm_ldflags}") |
| 174 | + set_target_properties(Enzyme-${LLVM_VERSION_MAJOR} PROPERTIES LINK_FLAGS ${llvm_ldflags}) |
| 175 | + target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} ${llvm_libraries}) |
| 176 | + |
| 177 | + llvm_map_components_to_libnames(llvm_librariess Passes Support) |
| 178 | + target_link_libraries(Enzyme-${LLVM_VERSION_MAJOR} ${llvm_librariess}) |
| 179 | + endif() |
149 | 180 | install(TARGETS Enzyme-${LLVM_VERSION_MAJOR} |
150 | 181 | EXPORT EnzymeTargets |
151 | 182 | LIBRARY DESTINATION lib COMPONENT shlib |
|
0 commit comments