cmSetSourceFilesPropertiesCommand.cxx 5.2 KB

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