summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorRegina Pfeifer <regina@mailbox.org>2019-09-18 17:35:37 +0200
committerRegina Pfeifer <regina@mailbox.org>2019-09-21 05:12:54 +0200
commit9c521088df3c45764fd9bfc1c10c9bfe63b63e78 (patch)
tree9f8019bf2cebfdcd121a4494a2b73fdc501351d0 /Source
parentfcfec154acea01518aa436d76f576d7cfea65fa2 (diff)
downloadcmake-9c521088df3c45764fd9bfc1c10c9bfe63b63e78.tar.gz
cmLoadCacheCommand: Port away from cmCommand
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCommands.cxx3
-rw-r--r--Source/cmLoadCacheCommand.cxx52
-rw-r--r--Source/cmLoadCacheCommand.h37
3 files changed, 35 insertions, 57 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index aba092ef19..a975856c8e 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -284,8 +284,7 @@ void GetProjectCommands(cmState* state)
cm::make_unique<cmTargetLinkOptionsCommand>());
state->AddBuiltinCommand("target_link_directories",
cm::make_unique<cmTargetLinkDirectoriesCommand>());
- state->AddBuiltinCommand("load_cache",
- cm::make_unique<cmLoadCacheCommand>());
+ state->AddBuiltinCommand("load_cache", cmLoadCacheCommand);
state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand);
state->AddBuiltinCommand("qt_wrap_ui", cmQTWrapUICommand);
state->AddBuiltinCommand("remove_definitions", cmRemoveDefinitionsCommand);
diff --git a/Source/cmLoadCacheCommand.cxx b/Source/cmLoadCacheCommand.cxx
index 3fd734393d..cca16336d1 100644
--- a/Source/cmLoadCacheCommand.cxx
+++ b/Source/cmLoadCacheCommand.cxx
@@ -3,24 +3,30 @@
#include "cmLoadCacheCommand.h"
#include "cmsys/FStream.hxx"
+#include <set>
+#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmake.h"
-class cmExecutionStatus;
+static bool ReadWithPrefix(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
-// cmLoadCacheCommand
-bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus&)
+static void CheckLine(cmMakefile& mf, std::string const& prefix,
+ std::set<std::string> const& variablesToRead,
+ const char* line);
+
+bool cmLoadCacheCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
{
if (args.empty()) {
- this->SetError("called with wrong number of arguments.");
+ status.SetError("called with wrong number of arguments.");
}
if (args.size() >= 2 && args[1] == "READ_WITH_PREFIX") {
- return this->ReadWithPrefix(args);
+ return ReadWithPrefix(args, status);
}
// Cache entries to be excluded from the import list.
@@ -59,24 +65,26 @@ bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& args,
}
}
+ cmMakefile& mf = status.GetMakefile();
+
// Loop over each build directory listed in the arguments. Each
// directory has a cache file.
for (std::string const& arg : args) {
if ((arg == "EXCLUDE") || (arg == "INCLUDE_INTERNALS")) {
break;
}
- this->Makefile->GetCMakeInstance()->LoadCache(arg, false, excludes,
- includes);
+ mf.GetCMakeInstance()->LoadCache(arg, false, excludes, includes);
}
return true;
}
-bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
+static bool ReadWithPrefix(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
{
// Make sure we have a prefix.
if (args.size() < 3) {
- this->SetError("READ_WITH_PREFIX form must specify a prefix.");
+ status.SetError("READ_WITH_PREFIX form must specify a prefix.");
return false;
}
@@ -84,17 +92,19 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
std::string cacheFile = args[0] + "/CMakeCache.txt";
if (!cmSystemTools::FileExists(cacheFile)) {
std::string e = "Cannot load cache file from " + cacheFile;
- this->SetError(e);
+ status.SetError(e);
return false;
}
// Prepare the table of variables to read.
- this->Prefix = args[2];
- this->VariablesToRead.insert(args.begin() + 3, args.end());
+ std::string const prefix = args[2];
+ std::set<std::string> const variablesToRead(args.begin() + 3, args.end());
// Read the cache file.
cmsys::ifstream fin(cacheFile.c_str());
+ cmMakefile& mf = status.GetMakefile();
+
// This is a big hack read loop to overcome a buggy ifstream
// implementation on HP-UX. This should work on all platforms even
// for small buffer sizes.
@@ -123,7 +133,7 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
}
if (i != end) {
// Completed a line.
- this->CheckLine(line.c_str());
+ CheckLine(mf, prefix, variablesToRead, line.c_str());
line.clear();
// Skip the newline character.
@@ -134,13 +144,15 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
}
if (!line.empty()) {
// Partial last line.
- this->CheckLine(line.c_str());
+ CheckLine(mf, prefix, variablesToRead, line.c_str());
}
return true;
}
-void cmLoadCacheCommand::CheckLine(const char* line)
+static void CheckLine(cmMakefile& mf, std::string const& prefix,
+ std::set<std::string> const& variablesToRead,
+ const char* line)
{
// Check one line of the cache file.
std::string var;
@@ -148,14 +160,14 @@ void cmLoadCacheCommand::CheckLine(const char* line)
cmStateEnums::CacheEntryType type = cmStateEnums::UNINITIALIZED;
if (cmake::ParseCacheEntry(line, var, value, type)) {
// Found a real entry. See if this one was requested.
- if (this->VariablesToRead.find(var) != this->VariablesToRead.end()) {
+ if (variablesToRead.find(var) != variablesToRead.end()) {
// This was requested. Set this variable locally with the given
// prefix.
- var = this->Prefix + var;
+ var = prefix + var;
if (!value.empty()) {
- this->Makefile->AddDefinition(var, value);
+ mf.AddDefinition(var, value);
} else {
- this->Makefile->RemoveDefinition(var);
+ mf.RemoveDefinition(var);
}
}
}
diff --git a/Source/cmLoadCacheCommand.h b/Source/cmLoadCacheCommand.h
index 37f037273b..7cee6637c3 100644
--- a/Source/cmLoadCacheCommand.h
+++ b/Source/cmLoadCacheCommand.h
@@ -5,45 +5,12 @@
#include "cmConfigure.h" // IWYU pragma: keep
-#include <set>
#include <string>
#include <vector>
-#include <cm/memory>
-
-#include "cmCommand.h"
-
class cmExecutionStatus;
-/** \class cmLoadCacheCommand
- * \brief load a cache file
- *
- * cmLoadCacheCommand loads the non internal values of a cache file
- */
-class cmLoadCacheCommand : public cmCommand
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmLoadCacheCommand>();
- }
-
- /**
- * 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;
-
-protected:
- std::set<std::string> VariablesToRead;
- std::string Prefix;
-
- bool ReadWithPrefix(std::vector<std::string> const& args);
- void CheckLine(const char* line);
-};
+bool cmLoadCacheCommand(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif