cmGetSourceFilePropertyCommand.cxx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 "cmGetSourceFilePropertyCommand.h"
  4. #include "cmMakefile.h"
  5. #include "cmSourceFile.h"
  6. class cmExecutionStatus;
  7. // cmSetSourceFilePropertyCommand
  8. bool cmGetSourceFilePropertyCommand::InitialPass(
  9. std::vector<std::string> const& args, cmExecutionStatus&)
  10. {
  11. if (args.size() != 3) {
  12. this->SetError("called with incorrect number of arguments");
  13. return false;
  14. }
  15. std::string const& var = args[0];
  16. std::string const& file = args[1];
  17. cmSourceFile* sf = this->Makefile->GetSource(file);
  18. // for the location we must create a source file first
  19. if (!sf && args[2] == "LOCATION") {
  20. sf = this->Makefile->CreateSource(file);
  21. }
  22. if (sf) {
  23. if (args[2] == "LANGUAGE") {
  24. this->Makefile->AddDefinition(var, sf->GetLanguage().c_str());
  25. return true;
  26. }
  27. const char* prop = nullptr;
  28. if (!args[2].empty()) {
  29. prop = sf->GetPropertyForUser(args[2]);
  30. }
  31. if (prop) {
  32. this->Makefile->AddDefinition(var, prop);
  33. return true;
  34. }
  35. }
  36. this->Makefile->AddDefinition(var, "NOTFOUND");
  37. return true;
  38. }