cmSetTargetPropertiesCommand.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. // cmSetTargetPropertiesCommand
  17. bool cmSetTargetPropertiesCommand
  18. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  19. {
  20. if(args.size() < 2 )
  21. {
  22. this->SetError("called with incorrect number of arguments");
  23. return false;
  24. }
  25. // first collect up the list of files
  26. std::vector<std::string> propertyPairs;
  27. bool doingFiles = true;
  28. int numFiles = 0;
  29. std::vector<std::string>::const_iterator j;
  30. for(j= args.begin(); j != args.end();++j)
  31. {
  32. if(*j == "PROPERTIES")
  33. {
  34. doingFiles = false;
  35. // now loop through the rest of the arguments, new style
  36. ++j;
  37. while (j != args.end())
  38. {
  39. propertyPairs.push_back(*j);
  40. ++j;
  41. if(j == args.end())
  42. {
  43. this->SetError("called with incorrect number of arguments.");
  44. return false;
  45. }
  46. propertyPairs.push_back(*j);
  47. ++j;
  48. }
  49. // break out of the loop because j is already == end
  50. break;
  51. }
  52. else if (doingFiles)
  53. {
  54. numFiles++;
  55. }
  56. else
  57. {
  58. this->SetError("called with illegal arguments, maybe missing "
  59. "a PROPERTIES specifier?");
  60. return false;
  61. }
  62. }
  63. if(propertyPairs.size() == 0)
  64. {
  65. this->SetError("called with illegal arguments, maybe missing "
  66. "a PROPERTIES specifier?");
  67. return false;
  68. }
  69. // now loop over all the targets
  70. int i;
  71. for(i = 0; i < numFiles; ++i)
  72. {
  73. bool ret = cmSetTargetPropertiesCommand::SetOneTarget
  74. (args[i].c_str(),propertyPairs,this->Makefile);
  75. if (!ret)
  76. {
  77. std::string message = "Can not find target to add properties to: ";
  78. message += args[i];
  79. this->SetError(message.c_str());
  80. return false;
  81. }
  82. }
  83. return true;
  84. }
  85. bool cmSetTargetPropertiesCommand
  86. ::SetOneTarget(const char *tname,
  87. std::vector<std::string> &propertyPairs,
  88. cmMakefile *mf)
  89. {
  90. if(cmTarget* target = mf->FindTargetToUse(tname))
  91. {
  92. // now loop through all the props and set them
  93. unsigned int k;
  94. for (k = 0; k < propertyPairs.size(); k = k + 2)
  95. {
  96. target->SetProperty(propertyPairs[k].c_str(),
  97. propertyPairs[k+1].c_str());
  98. }
  99. }
  100. // if file is not already in the makefile, then add it
  101. else
  102. {
  103. return false;
  104. }
  105. return true;
  106. }