cmAddCustomTargetCommand.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 "cmAddCustomTargetCommand.h"
  14. // cmAddCustomTargetCommand
  15. bool cmAddCustomTargetCommand::InitialPass(
  16. std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 1 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // Accumulate one command line at a time.
  24. cmCustomCommandLine currentLine;
  25. // Save all command lines.
  26. cmCustomCommandLines commandLines;
  27. // Accumulate dependencies.
  28. std::vector<std::string> depends;
  29. std::string working_directory;
  30. // Keep track of parser state.
  31. enum tdoing {
  32. doing_command,
  33. doing_depends,
  34. doing_working_directory
  35. };
  36. tdoing doing = doing_command;
  37. // Look for the ALL option.
  38. bool all = false;
  39. unsigned int start = 1;
  40. if(args.size() > 1)
  41. {
  42. if(args[1] == "ALL")
  43. {
  44. all = true;
  45. start = 2;
  46. }
  47. }
  48. // Parse the rest of the arguments.
  49. for(unsigned int j = start; j < args.size(); ++j)
  50. {
  51. std::string const& copy = args[j];
  52. if(copy == "DEPENDS")
  53. {
  54. doing = doing_depends;
  55. }
  56. else if(copy == "WORKING_DIRECTORY")
  57. {
  58. doing = doing_working_directory;
  59. }
  60. else if(copy == "COMMAND")
  61. {
  62. doing = doing_command;
  63. // Save the current command before starting the next command.
  64. if(!currentLine.empty())
  65. {
  66. commandLines.push_back(currentLine);
  67. currentLine.clear();
  68. }
  69. }
  70. else
  71. {
  72. switch (doing)
  73. {
  74. case doing_working_directory:
  75. working_directory = copy;
  76. break;
  77. case doing_command:
  78. currentLine.push_back(copy);
  79. break;
  80. case doing_depends:
  81. depends.push_back(copy);
  82. break;
  83. default:
  84. this->SetError("Wrong syntax. Unknown type of argument.");
  85. return false;
  86. }
  87. }
  88. }
  89. std::string::size_type pos = args[0].find_first_of("#<>");
  90. if(pos != args[0].npos)
  91. {
  92. cmOStringStream msg;
  93. msg << "called with target name containing a \"" << args[0][pos]
  94. << "\". This character is not allowed.";
  95. this->SetError(msg.str().c_str());
  96. return false;
  97. }
  98. // Store the last command line finished.
  99. if(!currentLine.empty())
  100. {
  101. commandLines.push_back(currentLine);
  102. currentLine.clear();
  103. }
  104. // Add the utility target to the makefile.
  105. const char* no_output = 0;
  106. m_Makefile->AddUtilityCommand(args[0].c_str(), all, no_output,
  107. working_directory.c_str(), depends,
  108. commandLines);
  109. return true;
  110. }