Browse Source

GetPrerequisites: Optionally filter "objdump" output for speed

As dumpbin.exe is no longer reliable for gcc libraries on MinGW because
it crashes on many common libraries like libgcc_s and libgfortran it is
now necessary too resort to using objdump for DLL dependency walking.
Using objdump has a secondary problem in that it generates a lot of
output for large libraries and causes fixup_bundle() to take many
minutes to process what took fractions of a second with
"dumpbin.exe /dependents".

Add a 'grep' pre-filter in the execute_process() command pipeline to
reduce this output to a minimum for a several orders of magnitude speed
up.  If grep is not available just use the full output.

As there does not seem to be a reliable way of detecting MinGW, callers
of fixup_bundle() may have to set the variable gp_tool to "objdump" if
dumpbin.exe is installed on the build machine to stop it using the
broken MS dumpbin.exe for library dependency walking.
Bill Somerville 10 years ago
parent
commit
5d0a8b1abc
1 changed files with 8 additions and 0 deletions
  1. 8 0
      Modules/GetPrerequisites.cmake

+ 8 - 0
Modules/GetPrerequisites.cmake

@@ -700,6 +700,8 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
     return()
   endif()
 
+  set(gp_cmd_maybe_filter)      # optional command to pre-filter gp_tool results
+
   if(gp_tool STREQUAL "ldd")
     set(gp_cmd_args "")
     set(gp_regex "^[\t ]*[^\t ]+ => ([^\t\(]+) .*${eol_char}$")
@@ -724,6 +726,11 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
     set(gp_regex_error "")
     set(gp_regex_fallback "")
     set(gp_regex_cmp_count 1)
+    # objdump generaates copious output so we create a grep filter to pre-filter results
+    find_program(gp_grep_cmd grep)
+    if(gp_grep_cmd)
+      set(gp_cmd_maybe_filter COMMAND ${gp_grep_cmd} "^[[:blank:]]*DLL Name: ")
+    endif()
   else()
     message(STATUS "warning: gp_tool='${gp_tool}' is an unknown tool...")
     message(STATUS "CMake function get_prerequisites needs more code to handle '${gp_tool}'")
@@ -780,6 +787,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
   #
   execute_process(
     COMMAND ${gp_cmd} ${gp_cmd_args} ${target}
+    ${gp_cmd_maybe_filter}
     RESULT_VARIABLE gp_rv
     OUTPUT_VARIABLE gp_cmd_ov
     ERROR_VARIABLE gp_ev