cmSubdirCommand.cxx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. this->Makefile->GetCurrentSourceDirectory() + "/" + i;
  29. if (cmSystemTools::FileIsDirectory(srcPath)) {
  30. std::string binPath =
  31. 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 = this->Makefile->GetCurrentBinaryDirectory() + "/" +
  39. cmSystemTools::GetFilenameName(i);
  40. this->Makefile->AddSubDirectory(i, binPath, excludeFromAll, false);
  41. } else {
  42. std::string error = "Incorrect SUBDIRS command. Directory: ";
  43. error += i + " does not exist.";
  44. this->SetError(error);
  45. res = false;
  46. }
  47. }
  48. return res;
  49. }