1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
4 #include "cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool.h"
8 #include <cmsys/RegularExpression.hxx>
10 #include "cmRuntimeDependencyArchive.h"
11 #include "cmSystemTools.h"
12 #include "cmUVProcessChain.h"
14 cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool::
15 cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool(
16 cmRuntimeDependencyArchive* archive)
17 : cmBinUtilsWindowsPEGetRuntimeDependenciesTool(archive)
21 bool cmBinUtilsWindowsPEObjdumpGetRuntimeDependenciesTool::GetFileInfo(
22 const std::string& file, std::vector<std::string>& needed)
24 cmUVProcessChainBuilder builder;
25 builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT);
27 std::vector<std::string> command;
28 if (!this->Archive->GetGetRuntimeDependenciesCommand("objdump", command)) {
29 this->SetError("Could not find objdump");
32 command.emplace_back("-p");
33 command.push_back(file);
34 builder.AddCommand(command);
36 auto process = builder.Start();
37 if (!process.Valid()) {
39 e << "Failed to start objdump process for:\n " << file;
40 this->SetError(e.str());
45 static const cmsys::RegularExpression regex(
46 "^\t*DLL Name: ([^\n]*\\.[Dd][Ll][Ll])$");
47 while (cmSystemTools::GetLineFromStream(*process.OutputStream(), line)) {
48 cmsys::RegularExpressionMatch match;
49 if (regex.find(line.c_str(), match)) {
50 needed.push_back(match.match(1));
54 if (!process.Wait()) {
56 e << "Failed to wait on objdump process for:\n " << file;
57 this->SetError(e.str());
60 auto status = process.GetStatus();
61 if (!status[0] || status[0]->ExitStatus != 0) {
63 e << "Failed to run objdump on:\n " << file;
64 this->SetError(e.str());