cmSetTargetPropertiesCommand.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmSetTargetPropertiesCommand.h"
  14. // cmSetTargetPropertiesCommand
  15. bool cmSetTargetPropertiesCommand::InitialPass(
  16. std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 2 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // first collect up the list of files
  24. std::vector<std::string> propertyPairs;
  25. bool doingFiles = true;
  26. int numFiles = 0;
  27. std::vector<std::string>::const_iterator j;
  28. for(j= args.begin(); j != args.end();++j)
  29. {
  30. if(*j == "PROPERTIES")
  31. {
  32. doingFiles = false;
  33. // now loop through the rest of the arguments, new style
  34. ++j;
  35. while (j != args.end())
  36. {
  37. propertyPairs.push_back(*j);
  38. ++j;
  39. if(j == args.end())
  40. {
  41. this->SetError("called with incorrect number of arguments.");
  42. return false;
  43. }
  44. propertyPairs.push_back(*j);
  45. ++j;
  46. }
  47. // break out of the loop because j is already == end
  48. break;
  49. }
  50. else if (doingFiles)
  51. {
  52. numFiles++;
  53. }
  54. else
  55. {
  56. this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
  57. return false;
  58. }
  59. }
  60. if(propertyPairs.size() == 0)
  61. {
  62. this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
  63. return false;
  64. }
  65. cmTargets& targets = this->Makefile->GetTargets();
  66. // now loop over all the targets
  67. int i;
  68. unsigned int k;
  69. for(i = 0; i < numFiles; ++i)
  70. {
  71. // if the file is already in the makefile just set properites on it
  72. cmTargets::iterator t = targets.find(args[i]);
  73. if ( t != targets.end())
  74. {
  75. cmTarget& target = t->second;
  76. // now loop through all the props and set them
  77. for (k = 0; k < propertyPairs.size(); k = k + 2)
  78. {
  79. target.SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  80. }
  81. }
  82. // if file is not already in the makefile, then add it
  83. else
  84. {
  85. std::string message = "Can not find target to add properties to: ";
  86. message += args[i];
  87. this->SetError(message.c_str());
  88. return false;
  89. }
  90. }
  91. return true;
  92. }