cmConfigureFileCommand.cxx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. m_InputFile = args[0];
  24. m_OuputFile = args[1];
  25. m_CopyOnly = false;
  26. m_EscapeQuotes = false;
  27. // for CMake 2.0 and earlier CONFIGURE_FILE defaults to the FinalPass,
  28. // after 2.0 it only does InitialPass
  29. m_Immediate = false;
  30. const char* versionValue
  31. = m_Makefile->GetRequiredDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
  32. if (atof(versionValue) > 2.0)
  33. {
  34. m_Immediate = true;
  35. }
  36. m_AtOnly = false;
  37. for(unsigned int i=2;i < args.size();++i)
  38. {
  39. if(args[i] == "COPYONLY")
  40. {
  41. m_CopyOnly = true;
  42. }
  43. else if(args[i] == "ESCAPE_QUOTES")
  44. {
  45. m_EscapeQuotes = true;
  46. }
  47. else if(args[i] == "@ONLY")
  48. {
  49. m_AtOnly = true;
  50. }
  51. else if(args[i] == "IMMEDIATE")
  52. {
  53. m_Immediate = true;
  54. }
  55. }
  56. // If we were told to copy the file immediately, then do it on the
  57. // first pass (now).
  58. if(m_Immediate)
  59. {
  60. if ( !this->ConfigureFile() )
  61. {
  62. this->SetError("Problem configuring file");
  63. return false;
  64. }
  65. }
  66. return true;
  67. }
  68. void cmConfigureFileCommand::FinalPass()
  69. {
  70. if(!m_Immediate)
  71. {
  72. this->ConfigureFile();
  73. }
  74. }
  75. int cmConfigureFileCommand::ConfigureFile()
  76. {
  77. return m_Makefile->ConfigureFile(m_InputFile.c_str(),
  78. m_OuputFile.c_str(),
  79. m_CopyOnly,
  80. m_AtOnly,
  81. m_EscapeQuotes);
  82. }