cmLinkDirectoriesCommand.cxx 1.9 KB

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