cmSubdirCommand.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "cmSubdirCommand.h"
  4. #include "cmMakefile.h"
  5. #include "cmSystemTools.h"
  6. class cmExecutionStatus;
  7. // cmSubdirCommand
  8. bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args,
  9. cmExecutionStatus&)
  10. {
  11. if (args.empty()) {
  12. this->SetError("called with incorrect number of arguments");
  13. return false;
  14. }
  15. bool res = true;
  16. bool excludeFromAll = false;
  17. for (std::string const& i : args) {
  18. if (i == "EXCLUDE_FROM_ALL") {
  19. excludeFromAll = true;
  20. continue;
  21. }
  22. if (i == "PREORDER") {
  23. // Ignored
  24. continue;
  25. }
  26. // if they specified a relative path then compute the full
  27. std::string srcPath =
  28. std::string(this->Makefile->GetCurrentSourceDirectory()) + "/" + i;
  29. if (cmSystemTools::FileIsDirectory(srcPath)) {
  30. std::string binPath =
  31. std::string(this->Makefile->GetCurrentBinaryDirectory()) + "/" + i;
  32. this->Makefile->AddSubDirectory(srcPath, binPath, excludeFromAll, false);
  33. }
  34. // otherwise it is a full path
  35. else if (cmSystemTools::FileIsDirectory(i)) {
  36. // we must compute the binPath from the srcPath, we just take the last
  37. // element from the source path and use that
  38. std::string binPath =
  39. std::string(this->Makefile->GetCurrentBinaryDirectory()) + "/" +
  40. cmSystemTools::GetFilenameName(i);
  41. this->Makefile->AddSubDirectory(i, binPath, excludeFromAll, false);
  42. } else {
  43. std::string error = "Incorrect SUBDIRS command. Directory: ";
  44. error += i + " does not exist.";
  45. this->SetError(error);
  46. res = false;
  47. }
  48. }
  49. return res;
  50. }