cmSetSourceFilesPropertiesCommand.cxx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 "
  60. "COMPILE_FLAGS with no flags");
  61. return false;
  62. }
  63. propertyPairs.push_back(*j);
  64. }
  65. else if(*j == "OBJECT_DEPENDS")
  66. {
  67. doingFiles = false;
  68. propertyPairs.push_back("OBJECT_DEPENDS");
  69. ++j;
  70. if(j == args.end())
  71. {
  72. this->SetError("called with incorrect number of arguments "
  73. "OBJECT_DEPENDS with no dependencies");
  74. return false;
  75. }
  76. propertyPairs.push_back(*j);
  77. }
  78. else if(*j == "PROPERTIES")
  79. {
  80. // now loop through the rest of the arguments, new style
  81. ++j;
  82. bool dontPush = false;
  83. while (j != args.end())
  84. {
  85. propertyPairs.push_back(*j);
  86. if(*j == "GENERATED")
  87. {
  88. ++j;
  89. if(j != args.end() && cmSystemTools::IsOn(j->c_str()))
  90. {
  91. generated = true;
  92. }
  93. }
  94. else if(*j == "MACOSX_PACKAGE_LOCATION")
  95. {
  96. ++j;
  97. if(j == args.end())
  98. {
  99. this->SetError("called with incorrect number of arguments "
  100. "MACOSX_PACKAGE_LOCATION with no flags");
  101. return false;
  102. }
  103. propertyPairs.push_back(*j);
  104. propertyPairs.push_back("EXTRA_CONTENT");
  105. propertyPairs.push_back("1");
  106. propertyPairs.push_back("KEEP_EXTENSION");
  107. propertyPairs.push_back("1");
  108. propertyPairs.push_back("LANGUAGE");
  109. propertyPairs.push_back("MacOSX_Content");
  110. dontPush = true;
  111. }
  112. else
  113. {
  114. ++j;
  115. }
  116. if(j == args.end())
  117. {
  118. this->SetError("called with incorrect number of arguments.");
  119. return false;
  120. }
  121. if ( !dontPush )
  122. {
  123. propertyPairs.push_back(*j);
  124. }
  125. ++j;
  126. dontPush = false;
  127. }
  128. // break out of the loop because j is already == end
  129. break;
  130. }
  131. else if (doingFiles)
  132. {
  133. numFiles++;
  134. }
  135. else
  136. {
  137. this->SetError("called with illegal arguments, maybe missing a "
  138. "PROPERTIES specifier?");
  139. return false;
  140. }
  141. }
  142. // now loop over all the files
  143. int i;
  144. unsigned int k;
  145. for(i = 0; i < numFiles; ++i)
  146. {
  147. // get the source file
  148. cmSourceFile* sf =
  149. this->Makefile->GetOrCreateSource(args[i].c_str(), generated);
  150. if(sf)
  151. {
  152. // now loop through all the props and set them
  153. for (k = 0; k < propertyPairs.size(); k = k + 2)
  154. {
  155. sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  156. }
  157. }
  158. }
  159. return true;
  160. }