diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -942,17 +942,54 @@ DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} COMPONENT cmake-exports) - file(WRITE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "//extension handlers\n") + set(LLVM_EXTENSION_DEF "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") + file(WRITE "${LLVM_EXTENSION_DEF}.tmp" "//extension handlers\n") foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) - file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension})\n") + file(APPEND "${LLVM_EXTENSION_DEF}.tmp" "HANDLE_EXTENSION(${llvm_extension})\n") endforeach() - file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "#undef HANDLE_EXTENSION\n") + file(APPEND "${LLVM_EXTENSION_DEF}.tmp" "#undef HANDLE_EXTENSION\n") # only replace if there's an actual change execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" - "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") - file(REMOVE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp") + "${LLVM_EXTENSION_DEF}.tmp" + "${LLVM_EXTENSION_DEF}") + file(REMOVE "${LLVM_EXTENSION_DEF}.tmp") + + # also generate build information for llvm-config + set(llvm_plugin_max_deps_length 0) + foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) + get_property(llvm_plugin_deps TARGET ${llvm_extension} PROPERTY LINK_LIBRARIES) + list(LENGTH llvm_plugin_deps llvm_plugin_deps_length) + if(llvm_plugin_deps_length GREATER llvm_plugin_max_deps_length) + set(llvm_plugin_max_deps_length ${llvm_plugin_deps_length}) + endif() + endforeach() + + set(LLVM_EXTENSION_DEPS "${LLVM_BINARY_DIR}/tools/llvm-config/ExtensionDependencies.inc") + file(WRITE + "${LLVM_EXTENSION_DEPS}.tmp" + "struct { const char* Name; const char* const RequiredLibraries[1 + 1 + ${llvm_plugin_max_deps_length}];} AvailableExtensions[] = {\n") + foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) + get_property(llvm_plugin_deps TARGET ${llvm_extension} PROPERTY LINK_LIBRARIES) + file(APPEND "${LLVM_EXTENSION_DEPS}.tmp" "\t{\"${llvm_extension}\", {\"${llvm_extension}\",") + foreach(llvm_plugin_dep ${llvm_plugin_deps}) + STRING(REGEX REPLACE "^-l" "" plugin_dep_name ${llvm_plugin_dep}) + STRING(REGEX MATCH "^LLVM" is_llvm_library ${plugin_dep_name}) + if(is_llvm_library) + STRING(REGEX REPLACE "^LLVM" "" plugin_dep_name ${plugin_dep_name}) + STRING(TOLOWER ${plugin_dep_name} plugin_dep_name) + endif() + file(APPEND "${LLVM_EXTENSION_DEPS}.tmp" "\"${plugin_dep_name}\", ") + endforeach() + file(APPEND "${LLVM_EXTENSION_DEPS}.tmp" "nullptr}},\n") + endforeach() + file(APPEND "${LLVM_EXTENSION_DEPS}.tmp" "};\n") + + # only replace if there's an actual change + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${LLVM_EXTENSION_DEPS}.tmp" + "${LLVM_EXTENSION_DEPS}") + file(REMOVE "${LLVM_EXTENSION_DEPS}.tmp") endif() endfunction() diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp --- a/llvm/tools/llvm-config/llvm-config.cpp +++ b/llvm/tools/llvm-config/llvm-config.cpp @@ -46,6 +46,10 @@ // create entries for pseudo groups like x86 or all-targets. #include "LibraryDependencies.inc" +// Extension also register their dependencies as a dependency of "passes" +// component. +#include "ExtensionDependencies.inc" + // LinkMode determines what libraries and flags are returned by llvm-config. enum LinkMode { // LinkModeAuto will link with the default link mode for the installation, @@ -127,6 +131,21 @@ } RequiredLibs.push_back(AC->Library); } + if (Name == "passes") { + for (auto const &AvailableExtension : AvailableExtensions) { + for (const char *const *Iter = &AvailableExtension.RequiredLibraries[0]; + *Iter; ++Iter) { + AvailableComponent *AC = ComponentMap.lookup(*Iter); + if (!AC) { + RequiredLibs.push_back(*Iter); + } else { + VisitComponent(*Iter, ComponentMap, VisitedComponents, RequiredLibs, + IncludeNonInstalled, GetComponentNames, + GetComponentLibraryPath, Missing, DirSep); + } + } + } + } } /// Compute the list of required libraries for a given list of