diff options
author | Peter Zotov <whitequark@whitequark.org> | 2014-12-18 23:56:52 +0000 |
---|---|---|
committer | Peter Zotov <whitequark@whitequark.org> | 2014-12-18 23:56:52 +0000 |
commit | f94eed608393f54389145b42a2f32c53f3b84274 (patch) | |
tree | eb3e753f5856f26613119e0b712aca36d313853f /llvm/cmake/modules | |
parent | 824e011ad7b400ef79920ae9f84e5f55375720f2 (diff) | |
download | bcm5719-llvm-f94eed608393f54389145b42a2f32c53f3b84274.tar.gz bcm5719-llvm-f94eed608393f54389145b42a2f32c53f3b84274.zip |
[cmake] Unbreak LLVM-Config.cmake / llvm_expand_dependencies.
The algorithm for sorting libraries in topological order, as
previously implemented, had a few issues:
* It didn't make any sense.
* It didn't actually sort libraries in topological order.
* It hung on some inputs, e.g. "LLVMipo".
This commit replaces the old algorithm with a straightforward port
from llvm-config.cpp.
llvm-svn: 224554
Diffstat (limited to 'llvm/cmake/modules')
-rw-r--r-- | llvm/cmake/modules/LLVM-Config.cmake | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/llvm/cmake/modules/LLVM-Config.cmake b/llvm/cmake/modules/LLVM-Config.cmake index e8c42fc8dc7..b24c12989fa 100644 --- a/llvm/cmake/modules/LLVM-Config.cmake +++ b/llvm/cmake/modules/LLVM-Config.cmake @@ -152,29 +152,39 @@ function(llvm_map_components_to_libnames out_libs) set(${out_libs} ${expanded_components} PARENT_SCOPE) endfunction() +# Perform a post-order traversal of the dependency graph. +# This duplicates the algorithm used by llvm-config, originally +# in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents. +function(expand_topologically name required_libs visited_libs) + list(FIND visited_libs ${name} found) + if( found LESS 0 ) + list(APPEND visited_libs ${name}) + set(visited_libs ${visited_libs} PARENT_SCOPE) + + get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) + foreach( lib_dep ${lib_deps} ) + expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}") + set(required_libs ${required_libs} PARENT_SCOPE) + set(visited_libs ${visited_libs} PARENT_SCOPE) + endforeach() + + list(APPEND required_libs ${name}) + set(required_libs ${required_libs} PARENT_SCOPE) + endif() +endfunction() + # Expand dependencies while topologically sorting the list of libraries: function(llvm_expand_dependencies out_libs) set(expanded_components ${ARGN}) - list(LENGTH expanded_components lst_size) - set(cursor 0) - set(processed) - while( cursor LESS lst_size ) - list(GET expanded_components ${cursor} lib) - get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib}) - list(APPEND expanded_components ${lib_deps}) - # Remove duplicates at the front: - list(REVERSE expanded_components) - list(REMOVE_DUPLICATES expanded_components) - list(REVERSE expanded_components) - list(APPEND processed ${lib}) - # Find the maximum index that doesn't have to be re-processed: - while(NOT "${expanded_components}" MATCHES "^${processed}.*" ) - list(REMOVE_AT processed -1) - endwhile() - list(LENGTH processed cursor) - list(LENGTH expanded_components lst_size) - endwhile( cursor LESS lst_size ) - set(${out_libs} ${expanded_components} PARENT_SCOPE) + + set(required_libs) + set(visited_libs) + foreach( lib ${expanded_components} ) + expand_topologically(${lib} "${required_libs}" "${visited_libs}") + endforeach() + + list(REVERSE required_libs) + set(${out_libs} ${required_libs} PARENT_SCOPE) endfunction() function(explicit_map_components_to_libraries out_libs) |