Add automatic variable CMAKE_CURRENT_LIST_DIR(dir of CMAKE_CURRENT_LIST_FILE)
Comes with a simple test and docs. Alex
This commit is contained in:
parent
f9fc79cac5
commit
41e4f1a210
@ -77,6 +77,25 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
|
|||||||
" processed by cmake.", false,
|
" processed by cmake.", false,
|
||||||
"Variables that Provide Information");
|
"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
|
cm->DefineProperty
|
||||||
("CMAKE_BUILD_TOOL", cmProperty::VARIABLE,
|
("CMAKE_BUILD_TOOL", cmProperty::VARIABLE,
|
||||||
"Tool used for the actual build process.",
|
"Tool used for the actual build process.",
|
||||||
|
@ -610,6 +610,8 @@ bool cmMakefile::ReadListFile(const char* filename_in,
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", filenametoread);
|
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
|
// try to see if the list file is the top most
|
||||||
// list file for a project, and if it is, then it
|
// 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_PARENT_LIST_FILE", currentParentFile.c_str());
|
||||||
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
|
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
|
||||||
|
this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
|
||||||
|
cmSystemTools::GetFilenamePath(currentFile).c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// add this list file to the list of dependencies
|
// 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_PARENT_LIST_FILE", currentParentFile.c_str());
|
||||||
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.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
|
// pop the listfile off the stack
|
||||||
this->ListFileStack.pop_back();
|
this->ListFileStack.pop_back();
|
||||||
|
@ -35,3 +35,7 @@ if(NOT "${fileOne}" STREQUAL "${fileTwo}")
|
|||||||
message(FATAL_ERROR "Wrong CMake.cmake was included: \"${fileOne}\" expected \"${fileTwo}\"")
|
message(FATAL_ERROR "Wrong CMake.cmake was included: \"${fileOne}\" expected \"${fileTwo}\"")
|
||||||
endif(NOT "${fileOne}" STREQUAL "${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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user