You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.6 KiB

  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 "cmSourceGroupCommand.h"
  14. inline std::vector<std::string> tokenize(const std::string& str,
  15. const std::string& sep)
  16. {
  17. std::vector<std::string> tokens;
  18. std::string::size_type tokend = 0;
  19. do
  20. {
  21. std::string::size_type tokstart=str.find_first_not_of(sep, tokend);
  22. if (tokstart==std::string::npos)
  23. {
  24. break; // no more tokens
  25. }
  26. tokend=str.find_first_of(sep,tokstart);
  27. if (tokend==std::string::npos)
  28. {
  29. tokens.push_back(str.substr(tokstart));
  30. }
  31. else
  32. {
  33. tokens.push_back(str.substr(tokstart,tokend-tokstart));
  34. }
  35. } while (tokend!=std::string::npos);
  36. if (tokens.empty())
  37. {
  38. tokens.push_back("");
  39. }
  40. return tokens;
  41. }
  42. // cmSourceGroupCommand
  43. bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args)
  44. {
  45. if(args.size() < 1)
  46. {
  47. this->SetError("called with incorrect number of arguments");
  48. return false;
  49. }
  50. std::string delimiter = "\\";
  51. if(this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"))
  52. {
  53. delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
  54. }
  55. std::vector<std::string> folders = tokenize(args[0], delimiter);
  56. cmSourceGroup* sg = 0;
  57. sg = this->Makefile->GetSourceGroup(folders);
  58. if(!sg)
  59. {
  60. this->Makefile->AddSourceGroup(folders);
  61. sg = this->Makefile->GetSourceGroup(folders);
  62. }
  63. if(!sg)
  64. {
  65. this->SetError("Could not create or find source group");
  66. return false;
  67. }
  68. // If only two arguments are given, the pre-1.8 version of the
  69. // command is being invoked.
  70. if(args.size() == 2 && args[1] != "FILES")
  71. {
  72. sg->SetGroupRegex(args[1].c_str());
  73. return true;
  74. }
  75. // Process arguments.
  76. bool doingFiles = false;
  77. for(unsigned int i=1; i < args.size(); ++i)
  78. {
  79. if(args[i] == "REGULAR_EXPRESSION")
  80. {
  81. // Next argument must specify the regex.
  82. if(i+1 < args.size())
  83. {
  84. ++i;
  85. sg->SetGroupRegex(args[i].c_str());
  86. }
  87. else
  88. {
  89. this->SetError("REGULAR_EXPRESSION argument given without a regex.");
  90. return false;
  91. }
  92. doingFiles = false;
  93. }
  94. else if(args[i] == "FILES")
  95. {
  96. // Next arguments will specify files.
  97. doingFiles = true;
  98. }
  99. else if(doingFiles)
  100. {
  101. // Convert name to full path and add to the group's list.
  102. std::string src = args[i].c_str();
  103. if(!cmSystemTools::FileIsFullPath(src.c_str()))
  104. {
  105. src = this->Makefile->GetCurrentDirectory();
  106. src += "/";
  107. src += args[i];
  108. }
  109. src = cmSystemTools::CollapseFullPath(src.c_str());
  110. sg->AddGroupFile(src.c_str());
  111. }
  112. else
  113. {
  114. cmOStringStream err;
  115. err << "Unknown argument \"" << args[i].c_str() << "\". "
  116. << "Perhaps the FILES keyword is missing.\n";
  117. this->SetError(err.str().c_str());
  118. return false;
  119. }
  120. }
  121. return true;
  122. }