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 "cmLDConfigLDConfigTool.h"
10 #include "cmsys/RegularExpression.hxx"
12 #include "cmMakefile.h"
13 #include "cmRuntimeDependencyArchive.h"
14 #include "cmStringAlgorithms.h"
15 #include "cmSystemTools.h"
16 #include "cmUVProcessChain.h"
18 cmLDConfigLDConfigTool::cmLDConfigLDConfigTool(
19 cmRuntimeDependencyArchive* archive)
20 : cmLDConfigTool(archive)
24 bool cmLDConfigLDConfigTool::GetLDConfigPaths(std::vector<std::string>& paths)
26 std::string ldConfigPath =
27 this->Archive->GetMakefile()->GetSafeDefinition("CMAKE_LDCONFIG_COMMAND");
28 if (ldConfigPath.empty()) {
29 ldConfigPath = cmSystemTools::FindProgram(
30 "ldconfig", { "/sbin", "/usr/sbin", "/usr/local/sbin" });
31 if (ldConfigPath.empty()) {
32 this->Archive->SetError("Could not find ldconfig");
37 std::vector<std::string> ldConfigCommand = cmExpandedList(ldConfigPath);
38 ldConfigCommand.emplace_back("-v");
39 ldConfigCommand.emplace_back("-N"); // Don't rebuild the cache.
40 ldConfigCommand.emplace_back("-X"); // Don't update links.
42 cmUVProcessChainBuilder builder;
43 builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT)
44 .AddCommand(ldConfigCommand);
45 auto process = builder.Start();
46 if (!process.Valid()) {
47 this->Archive->SetError("Failed to start ldconfig process");
52 static const cmsys::RegularExpression regex("^([^\t:]*):");
53 while (std::getline(*process.OutputStream(), line)) {
54 cmsys::RegularExpressionMatch match;
55 if (regex.find(line.c_str(), match)) {
56 paths.push_back(match.match(1));
60 if (!process.Wait()) {
61 this->Archive->SetError("Failed to wait on ldconfig process");
64 auto status = process.GetStatus();
65 if (!status[0] || status[0]->ExitStatus != 0) {
66 this->Archive->SetError("Failed to run ldconfig");