cmSetSourceFilesPropertiesCommand.cxx 5.1 KB

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