cmSetPropertiesCommand.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 "cmSetPropertiesCommand.h"
  14. #include "cmSetTargetPropertiesCommand.h"
  15. // cmSetPropertiesCommand
  16. bool cmSetPropertiesCommand::InitialPass(
  17. std::vector<std::string> const& args)
  18. {
  19. if(args.size() < 2 )
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. // first collect up the list of files
  25. std::vector<std::string> propertyPairs;
  26. bool doingFiles = true;
  27. int numFiles = 0;
  28. std::vector<std::string>::const_iterator j;
  29. for(j= args.begin(); j != args.end();++j)
  30. {
  31. if(*j == "PROPERTIES")
  32. {
  33. doingFiles = false;
  34. // now loop through the rest of the arguments, new style
  35. ++j;
  36. while (j != args.end())
  37. {
  38. propertyPairs.push_back(*j);
  39. ++j;
  40. if(j == args.end())
  41. {
  42. this->SetError("called with incorrect number of arguments.");
  43. return false;
  44. }
  45. propertyPairs.push_back(*j);
  46. ++j;
  47. }
  48. // break out of the loop because j is already == end
  49. break;
  50. }
  51. else if (doingFiles)
  52. {
  53. numFiles++;
  54. }
  55. else
  56. {
  57. this->SetError("called with illegal arguments, maybe missing "
  58. "a PROPERTIES specifier?");
  59. return false;
  60. }
  61. }
  62. if(propertyPairs.size() == 0)
  63. {
  64. this->SetError("called with illegal arguments, maybe missing "
  65. "a PROPERTIES specifier?");
  66. return false;
  67. }
  68. cmProperty::ScopeType scope;
  69. const char *scopeName = 0;
  70. if (args[0] == "GLOBAL" && numFiles == 1)
  71. {
  72. scope = cmProperty::GLOBAL;
  73. }
  74. else if (args[0] == "DIRECTORY" && numFiles == 1)
  75. {
  76. scope = cmProperty::DIRECTORY;
  77. }
  78. else if (args[0] == "TARGET" && numFiles == 2)
  79. {
  80. scope = cmProperty::TARGET;
  81. scopeName = args[1].c_str();
  82. }
  83. else
  84. {
  85. this->SetError("called with illegal arguments.");
  86. return false;
  87. }
  88. switch (scope)
  89. {
  90. case cmProperty::TARGET:
  91. {
  92. bool ret = cmSetTargetPropertiesCommand::
  93. SetOneTarget(scopeName,propertyPairs, this->Makefile);
  94. if (!ret)
  95. {
  96. std::string message = "Can not find target to add properties to: ";
  97. message += scopeName;
  98. this->SetError(message.c_str());
  99. }
  100. return ret;
  101. }
  102. break;
  103. case cmProperty::DIRECTORY:
  104. {
  105. std::string errors;
  106. bool ret =
  107. cmSetDirectoryPropertiesCommand::RunCommand(this->Makefile,
  108. args.begin() + 2,
  109. args.end(),
  110. errors);
  111. if (!ret)
  112. {
  113. this->SetError(errors.c_str());
  114. return ret;
  115. }
  116. }
  117. break;
  118. case cmProperty::GLOBAL:
  119. {
  120. std::vector<std::string>::const_iterator j;
  121. for(j= propertyPairs.begin(); j != propertyPairs.end(); ++j)
  122. {
  123. this->Makefile->GetCMakeInstance()->SetProperty(j->c_str(),
  124. (++j)->c_str());
  125. }
  126. }
  127. break;
  128. }
  129. return true;
  130. }