Ver Fonte

Teach configure_file to handle relative paths

The configure_file() command now converts relative output paths to full
paths using the current binary directory.  Input relative paths were
already converted using the current source directory, but this behavior
was not previously documented.
Brad King há 16 anos atrás
pai
commit
700cdf393a
2 ficheiros alterados com 27 adições e 12 exclusões
  1. 19 10
      Source/cmConfigureFileCommand.cxx
  2. 8 2
      Source/cmConfigureFileCommand.h

+ 19 - 10
Source/cmConfigureFileCommand.cxx

@@ -27,8 +27,23 @@ bool cmConfigureFileCommand
     this->SetError("called with incorrect number of arguments, expected 2");
     this->SetError("called with incorrect number of arguments, expected 2");
     return false;
     return false;
     }
     }
-  this->InputFile = args[0];
-  this->OutputFile = args[1];
+
+  const char* inFile = args[0].c_str();
+  if(!cmSystemTools::FileIsFullPath(inFile))
+    {
+    this->InputFile = this->Makefile->GetCurrentDirectory();
+    this->InputFile += "/";
+    }
+  this->InputFile += inFile;
+
+  const char* outFile = args[1].c_str();
+  if(!cmSystemTools::FileIsFullPath(outFile))
+    {
+    this->OutputFile = this->Makefile->GetCurrentOutputDirectory();
+    this->OutputFile += "/";
+    }
+  this->OutputFile += outFile;
+
   if ( !this->Makefile->CanIWriteThisFile(this->OutputFile.c_str()) )
   if ( !this->Makefile->CanIWriteThisFile(this->OutputFile.c_str()) )
     {
     {
     std::string e = "attempted to configure a file: " + this->OutputFile
     std::string e = "attempted to configure a file: " + this->OutputFile
@@ -89,14 +104,8 @@ void cmConfigureFileCommand::FinalPass()
 
 
 int cmConfigureFileCommand::ConfigureFile()
 int cmConfigureFileCommand::ConfigureFile()
 {
 {
-  std::string inFile = this->InputFile;
-  if (!cmSystemTools::FileIsFullPath(inFile.c_str()))
-    {
-    inFile = this->Makefile->GetStartDirectory();
-    inFile += "/";
-    inFile += this->InputFile;
-    }
-  return this->Makefile->ConfigureFile(inFile.c_str(),
+  return this->Makefile->ConfigureFile(
+    this->InputFile.c_str(),
     this->OutputFile.c_str(),
     this->OutputFile.c_str(),
     this->CopyOnly,
     this->CopyOnly,
     this->AtOnly,
     this->AtOnly,

+ 8 - 2
Source/cmConfigureFileCommand.h

@@ -60,9 +60,15 @@ public:
   virtual const char* GetFullDocumentation()
   virtual const char* GetFullDocumentation()
     {
     {
       return
       return
-        "  configure_file(InputFile OutputFile\n"
+        "  configure_file(<input> <output>\n"
         "                 [COPYONLY] [ESCAPE_QUOTES] [@ONLY])\n"
         "                 [COPYONLY] [ESCAPE_QUOTES] [@ONLY])\n"
-        "The Input and Output files have to have full paths.  "
+        "Copies a file <input> to file <output> and substitutes variable "
+        "values referenced in the file content.  "
+        "If <input> is a relative path it is evaluated with respect to "
+        "the current source directory.  "
+        "If <output> is a relative path it is evaluated with respect to "
+        "the current binary directory.  "
+        "\n"
         "This command replaces any variables in the input file referenced as "
         "This command replaces any variables in the input file referenced as "
         "${VAR} or @VAR@ with their values as determined by CMake.  If a "
         "${VAR} or @VAR@ with their values as determined by CMake.  If a "
         "variable is not defined, it will be replaced with nothing.  "
         "variable is not defined, it will be replaced with nothing.  "