cmSetSourceFilesPropertiesCommand.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 "cmSetSourceFilesPropertiesCommand.h"
  14. #include "cmSourceFile.h"
  15. // cmSetSourceFilesPropertiesCommand
  16. bool cmSetSourceFilesPropertiesCommand::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. bool generated = false;
  28. int numFiles = 0;
  29. std::vector<std::string>::const_iterator j;
  30. for(j= args.begin(); j != args.end();++j)
  31. {
  32. // old style allows for specifier before PROPERTIES keyword
  33. if(*j == "ABSTRACT")
  34. {
  35. doingFiles = false;
  36. propertyPairs.push_back("ABSTRACT");
  37. propertyPairs.push_back("1");
  38. }
  39. else if(*j == "WRAP_EXCLUDE")
  40. {
  41. doingFiles = false;
  42. propertyPairs.push_back("WRAP_EXCLUDE");
  43. propertyPairs.push_back("1");
  44. }
  45. else if(*j == "GENERATED")
  46. {
  47. doingFiles = false;
  48. generated = true;
  49. propertyPairs.push_back("GENERATED");
  50. propertyPairs.push_back("1");
  51. }
  52. else if(*j == "COMPILE_FLAGS")
  53. {
  54. doingFiles = false;
  55. propertyPairs.push_back("COMPILE_FLAGS");
  56. ++j;
  57. if(j == args.end())
  58. {
  59. this->SetError("called with incorrect number of arguments COMPILE_FLAGS with no flags");
  60. return false;
  61. }
  62. propertyPairs.push_back(*j);
  63. }
  64. else if(*j == "OBJECT_DEPENDS")
  65. {
  66. doingFiles = false;
  67. propertyPairs.push_back("OBJECT_DEPENDS");
  68. ++j;
  69. if(j == args.end())
  70. {
  71. this->SetError("called with incorrect number of arguments "
  72. "OBJECT_DEPENDS with no dependencies");
  73. return false;
  74. }
  75. propertyPairs.push_back(*j);
  76. }
  77. else if(*j == "PROPERTIES")
  78. {
  79. // now loop through the rest of the arguments, new style
  80. ++j;
  81. while (j != args.end())
  82. {
  83. propertyPairs.push_back(*j);
  84. if(*j == "GENERATED")
  85. {
  86. ++j;
  87. if(j != args.end() && cmSystemTools::IsOn(j->c_str()))
  88. {
  89. generated = true;
  90. }
  91. }
  92. else
  93. {
  94. ++j;
  95. }
  96. if(j == args.end())
  97. {
  98. this->SetError("called with incorrect number of arguments.");
  99. return false;
  100. }
  101. propertyPairs.push_back(*j);
  102. ++j;
  103. }
  104. // break out of the loop because j is already == end
  105. break;
  106. }
  107. else if (doingFiles)
  108. {
  109. numFiles++;
  110. }
  111. else
  112. {
  113. this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
  114. return false;
  115. }
  116. }
  117. // now loop over all the files
  118. int i;
  119. unsigned int k;
  120. for(i = 0; i < numFiles; ++i)
  121. {
  122. // get the source file
  123. cmSourceFile* sf =
  124. m_Makefile->GetOrCreateSource(args[i].c_str(), generated);
  125. if(sf)
  126. {
  127. // now loop through all the props and set them
  128. for (k = 0; k < propertyPairs.size(); k = k + 2)
  129. {
  130. sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  131. }
  132. }
  133. }
  134. return true;
  135. }