cmLinkDirectoriesCommand.cxx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "cmMakefile.h"
  6. #include "cmPolicies.h"
  7. #include "cmSystemTools.h"
  8. #include "cmake.h"
  9. class cmExecutionStatus;
  10. // cmLinkDirectoriesCommand
  11. bool cmLinkDirectoriesCommand::InitialPass(
  12. std::vector<std::string> const& args, cmExecutionStatus&)
  13. {
  14. if (args.empty()) {
  15. return true;
  16. }
  17. for (std::vector<std::string>::const_iterator i = args.begin();
  18. i != args.end(); ++i) {
  19. this->AddLinkDir(*i);
  20. }
  21. return true;
  22. }
  23. void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir)
  24. {
  25. std::string unixPath = dir;
  26. cmSystemTools::ConvertToUnixSlashes(unixPath);
  27. if (!cmSystemTools::FileIsFullPath(unixPath.c_str())) {
  28. bool convertToAbsolute = false;
  29. std::ostringstream e;
  30. /* clang-format off */
  31. e << "This command specifies the relative path\n"
  32. << " " << unixPath << "\n"
  33. << "as a link directory.\n";
  34. /* clang-format on */
  35. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015)) {
  36. case cmPolicies::WARN:
  37. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015);
  38. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
  39. case cmPolicies::OLD:
  40. // OLD behavior does not convert
  41. break;
  42. case cmPolicies::REQUIRED_IF_USED:
  43. case cmPolicies::REQUIRED_ALWAYS:
  44. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0015);
  45. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  46. CM_FALLTHROUGH;
  47. case cmPolicies::NEW:
  48. // NEW behavior converts
  49. convertToAbsolute = true;
  50. break;
  51. }
  52. if (convertToAbsolute) {
  53. std::string tmp = this->Makefile->GetCurrentSourceDirectory();
  54. tmp += "/";
  55. tmp += unixPath;
  56. unixPath = tmp;
  57. }
  58. }
  59. this->Makefile->AppendProperty("LINK_DIRECTORIES", unixPath.c_str());
  60. }