summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Neundorf <neundorf@kde.org>2010-09-28 22:09:14 +0200
committerAlex Neundorf <neundorf@kde.org>2010-09-28 22:10:47 +0200
commit41e4f1a2109cc03008ef0d1db5cab1c9345866e3 (patch)
tree588fe929d70a87772f0cf48a3295cdef4bb5e489
parentf9fc79cac54b1d97afb65075b949bac264961439 (diff)
downloadcmake-41e4f1a2109cc03008ef0d1db5cab1c9345866e3.tar.gz
Add automatic variable CMAKE_CURRENT_LIST_DIR(dir of CMAKE_CURRENT_LIST_FILE)
Comes with a simple test and docs. Alex
-rw-r--r--Source/cmDocumentVariables.cxx19
-rw-r--r--Source/cmMakefile.cxx6
-rw-r--r--Tests/CMakeTests/IncludeTest.cmake.in4
3 files changed, 29 insertions, 0 deletions
diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index a1fb0640fe..a877680dea 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -78,6 +78,25 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
"Variables that Provide Information");
cm->DefineProperty
+ ("CMAKE_CURRENT_LIST_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 directory where this file is located. "
+ "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.",
"This variable is set to the program that will be"
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index a69fee7232..e32619ac63 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -610,6 +610,8 @@ bool cmMakefile::ReadListFile(const char* filename_in,
}
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread);
+ this->AddDefinition("CMAKE_CURRENT_LIST_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 +645,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_DIR",
+ cmSystemTools::GetFilenamePath(currentFile).c_str());
return false;
}
// add this list file to the list of dependencies
@@ -683,6 +687,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_DIR",
+ cmSystemTools::GetFilenamePath(currentFile).c_str());
// pop the listfile off the stack
this->ListFileStack.pop_back();
diff --git a/Tests/CMakeTests/IncludeTest.cmake.in b/Tests/CMakeTests/IncludeTest.cmake.in
index 01cec38f40..eca679b4a3 100644
--- a/Tests/CMakeTests/IncludeTest.cmake.in
+++ b/Tests/CMakeTests/IncludeTest.cmake.in
@@ -35,3 +35,7 @@ if(NOT "${fileOne}" STREQUAL "${fileTwo}")
message(FATAL_ERROR "Wrong CMake.cmake was included: \"${fileOne}\" expected \"${fileTwo}\"")
endif(NOT "${fileOne}" STREQUAL "${fileTwo}")
+# Check that CMAKE_CURRENT_LIST_DIR is working:
+# Needs to be a file in the build tree, which is correct cmake script
+# but doesn't do a lot, if possible only set() commands:
+include(${CMAKE_CURRENT_LIST_DIR}/../../CTestCustom.cmake)