cmSetTargetPropertiesCommand.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmSetTargetPropertiesCommand.h"
  11. #include "cmGlobalGenerator.h"
  12. // cmSetTargetPropertiesCommand
  13. bool cmSetTargetPropertiesCommand
  14. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  15. {
  16. if(args.size() < 2 )
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // first collect up the list of files
  22. std::vector<std::string> propertyPairs;
  23. int numFiles = 0;
  24. std::vector<std::string>::const_iterator j;
  25. for(j= args.begin(); j != args.end();++j)
  26. {
  27. if(*j == "PROPERTIES")
  28. {
  29. // now loop through the rest of the arguments, new style
  30. ++j;
  31. if (std::distance(j, args.end()) % 2 != 0)
  32. {
  33. this->SetError("called with incorrect number of arguments.");
  34. return false;
  35. }
  36. propertyPairs.insert(propertyPairs.end(), j, args.end());
  37. break;
  38. }
  39. else
  40. {
  41. numFiles++;
  42. }
  43. }
  44. if(propertyPairs.empty())
  45. {
  46. this->SetError("called with illegal arguments, maybe missing "
  47. "a PROPERTIES specifier?");
  48. return false;
  49. }
  50. // now loop over all the targets
  51. int i;
  52. for(i = 0; i < numFiles; ++i)
  53. {
  54. if (this->Makefile->IsAlias(args[i]))
  55. {
  56. this->SetError("can not be used on an ALIAS target.");
  57. return false;
  58. }
  59. bool ret = cmSetTargetPropertiesCommand::SetOneTarget
  60. (args[i],propertyPairs,this->Makefile);
  61. if (!ret)
  62. {
  63. std::string message = "Can not find target to add properties to: ";
  64. message += args[i];
  65. this->SetError(message);
  66. return false;
  67. }
  68. }
  69. return true;
  70. }
  71. bool cmSetTargetPropertiesCommand
  72. ::SetOneTarget(const std::string& tname,
  73. std::vector<std::string> &propertyPairs,
  74. cmMakefile *mf)
  75. {
  76. if(cmTarget* target = mf->FindTargetToUse(tname))
  77. {
  78. // now loop through all the props and set them
  79. unsigned int k;
  80. for (k = 0; k < propertyPairs.size(); k = k + 2)
  81. {
  82. target->SetProperty(propertyPairs[k],
  83. propertyPairs[k+1].c_str());
  84. target->CheckProperty(propertyPairs[k], mf);
  85. }
  86. }
  87. // if file is not already in the makefile, then add it
  88. else
  89. {
  90. return false;
  91. }
  92. return true;
  93. }