[cmake-developers] [CMake 0011289]: Add functionality to GetPrerequisites to extract DLL names from stub .LIB files on Windows

Mantis Bug Tracker mantis at public.kitware.com
Tue Oct 5 09:03:52 EDT 2010


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=11289 
====================================================================== 
Reported By:                Steffen Hansen
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   11289
Category:                   Modules
Reproducibility:            always
Severity:                   feature
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2010-10-05 09:03 EDT
Last Modified:              2010-10-05 09:03 EDT
====================================================================== 
Summary:                    Add functionality to GetPrerequisites to extract DLL
names from stub .LIB files on Windows
Description: 
I needed to include some DLLs in my projects installer that were not
explicitly linked to by any executable (ie, runtime loaded instead). The
output of FindLibrary() is just the name/location of the .LIB stub file and
not the DLL itself, so I needed a way to get to the DLL name/path.

The tool to use is dumpbin.exe, which is nicely discovered by
GetPrerequisites, and since I think my code might be useful in general,
maybe it could be included in GetPrerequisites in one form or another. Code
snippet below:

MACRO(DLL_NAMES_FROM_LIB_CMAKE libname paths output)
        EXECUTE_PROCESS(COMMAND ${gp_cmd} /HEADERS "${libname}" 
                OUTPUT_VARIABLE _dumpbin_out
                RESULT_VARIABLE _result 
                ERROR_VARIABLE _error_out
                )
        IF(NOT ${RESULT_VARIABLE} EQUAL 0)
                MESSAGE(WARNING "${gp_cmd} did not work: ${_error_out}")
                SET(${output} "NOT-FOUND")
        ELSE()
                STRING(REGEX MATCHALL "DLL name *: ([^\\\n]+)\\\n" _dlls
"${_dumpbin_out}")
                STRING(REGEX REPLACE "DLL name *: ([^\\\n]+)\\\n" "\\1"
_dlls "${_dlls}")
                LIST(REMOVE_DUPLICATES _dlls)
                SET(${output} "")
                FOREACH( _dll ${_dlls})
                        FIND_FILE(_dllpath ${_dll} PATHS ${paths})
                        SET(${output} ${${outout}} ${_dllpath})
                ENDFOREACH()
        ENDIF()
ENDMACRO()
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2010-10-05 09:03 Steffen Hansen New Issue                                    
======================================================================




More information about the cmake-developers mailing list