cmLinkDirectoriesCommand.cxx 2.4 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3
#include "cmLinkDirectoriesCommand.h"
4

5 6
#include <sstream>

7
#include "cmAlgorithms.h"
8
#include "cmGeneratorExpression.h"
9
#include "cmMakefile.h"
10
#include "cmMessageType.h"
11
#include "cmPolicies.h"
12
#include "cmSystemTools.h"
13 14

class cmExecutionStatus;
15

16
// cmLinkDirectoriesCommand
17 18
bool cmLinkDirectoriesCommand::InitialPass(
  std::vector<std::string> const& args, cmExecutionStatus&)
19
{
20
  if (args.empty()) {
Ken Martin's avatar
Ken Martin committed
21
    return true;
22
  }
23

24 25 26 27 28 29 30 31 32 33 34 35 36 37
  bool before = this->Makefile->IsOn("CMAKE_LINK_DIRECTORIES_BEFORE");

  auto i = args.cbegin();
  if ((*i) == "BEFORE") {
    before = true;
    ++i;
  } else if ((*i) == "AFTER") {
    before = false;
    ++i;
  }

  std::vector<std::string> directories;
  for (; i != args.cend(); ++i) {
    this->AddLinkDir(*i, directories);
38
  }
39 40 41

  this->Makefile->AddLinkDirectory(cmJoin(directories, ";"), before);

42 43 44
  return true;
}

45 46
void cmLinkDirectoriesCommand::AddLinkDir(
  std::string const& dir, std::vector<std::string>& directories)
47 48 49
{
  std::string unixPath = dir;
  cmSystemTools::ConvertToUnixSlashes(unixPath);
50 51
  if (!cmSystemTools::FileIsFullPath(unixPath) &&
      !cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) {
52
    bool convertToAbsolute = false;
53
    std::ostringstream e;
54
    /* clang-format off */
55 56 57
    e << "This command specifies the relative path\n"
      << "  " << unixPath << "\n"
      << "as a link directory.\n";
58
    /* clang-format on */
59
    switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015)) {
60
      case cmPolicies::WARN:
61
        e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015);
62
        this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
63
        break;
64 65 66 67 68
      case cmPolicies::OLD:
        // OLD behavior does not convert
        break;
      case cmPolicies::REQUIRED_IF_USED:
      case cmPolicies::REQUIRED_ALWAYS:
69
        e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0015);
70
        this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
71
        CM_FALLTHROUGH;
72 73 74 75
      case cmPolicies::NEW:
        // NEW behavior converts
        convertToAbsolute = true;
        break;
76 77
    }
    if (convertToAbsolute) {
78
      std::string tmp = this->Makefile->GetCurrentSourceDirectory();
79 80 81 82
      tmp += "/";
      tmp += unixPath;
      unixPath = tmp;
    }
83
  }
84
  directories.push_back(unixPath);
85
}