cmSetTargetPropertiesCommand.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "
  57. "a PROPERTIES specifier?");
  58. return false;
  59. }
  60. }
  61. if(propertyPairs.size() == 0)
  62. {
  63. this->SetError("called with illegal arguments, maybe missing "
  64. "a PROPERTIES specifier?");
  65. return false;
  66. }
  67. cmTargets& targets = this->Makefile->GetTargets();
  68. // now loop over all the targets
  69. int i;
  70. unsigned int k;
  71. for(i = 0; i < numFiles; ++i)
  72. {
  73. // if the file is already in the makefile just set properites on it
  74. cmTargets::iterator t = targets.find(args[i]);
  75. if ( t != targets.end())
  76. {
  77. cmTarget& target = t->second;
  78. // now loop through all the props and set them
  79. for (k = 0; k < propertyPairs.size(); k = k + 2)
  80. {
  81. target.SetProperty(propertyPairs[k].c_str(),
  82. propertyPairs[k+1].c_str());
  83. }
  84. }
  85. // if file is not already in the makefile, then add it
  86. else
  87. {
  88. std::string message = "Can not find target to add properties to: ";
  89. message += args[i];
  90. this->SetError(message.c_str());
  91. return false;
  92. }
  93. }
  94. return true;
  95. }