cmSetTargetPropertiesCommand.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.empty())
  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. if (this->Makefile->IsAlias(args[i]))
  71. {
  72. this->SetError("can not be used on an ALIAS target.");
  73. return false;
  74. }
  75. bool ret = cmSetTargetPropertiesCommand::SetOneTarget
  76. (args[i],propertyPairs,this->Makefile);
  77. if (!ret)
  78. {
  79. std::string message = "Can not find target to add properties to: ";
  80. message += args[i];
  81. this->SetError(message);
  82. return false;
  83. }
  84. }
  85. return true;
  86. }
  87. bool cmSetTargetPropertiesCommand
  88. ::SetOneTarget(const std::string& tname,
  89. std::vector<std::string> &propertyPairs,
  90. cmMakefile *mf)
  91. {
  92. if(cmTarget* target = mf->FindTargetToUse(tname))
  93. {
  94. // now loop through all the props and set them
  95. unsigned int k;
  96. for (k = 0; k < propertyPairs.size(); k = k + 2)
  97. {
  98. target->SetProperty(propertyPairs[k],
  99. propertyPairs[k+1].c_str());
  100. target->CheckProperty(propertyPairs[k], mf);
  101. }
  102. }
  103. // if file is not already in the makefile, then add it
  104. else
  105. {
  106. return false;
  107. }
  108. return true;
  109. }