summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRegina Pfeifer <regina@mailbox.org>2019-04-08 07:55:52 (GMT)
committerRegina Pfeifer <regina@mailbox.org>2019-07-22 13:27:56 (GMT)
commitdfaa87f1b3335b2e80f68726fd5e1b3bbd87d667 (patch)
treed631728ba6308e21581ab455fd341d9fc92dd11d
parent28f2d12a055e025aa0ddeb9842f204f29181eaff (diff)
downloadCMake-dfaa87f1b3335b2e80f68726fd5e1b3bbd87d667.zip
CMake-dfaa87f1b3335b2e80f68726fd5e1b3bbd87d667.tar.gz
CMake-dfaa87f1b3335b2e80f68726fd5e1b3bbd87d667.tar.bz2
cmState: Support BuiltinCommands as free functions
-rw-r--r--Source/cmCommands.cxx5
-rw-r--r--Source/cmEnableTestingCommand.cxx11
-rw-r--r--Source/cmEnableTestingCommand.h26
-rw-r--r--Source/cmReturnCommand.cxx4
-rw-r--r--Source/cmReturnCommand.h30
-rw-r--r--Source/cmState.cxx17
-rw-r--r--Source/cmState.h3
7 files changed, 34 insertions, 62 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 9ae2f71..f351ff8 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -162,7 +162,7 @@ void GetScriptingCommands(cmState* state)
state->AddBuiltinCommand("option", cm::make_unique<cmOptionCommand>());
state->AddBuiltinCommand("cmake_parse_arguments",
cm::make_unique<cmParseArgumentsCommand>());
- state->AddBuiltinCommand("return", cm::make_unique<cmReturnCommand>());
+ state->AddBuiltinCommand("return", cmReturnCommand);
state->AddBuiltinCommand("separate_arguments",
cm::make_unique<cmSeparateArgumentsCommand>());
state->AddBuiltinCommand("set", cm::make_unique<cmSetCommand>());
@@ -255,8 +255,7 @@ void GetProjectCommands(cmState* state)
cm::make_unique<cmDefinePropertyCommand>());
state->AddBuiltinCommand("enable_language",
cm::make_unique<cmEnableLanguageCommand>());
- state->AddBuiltinCommand("enable_testing",
- cm::make_unique<cmEnableTestingCommand>());
+ state->AddBuiltinCommand("enable_testing", cmEnableTestingCommand);
state->AddBuiltinCommand("get_source_file_property",
cm::make_unique<cmGetSourceFilePropertyCommand>());
state->AddBuiltinCommand("get_target_property",
diff --git a/Source/cmEnableTestingCommand.cxx b/Source/cmEnableTestingCommand.cxx
index 6a64450..89212c8 100644
--- a/Source/cmEnableTestingCommand.cxx
+++ b/Source/cmEnableTestingCommand.cxx
@@ -2,15 +2,12 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmEnableTestingCommand.h"
+#include "cmExecutionStatus.h"
#include "cmMakefile.h"
-class cmExecutionStatus;
-
-// we do this in the final pass so that we now the subdirs have all
-// been defined
-bool cmEnableTestingCommand::InitialPass(std::vector<std::string> const&,
- cmExecutionStatus&)
+bool cmEnableTestingCommand(std::vector<std::string> const&,
+ cmExecutionStatus& status)
{
- this->Makefile->AddDefinition("CMAKE_TESTING_ENABLED", "1");
+ status.GetMakefile().AddDefinition("CMAKE_TESTING_ENABLED", "1");
return true;
}
diff --git a/Source/cmEnableTestingCommand.h b/Source/cmEnableTestingCommand.h
index fd50ebc..e4593f2 100644
--- a/Source/cmEnableTestingCommand.h
+++ b/Source/cmEnableTestingCommand.h
@@ -8,13 +8,9 @@
#include <string>
#include <vector>
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
class cmExecutionStatus;
-/** \class cmEnableTestingCommand
+/**
* \brief Enable testing for this directory and below.
*
* Produce the output testfile. This produces a file in the build directory
@@ -27,23 +23,7 @@ class cmExecutionStatus;
* Note that CTest expects to find this file in the build directory root;
* therefore, this command should be in the source directory root too.
*/
-class cmEnableTestingCommand : public cmCommand
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmEnableTestingCommand>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const&,
- cmExecutionStatus&) override;
-};
+bool cmEnableTestingCommand(std::vector<std::string> const&,
+ cmExecutionStatus&);
#endif
diff --git a/Source/cmReturnCommand.cxx b/Source/cmReturnCommand.cxx
index ceea8b4..5905669 100644
--- a/Source/cmReturnCommand.cxx
+++ b/Source/cmReturnCommand.cxx
@@ -5,8 +5,8 @@
#include "cmExecutionStatus.h"
// cmReturnCommand
-bool cmReturnCommand::InitialPass(std::vector<std::string> const&,
- cmExecutionStatus& status)
+bool cmReturnCommand(std::vector<std::string> const&,
+ cmExecutionStatus& status)
{
status.SetReturnInvoked();
return true;
diff --git a/Source/cmReturnCommand.h b/Source/cmReturnCommand.h
index e9264d2..2404a36 100644
--- a/Source/cmReturnCommand.h
+++ b/Source/cmReturnCommand.h
@@ -8,34 +8,10 @@
#include <string>
#include <vector>
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
class cmExecutionStatus;
-/** \class cmReturnCommand
- * \brief Return from a directory or function
- *
- * cmReturnCommand returns from a directory or function
- */
-class cmReturnCommand : public cmCommand
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmReturnCommand>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-};
+/// Return from a directory or function
+bool cmReturnCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 441f11c..0b12a65 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -432,6 +432,23 @@ void cmState::AddBuiltinCommand(std::string const& name, Command command)
this->BuiltinCommands.emplace(name, std::move(command));
}
+void cmState::AddBuiltinCommand(std::string const& name,
+ BuiltinCommand command)
+{
+ this->AddBuiltinCommand(
+ name,
+ [command](const std::vector<cmListFileArgument>& args,
+ cmExecutionStatus& status) -> bool {
+ std::vector<std::string> expandedArguments;
+ if (!status.GetMakefile().ExpandArguments(args, expandedArguments)) {
+ // There was an error expanding arguments. It was already
+ // reported, so we can skip this command without error.
+ return true;
+ }
+ return command(expandedArguments, status);
+ });
+}
+
void cmState::AddDisallowedCommand(std::string const& name,
std::unique_ptr<cmCommand> command,
cmPolicies::PolicyID policy,
diff --git a/Source/cmState.h b/Source/cmState.h
index 07c1c9b..8847f3b 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -145,6 +145,8 @@ public:
using Command = std::function<bool(std::vector<cmListFileArgument> const&,
cmExecutionStatus&)>;
+ using BuiltinCommand = bool (*)(std::vector<std::string> const&,
+ cmExecutionStatus&);
// Returns a command from its name, case insensitive, or nullptr
Command GetCommand(std::string const& name) const;
@@ -154,6 +156,7 @@ public:
void AddBuiltinCommand(std::string const& name,
std::unique_ptr<cmCommand> command);
void AddBuiltinCommand(std::string const& name, Command command);
+ void AddBuiltinCommand(std::string const& name, BuiltinCommand command);
void AddDisallowedCommand(std::string const& name,
std::unique_ptr<cmCommand> command,
cmPolicies::PolicyID policy, const char* message);