cmAddCustomTargetCommand.cxx 3.2 KB

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