cmLinkDirectoriesCommand.cxx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmLinkDirectoriesCommand.h"
  4. #include <sstream>
  5. #include "cmAlgorithms.h"
  6. #include "cmGeneratorExpression.h"
  7. #include "cmMakefile.h"
  8. #include "cmMessageType.h"
  9. #include "cmPolicies.h"
  10. #include "cmSystemTools.h"
  11. class cmExecutionStatus;
  12. // cmLinkDirectoriesCommand
  13. bool cmLinkDirectoriesCommand::InitialPass(
  14. std::vector<std::string> const& args, cmExecutionStatus&)
  15. {
  16. if (args.empty()) {
  17. return true;
  18. }
  19. bool before = this->Makefile->IsOn("CMAKE_LINK_DIRECTORIES_BEFORE");
  20. auto i = args.cbegin();
  21. if ((*i) == "BEFORE") {
  22. before = true;
  23. ++i;
  24. } else if ((*i) == "AFTER") {
  25. before = false;
  26. ++i;
  27. }
  28. std::vector<std::string> directories;
  29. for (; i != args.cend(); ++i) {
  30. this->AddLinkDir(*i, directories);
  31. }
  32. this->Makefile->AddLinkDirectory(cmJoin(directories, ";"), before);
  33. return true;
  34. }
  35. void cmLinkDirectoriesCommand::AddLinkDir(
  36. std::string const& dir, std::vector<std::string>& directories)
  37. {
  38. std::string unixPath = dir;
  39. cmSystemTools::ConvertToUnixSlashes(unixPath);
  40. if (!cmSystemTools::FileIsFullPath(unixPath) &&
  41. !cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) {
  42. bool convertToAbsolute = false;
  43. std::ostringstream e;
  44. /* clang-format off */
  45. e << "This command specifies the relative path\n"
  46. << " " << unixPath << "\n"
  47. << "as a link directory.\n";
  48. /* clang-format on */
  49. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015)) {
  50. case cmPolicies::WARN:
  51. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015);
  52. this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
  53. break;
  54. case cmPolicies::OLD:
  55. // OLD behavior does not convert
  56. break;
  57. case cmPolicies::REQUIRED_IF_USED:
  58. case cmPolicies::REQUIRED_ALWAYS:
  59. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0015);
  60. this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
  61. CM_FALLTHROUGH;
  62. case cmPolicies::NEW:
  63. // NEW behavior converts
  64. convertToAbsolute = true;
  65. break;
  66. }
  67. if (convertToAbsolute) {
  68. std::string tmp = this->Makefile->GetCurrentSourceDirectory();
  69. tmp += "/";
  70. tmp += unixPath;
  71. unixPath = tmp;
  72. }
  73. }
  74. directories.push_back(unixPath);
  75. }