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.

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