mirror of
https://github.com/reactos/CMake.git
synced 2025-01-20 02:12:35 +00:00
cmState: Support BuiltinCommands as free functions
This commit is contained in:
parent
28f2d12a05
commit
dfaa87f1b3
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user