summaryrefslogtreecommitdiffstats
path: root/Source/cmFunctionCommand.cxx
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2019-12-08 00:26:14 (GMT)
committerAlex Turbov <i.zaufi@gmail.com>2019-12-10 14:43:27 (GMT)
commit90e3e2a7778dc0ec5b421e9657ec49936a3cf174 (patch)
tree6788ff83fc4a9cd7e0e87a2f33f7a3cf0d87d216 /Source/cmFunctionCommand.cxx
parentdd54290dab61c3342866c71052145271c13468ad (diff)
downloadCMake-90e3e2a7778dc0ec5b421e9657ec49936a3cf174.zip
CMake-90e3e2a7778dc0ec5b421e9657ec49936a3cf174.tar.gz
CMake-90e3e2a7778dc0ec5b421e9657ec49936a3cf174.tar.bz2
cmFunctionCommand: Introduce `CMAKE_CURRENT_FUNCTION*` variables
`CMAKE_CURRENT_FUNCTION` Can be used for diagnostic or debugging messages like the `__PRETTY_FUNCTION__` macro of GCC. `CMAKE_CURRENT_FUNCTION_LIST_DIR` Eliminates the necessity of the additional "global" variables inside a module used to access additional "resource" files from functions defined in the module. ...
Diffstat (limited to 'Source/cmFunctionCommand.cxx')
-rw-r--r--Source/cmFunctionCommand.cxx21
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx
index bd96115..4b2f145 100644
--- a/Source/cmFunctionCommand.cxx
+++ b/Source/cmFunctionCommand.cxx
@@ -18,11 +18,19 @@
#include "cmRange.h"
#include "cmState.h"
#include "cmStringAlgorithms.h"
+#include "cmSystemTools.h"
namespace {
std::string const ARGC = "ARGC";
std::string const ARGN = "ARGN";
std::string const ARGV = "ARGV";
+std::string const CMAKE_CURRENT_FUNCTION = "CMAKE_CURRENT_FUNCTION";
+std::string const CMAKE_CURRENT_FUNCTION_LIST_FILE =
+ "CMAKE_CURRENT_FUNCTION_LIST_FILE";
+std::string const CMAKE_CURRENT_FUNCTION_LIST_DIR =
+ "CMAKE_CURRENT_FUNCTION_LIST_DIR";
+std::string const CMAKE_CURRENT_FUNCTION_LIST_LINE =
+ "CMAKE_CURRENT_FUNCTION_LIST_LINE";
// define the class for function commands
class cmFunctionHelperCommand
@@ -39,6 +47,7 @@ public:
std::vector<cmListFileFunction> Functions;
cmPolicies::PolicyMap Policies;
std::string FilePath;
+ long Line;
};
bool cmFunctionHelperCommand::operator()(
@@ -89,6 +98,17 @@ bool cmFunctionHelperCommand::operator()(
makefile.AddDefinition(ARGN, argnDef);
makefile.MarkVariableAsUsed(ARGN);
+ makefile.AddDefinition(CMAKE_CURRENT_FUNCTION, this->Args.front());
+ makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION);
+ makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_FILE, this->FilePath);
+ makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION_LIST_FILE);
+ makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_DIR,
+ cmSystemTools::GetFilenamePath(this->FilePath));
+ makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION_LIST_DIR);
+ makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_LINE,
+ std::to_string(this->Line));
+ makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION_LIST_LINE);
+
// Invoke all the functions that were collected in the block.
// for each function
for (cmListFileFunction const& func : this->Functions) {
@@ -143,6 +163,7 @@ bool cmFunctionFunctionBlocker::Replay(
f.Args = this->Args;
f.Functions = std::move(functions);
f.FilePath = this->GetStartingContext().FilePath;
+ f.Line = this->GetStartingContext().Line;
mf.RecordPolicies(f.Policies);
mf.GetState()->AddScriptedCommand(this->Args.front(), std::move(f));
return true;