cmSetTargetPropertiesCommand.cxx 3.1 KB

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