MantisBT - CMake
View Issue Details
0011289CMakeModulespublic2010-10-05 09:032011-06-06 18:25
Steffen Hansen 
David Cole 
normalfeaturealways
closedno change required 
CMake-2-8 
CMake 2.8.4 
0011289: Add functionality to GetPrerequisites to extract DLL names from stub .LIB files on Windows
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()
No tags attached.
Issue History
2010-10-05 09:03Steffen HansenNew Issue
2010-10-05 09:20Steffen HansenNote Added: 0022409
2010-10-05 17:45Bill HoffmanStatusnew => assigned
2010-10-05 17:45Bill HoffmanAssigned To => David Cole
2011-02-03 17:19David ColeNote Added: 0025255
2011-02-03 17:19David ColeStatusassigned => resolved
2011-02-03 17:19David ColeFixed in Version => CMake 2.8.4
2011-02-03 17:19David ColeResolutionopen => no change required
2011-06-06 18:25David ColeStatusresolved => closed
2011-06-06 18:25David ColeNote Added: 0026683

Notes
(0022409)
Steffen Hansen   
2010-10-05 09:20   
List handling improved (I'm still learning CMake):

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})
                        LIST(APPEND ${output} "${_dllpath}")
                ENDFOREACH()
        ENDIF()
ENDMACRO()
(0025255)
David Cole   
2011-02-03 17:19   
I do not see the value in using dumpbin to analyze stub libs for dll names. Aren't they usually the same name anyhow?

Either way, I think you're asking to put it in GetPrerequisites simply because it already finds dumpbin for you.

In my opinion, this belongs in its own module file, that can include GetPrerequisites just for the dumpbin finding if it wants to.

And it belongs only in projects that really need it, not in CMake in general. If you disagree with this judgment, please re-open the issue to discuss things further.

Thanks.
(0026683)
David Cole   
2011-06-06 18:25   
Closing resolved issues that have not been updated in more than 3 months.