cmConfigureFileCommand.cxx 3.1 KB

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