On Sunday 26 September 2010, Alexander Neundorf wrote:
> On Sunday 26 September 2010, Alexander Neundorf wrote:
> > On Saturday 25 September 2010, Eric Noulard wrote:
> > > 2010/9/25 Alexander Neundorf <[email protected]>:
> > > [..]
> > >
> > > > The other option would be to make sure that
> > > > INCLUDE(FindPackageHandleStandardArgs)
> > > > when used in cmake's own module would always load
> > > > FindPackageHandleStandardArgs.cmake from cmake, i.e. code like:
> > > >
> > > > GET_FILENAME_COMPONENT(_currentDir "${CMAKE_CURRENT_LIST_FILE}" PATH)
> > > > INCLUDE("${_currentDir}/FindPackageHandleStandardArgs.cmake")
> > > >
> > > >
> > > > Should all
> > > > INCLUDE(FindPackageHandleStandardArgs)
> > > > in all find-modules from cmake be changed to this ?
> > >
> > > I don't think it's a good idea.
> > > People may purposely want to override CMake provided module
> > > in order to implement specific behavior and/or to patch locally.
> >
> > This is what we do in KDE, and I think it would be good for us.
> >
> > Using
> > include(FPHSA CURRENT_DIR)
> > in the files in cmake would mean that the find-modules in cmake also get
> > the FPHSA they expect to get, and if we would use that in KDE too, we
> > would be sure we would get our modified version.
>
> Another option would be to add a new automatic cmake variable
> CMAKE_CURRENT_LIST_FILE_DIR, so we could simply do
>
> INCLUDE(${CMAKE_CURRENT_LIST_FILE_DIR}/FindPackageHandleStandardArgs.cmake)
>
> Wouldn't require any changes to include(), and can be used also for other
> things.

First version of a patch is attached.

Alex
diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index 3fc0fb1..ed9173e 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -76,6 +76,26 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
      "This is the line number of the file currently being"
      " processed by cmake.", false,
      "Variables that Provide Information");
+
+  cm->DefineProperty
+    ("CMAKE_CURRENT_LIST_FILE_DIR", cmProperty::VARIABLE,
+     "Full directory of the listfile currently being processed.",
+     "As CMake processes the listfiles in your project this "
+     "variable will always be set to the directory where the listfile which "
+     "is currently being processed (CMAKE_CURRENT_LIST_FILE) is located.  "
+     "The value has dynamic scope.  "
+     "When CMake starts processing commands in a source file "
+     "it sets this variable to the location of the file.  "
+     "When CMake finishes processing commands from the file it "
+     "restores the previous value.  "
+     "Therefore the value of the variable inside a macro or "
+     "function is the directory of the file invoking the bottom-most entry on "
+     "the call stack, not the directory of the file containing the macro or "
+     "function definition."
+     "\n"
+     "See also CMAKE_CURRENT_LIST_FILE.",false,
+     "Variables that Provide Information");
+
   cm->DefineProperty
     ("CMAKE_BUILD_TOOL", cmProperty::VARIABLE,
      "Tool used for the actual build process.",
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index a69fee7..ecbb965 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -610,6 +610,9 @@ bool cmMakefile::ReadListFile(const char* filename_in,
     }
 
   this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread);
+  this->AddDefinition("CMAKE_CURRENT_LIST_FILE_DIR",
+                      cmSystemTools::GetFilenamePath(filenametoread).c_str());
+
 
   // try to see if the list file is the top most
   // list file for a project, and if it is, then it
@@ -643,6 +646,8 @@ bool cmMakefile::ReadListFile(const char* filename_in,
       }
     this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
     this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
+    this->AddDefinition("CMAKE_CURRENT_LIST_FILE_DIR",
+                        cmSystemTools::GetFilenamePath(currentFile).c_str());
     return false;
     }
   // add this list file to the list of dependencies
@@ -683,6 +688,8 @@ bool cmMakefile::ReadListFile(const char* filename_in,
 
   this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
   this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
+  this->AddDefinition("CMAKE_CURRENT_LIST_FILE_DIR",
+                      cmSystemTools::GetFilenamePath(currentFile).c_str());
 
   // pop the listfile off the stack
   this->ListFileStack.pop_back();
_______________________________________________
cmake-developers mailing list
[email protected]
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to