cmConfigureFileCommand.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "cmConfigureFileCommand.h"
  14. #include <cmsys/RegularExpression.hxx>
  15. // cmConfigureFileCommand
  16. bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 2 )
  19. {
  20. this->SetError("called with incorrect number of arguments, expected 2");
  21. return false;
  22. }
  23. this->InputFile = args[0];
  24. this->OuputFile = args[1];
  25. if ( !this->Makefile->CanIWriteThisFile(this->OuputFile.c_str()) )
  26. {
  27. std::string e = "attempted to configure a file: " + this->OuputFile + " into a source directory.";
  28. this->SetError(e.c_str());
  29. cmSystemTools::SetFatalErrorOccured();
  30. return false;
  31. }
  32. this->CopyOnly = false;
  33. this->EscapeQuotes = false;
  34. // for CMake 2.0 and earlier CONFIGURE_FILE defaults to the FinalPass,
  35. // after 2.0 it only does InitialPass
  36. this->Immediate = false;
  37. const char* versionValue
  38. = this->Makefile->GetRequiredDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  39. if (atof(versionValue) > 2.0)
  40. {
  41. this->Immediate = true;
  42. }
  43. this->AtOnly = false;
  44. for(unsigned int i=2;i < args.size();++i)
  45. {
  46. if(args[i] == "COPYONLY")
  47. {
  48. this->CopyOnly = true;
  49. }
  50. else if(args[i] == "ESCAPE_QUOTES")
  51. {
  52. this->EscapeQuotes = true;
  53. }
  54. else if(args[i] == "@ONLY")
  55. {
  56. this->AtOnly = true;
  57. }
  58. else if(args[i] == "IMMEDIATE")
  59. {
  60. this->Immediate = true;
  61. }
  62. }
  63. // If we were told to copy the file immediately, then do it on the
  64. // first pass (now).
  65. if(this->Immediate)
  66. {
  67. if ( !this->ConfigureFile() )
  68. {
  69. this->SetError("Problem configuring file");
  70. return false;
  71. }
  72. }
  73. return true;
  74. }
  75. void cmConfigureFileCommand::FinalPass()
  76. {
  77. if(!this->Immediate)
  78. {
  79. this->ConfigureFile();
  80. }
  81. }
  82. int cmConfigureFileCommand::ConfigureFile()
  83. {
  84. std::string inFile = this->InputFile;
  85. if (!cmSystemTools::FileIsFullPath(inFile.c_str()))
  86. {
  87. inFile = this->Makefile->GetStartDirectory();
  88. inFile += "/";
  89. inFile += this->InputFile;
  90. }
  91. return this->Makefile->ConfigureFile(inFile.c_str(),
  92. this->OuputFile.c_str(),
  93. this->CopyOnly,
  94. this->AtOnly,
  95. this->EscapeQuotes);
  96. }