cmGetSourceFilePropertyCommand.cxx 1.1 KB

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