cmSetTargetPropertiesCommand.cxx 2.3 KB

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