cmSetSourceFilesPropertiesCommand.cxx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. // cmSetSourceFilesPropertiesCommand
  15. bool cmSetSourceFilesPropertiesCommand::InitialPass(
  16. std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 2 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // first collect up the list of files
  24. std::vector<std::string> propertyPairs;
  25. bool doingFiles = true;
  26. int numFiles = 0;
  27. std::vector<std::string>::const_iterator j;
  28. for(j= args.begin(); j != args.end();++j)
  29. {
  30. // old style allows for specifier before PROPERTIES keyword
  31. if(*j == "ABSTRACT")
  32. {
  33. doingFiles = false;
  34. propertyPairs.push_back("ABSTRACT");
  35. propertyPairs.push_back("1");
  36. }
  37. else if(*j == "WRAP_EXCLUDE")
  38. {
  39. doingFiles = false;
  40. propertyPairs.push_back("WRAP_EXCLUDE");
  41. propertyPairs.push_back("1");
  42. }
  43. else if(*j == "GENERATED")
  44. {
  45. doingFiles = false;
  46. propertyPairs.push_back("GENERATED");
  47. propertyPairs.push_back("1");
  48. }
  49. else if(*j == "COMPILE_FLAGS")
  50. {
  51. doingFiles = false;
  52. propertyPairs.push_back("COMPILE_FLAGS");
  53. ++j;
  54. if(j == args.end())
  55. {
  56. this->SetError("called with incorrect number of arguments COMPILE_FLAGS with no flags");
  57. return false;
  58. }
  59. propertyPairs.push_back(*j);
  60. }
  61. else if(*j == "OBJECT_DEPENDS")
  62. {
  63. doingFiles = false;
  64. propertyPairs.push_back("OBJECT_DEPENDS");
  65. ++j;
  66. if(j == args.end())
  67. {
  68. this->SetError("called with incorrect number of arguments "
  69. "OBJECT_DEPENDS with no dependencies");
  70. return false;
  71. }
  72. propertyPairs.push_back(*j);
  73. }
  74. else if(*j == "PROPERTIES")
  75. {
  76. doingFiles = false;
  77. // now loop through the rest of the arguments, new style
  78. ++j;
  79. while (j != args.end())
  80. {
  81. propertyPairs.push_back(*j);
  82. ++j;
  83. if(j == args.end())
  84. {
  85. this->SetError("called with incorrect number of arguments.");
  86. return false;
  87. }
  88. propertyPairs.push_back(*j);
  89. ++j;
  90. }
  91. // break out of the loop because j is already == end
  92. break;
  93. }
  94. else if (doingFiles)
  95. {
  96. numFiles++;
  97. }
  98. else
  99. {
  100. this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
  101. return false;
  102. }
  103. }
  104. // now loop over all the files
  105. int i;
  106. unsigned int k;
  107. for(i = 0; i < numFiles; ++i)
  108. {
  109. // if the file is already in the makefile just set properites on it
  110. cmSourceFile* sf = m_Makefile->GetSource(args[i].c_str());
  111. if(sf)
  112. {
  113. // now loop through all the props and set them
  114. for (k = 0; k < propertyPairs.size(); k = k + 2)
  115. {
  116. sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  117. }
  118. }
  119. // if file is not already in the makefile, then add it
  120. else
  121. {
  122. std::string newfile = args[i];
  123. cmSourceFile file;
  124. std::string path = cmSystemTools::GetFilenamePath(newfile);
  125. // now loop through all the props and set them
  126. for (k = 0; k < propertyPairs.size(); k = k + 2)
  127. {
  128. file.SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  129. }
  130. if(file.GetPropertyAsBool("GENERATED"))
  131. {
  132. std::string ext = cmSystemTools::GetFilenameExtension(newfile);
  133. std::string name_no_ext = cmSystemTools::GetFilenameName(newfile.c_str());
  134. name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
  135. if ( ext.length() && ext[0] == '.' )
  136. {
  137. ext = ext.substr(1);
  138. }
  139. if((path.size() && path[0] == '/') ||
  140. (path.size() > 1 && path[1] == ':'))
  141. {
  142. file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), false);
  143. }
  144. else
  145. {
  146. file.SetName(name_no_ext.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  147. ext.c_str(), false);
  148. }
  149. }
  150. else
  151. {
  152. // if this is a full path then
  153. if((path.size() && path[0] == '/') ||
  154. (path.size() > 1 && path[1] == ':'))
  155. {
  156. file.SetName(cmSystemTools::GetFilenameName(newfile.c_str()).c_str(),
  157. path.c_str(),
  158. m_Makefile->GetSourceExtensions(),
  159. m_Makefile->GetHeaderExtensions());
  160. }
  161. else
  162. {
  163. file.SetName(newfile.c_str(), m_Makefile->GetCurrentDirectory(),
  164. m_Makefile->GetSourceExtensions(),
  165. m_Makefile->GetHeaderExtensions());
  166. }
  167. }
  168. // add the source file to the makefile
  169. m_Makefile->AddSource(file);
  170. }
  171. }
  172. return true;
  173. }