cmSetSourceFilesPropertiesCommand.cxx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. // now loop through the rest of the arguments, new style
  77. ++j;
  78. while (j != args.end())
  79. {
  80. propertyPairs.push_back(*j);
  81. ++j;
  82. if(j == args.end())
  83. {
  84. this->SetError("called with incorrect number of arguments.");
  85. return false;
  86. }
  87. propertyPairs.push_back(*j);
  88. ++j;
  89. }
  90. // break out of the loop because j is already == end
  91. break;
  92. }
  93. else if (doingFiles)
  94. {
  95. numFiles++;
  96. }
  97. else
  98. {
  99. this->SetError("called with illegal arguments, maybe missing a PROPERTIES specifier?");
  100. return false;
  101. }
  102. }
  103. // now loop over all the files
  104. int i;
  105. unsigned int k;
  106. for(i = 0; i < numFiles; ++i)
  107. {
  108. // if the file is already in the makefile just set properites on it
  109. cmSourceFile* sf = m_Makefile->GetSource(args[i].c_str());
  110. if(sf)
  111. {
  112. // now loop through all the props and set them
  113. for (k = 0; k < propertyPairs.size(); k = k + 2)
  114. {
  115. sf->SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  116. }
  117. }
  118. // if file is not already in the makefile, then add it
  119. else
  120. {
  121. std::string newfile = args[i];
  122. cmSourceFile file;
  123. std::string path = cmSystemTools::GetFilenamePath(newfile);
  124. // now loop through all the props and set them
  125. for (k = 0; k < propertyPairs.size(); k = k + 2)
  126. {
  127. file.SetProperty(propertyPairs[k].c_str(),propertyPairs[k+1].c_str());
  128. }
  129. if(file.GetPropertyAsBool("GENERATED"))
  130. {
  131. std::string ext = cmSystemTools::GetFilenameExtension(newfile);
  132. std::string name_no_ext = cmSystemTools::GetFilenameName(newfile.c_str());
  133. name_no_ext = name_no_ext.substr(0, name_no_ext.length()-ext.length());
  134. if ( ext.length() && ext[0] == '.' )
  135. {
  136. ext = ext.substr(1);
  137. }
  138. if((path.size() && path[0] == '/') ||
  139. (path.size() > 1 && path[1] == ':'))
  140. {
  141. file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), false);
  142. }
  143. else
  144. {
  145. file.SetName(name_no_ext.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  146. ext.c_str(), false);
  147. }
  148. }
  149. else
  150. {
  151. // if this is a full path then
  152. if((path.size() && path[0] == '/') ||
  153. (path.size() > 1 && path[1] == ':'))
  154. {
  155. file.SetName(cmSystemTools::GetFilenameName(newfile.c_str()).c_str(),
  156. path.c_str(),
  157. m_Makefile->GetSourceExtensions(),
  158. m_Makefile->GetHeaderExtensions());
  159. }
  160. else
  161. {
  162. file.SetName(newfile.c_str(), m_Makefile->GetCurrentDirectory(),
  163. m_Makefile->GetSourceExtensions(),
  164. m_Makefile->GetHeaderExtensions());
  165. }
  166. }
  167. // add the source file to the makefile
  168. m_Makefile->AddSource(file);
  169. }
  170. }
  171. return true;
  172. }