cmSetTargetPropertiesCommand.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "cmSetTargetPropertiesCommand.h"
  4. #include <iterator>
  5. #include "cmAlgorithms.h"
  6. #include "cmMakefile.h"
  7. #include "cmTarget.h"
  8. class cmExecutionStatus;
  9. // cmSetTargetPropertiesCommand
  10. bool cmSetTargetPropertiesCommand::InitialPass(
  11. std::vector<std::string> const& args, cmExecutionStatus&)
  12. {
  13. if (args.size() < 2) {
  14. this->SetError("called with incorrect number of arguments");
  15. return false;
  16. }
  17. // first collect up the list of files
  18. std::vector<std::string> propertyPairs;
  19. int numFiles = 0;
  20. std::vector<std::string>::const_iterator j;
  21. for (j = args.begin(); j != args.end(); ++j) {
  22. if (*j == "PROPERTIES") {
  23. // now loop through the rest of the arguments, new style
  24. ++j;
  25. if (std::distance(j, args.end()) % 2 != 0) {
  26. this->SetError("called with incorrect number of arguments.");
  27. return false;
  28. }
  29. cmAppend(propertyPairs, j, args.end());
  30. break;
  31. }
  32. numFiles++;
  33. }
  34. if (propertyPairs.empty()) {
  35. this->SetError("called with illegal arguments, maybe missing "
  36. "a PROPERTIES specifier?");
  37. return false;
  38. }
  39. // now loop over all the targets
  40. int i;
  41. for (i = 0; i < numFiles; ++i) {
  42. if (this->Makefile->IsAlias(args[i])) {
  43. this->SetError("can not be used on an ALIAS target.");
  44. return false;
  45. }
  46. bool ret = cmSetTargetPropertiesCommand::SetOneTarget(
  47. args[i], propertyPairs, this->Makefile);
  48. if (!ret) {
  49. std::string message = "Can not find target to add properties to: ";
  50. message += args[i];
  51. this->SetError(message);
  52. return false;
  53. }
  54. }
  55. return true;
  56. }
  57. bool cmSetTargetPropertiesCommand::SetOneTarget(
  58. const std::string& tname, std::vector<std::string>& propertyPairs,
  59. cmMakefile* mf)
  60. {
  61. if (cmTarget* target = mf->FindTargetToUse(tname)) {
  62. // now loop through all the props and set them
  63. unsigned int k;
  64. for (k = 0; k < propertyPairs.size(); k = k + 2) {
  65. target->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
  66. target->CheckProperty(propertyPairs[k], mf);
  67. }
  68. }
  69. // if file is not already in the makefile, then add it
  70. else {
  71. return false;
  72. }
  73. return true;
  74. }