From 41e4f1a2109cc03008ef0d1db5cab1c9345866e3 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Tue, 28 Sep 2010 22:09:14 +0200 Subject: Add automatic variable CMAKE_CURRENT_LIST_DIR(dir of CMAKE_CURRENT_LIST_FILE) Comes with a simple test and docs. Alex --- Source/cmDocumentVariables.cxx | 19 +++++++++++++++++++ Source/cmMakefile.cxx | 6 ++++++ Tests/CMakeTests/IncludeTest.cmake.in | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx index a1fb064..a877680 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 a69fee7..e32619a 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 01cec38..eca679b 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) -- cgit v0.12