Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmTargetLinkDirectoriesCommand.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmTargetLinkDirectoriesCommand.h"
4
5
#include "cmGeneratorExpression.h"
6
#include "cmList.h"
7
#include "cmListFileCache.h"
8
#include "cmMakefile.h"
9
#include "cmMessageType.h"
10
#include "cmStringAlgorithms.h"
11
#include "cmSystemTools.h"
12
#include "cmTarget.h"
13
#include "cmTargetPropCommandBase.h"
14
15
namespace {
16
17
class TargetLinkDirectoriesImpl : public cmTargetPropCommandBase
18
{
19
public:
20
  using cmTargetPropCommandBase::cmTargetPropCommandBase;
21
22
private:
23
  void HandleMissingTarget(std::string const& name) override
24
0
  {
25
0
    this->Makefile->IssueMessage(
26
0
      MessageType::FATAL_ERROR,
27
0
      cmStrCat("Cannot specify link directories for target \"", name,
28
0
               "\" which is not built by this project."));
29
0
  }
30
31
  std::string Join(std::vector<std::string> const& content) override;
32
33
  bool HandleDirectContent(cmTarget* tgt,
34
                           std::vector<std::string> const& content,
35
                           bool prepend, bool /*system*/) override
36
0
  {
37
0
    cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
38
0
    tgt->InsertLinkDirectory(BT<std::string>(this->Join(content), lfbt),
39
0
                             prepend);
40
0
    return true; // Successfully handled.
41
0
  }
42
};
43
44
std::string TargetLinkDirectoriesImpl::Join(
45
  std::vector<std::string> const& content)
46
0
{
47
0
  std::vector<std::string> directories;
48
49
0
  for (auto const& dir : content) {
50
0
    auto unixPath = dir;
51
0
    cmSystemTools::ConvertToUnixSlashes(unixPath);
52
0
    if (!cmSystemTools::FileIsFullPath(unixPath) &&
53
0
        !cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) {
54
0
      auto tmp = this->Makefile->GetCurrentSourceDirectory();
55
0
      tmp += "/";
56
0
      tmp += unixPath;
57
0
      unixPath = tmp;
58
0
    }
59
0
    directories.push_back(unixPath);
60
0
  }
61
62
0
  return cmList::to_string(directories);
63
0
}
64
65
} // namespace
66
67
bool cmTargetLinkDirectoriesCommand(std::vector<std::string> const& args,
68
                                    cmExecutionStatus& status)
69
0
{
70
0
  return TargetLinkDirectoriesImpl(status).HandleArguments(
71
0
    args, "LINK_DIRECTORIES", TargetLinkDirectoriesImpl::PROCESS_BEFORE);
72
0
}