summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRegina Pfeifer <regina@mailbox.org>2019-09-10 21:44:48 +0200
committerRegina Pfeifer <regina@mailbox.org>2019-09-10 22:13:11 +0200
commit8a18bb7cdf2478d68e11a5e532b5134ea92b3678 (patch)
treee0210e119c21d5326041969831ed2e97b1ed413c
parent95d4a2d05562c5f0a4113527d31dadef4d7756bd (diff)
downloadcmake-8a18bb7cdf2478d68e11a5e532b5134ea92b3678.tar.gz
cmFind*: Port away from cmCommand
-rw-r--r--Source/cmCommands.cxx13
-rw-r--r--Source/cmFindBase.cxx5
-rw-r--r--Source/cmFindBase.h6
-rw-r--r--Source/cmFindCommon.cxx10
-rw-r--r--Source/cmFindCommon.h14
-rw-r--r--Source/cmFindFileCommand.cxx11
-rw-r--r--Source/cmFindFileCommand.h18
-rw-r--r--Source/cmFindLibraryCommand.cxx12
-rw-r--r--Source/cmFindLibraryCommand.h24
-rw-r--r--Source/cmFindPackageCommand.cxx12
-rw-r--r--Source/cmFindPackageCommand.h27
-rw-r--r--Source/cmFindPathCommand.cxx12
-rw-r--r--Source/cmFindPathCommand.h24
-rw-r--r--Source/cmFindProgramCommand.cxx12
-rw-r--r--Source/cmFindProgramCommand.h24
15 files changed, 111 insertions, 113 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 702b743204..dfe130e992 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -125,14 +125,11 @@ void GetScriptingCommands(cmState* state)
state->AddBuiltinCommand("exec_program", cmExecProgramCommand);
state->AddBuiltinCommand("execute_process", cmExecuteProcessCommand);
state->AddBuiltinCommand("file", cmFileCommand);
- state->AddBuiltinCommand("find_file", cm::make_unique<cmFindFileCommand>());
- state->AddBuiltinCommand("find_library",
- cm::make_unique<cmFindLibraryCommand>());
- state->AddBuiltinCommand("find_package",
- cm::make_unique<cmFindPackageCommand>());
- state->AddBuiltinCommand("find_path", cm::make_unique<cmFindPathCommand>());
- state->AddBuiltinCommand("find_program",
- cm::make_unique<cmFindProgramCommand>());
+ state->AddBuiltinCommand("find_file", cmFindFile);
+ state->AddBuiltinCommand("find_library", cmFindLibrary);
+ state->AddBuiltinCommand("find_package", cmFindPackage);
+ state->AddBuiltinCommand("find_path", cmFindPath);
+ state->AddBuiltinCommand("find_program", cmFindProgram);
state->AddBuiltinCommand("foreach", cmForEachCommand);
state->AddBuiltinCommand("function", cmFunctionCommand);
state->AddBuiltinCommand("get_cmake_property", cmGetCMakePropertyCommand);
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index cdc5f63216..e0daa4f0b7 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -16,7 +16,10 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
-cmFindBase::cmFindBase()
+class cmExecutionStatus;
+
+cmFindBase::cmFindBase(cmExecutionStatus& status)
+ : cmFindCommon(status)
{
this->AlreadyInCache = false;
this->AlreadyInCacheWithoutMetaInfo = false;
diff --git a/Source/cmFindBase.h b/Source/cmFindBase.h
index 88b5b6c18a..f75db5ff3f 100644
--- a/Source/cmFindBase.h
+++ b/Source/cmFindBase.h
@@ -10,6 +10,8 @@
#include "cmFindCommon.h"
+class cmExecutionStatus;
+
/** \class cmFindBase
* \brief Base class for most FIND_XXX commands.
*
@@ -19,7 +21,9 @@
class cmFindBase : public cmFindCommon
{
public:
- cmFindBase();
+ cmFindBase(cmExecutionStatus& status);
+ virtual ~cmFindBase() = default;
+
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx
index 9425f99a4d..560683830e 100644
--- a/Source/cmFindCommon.cxx
+++ b/Source/cmFindCommon.cxx
@@ -8,6 +8,7 @@
#include <utility>
#include "cmAlgorithms.h"
+#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -24,7 +25,9 @@ cmFindCommon::PathLabel cmFindCommon::PathLabel::SystemEnvironment(
cmFindCommon::PathLabel cmFindCommon::PathLabel::CMakeSystem("CMAKE_SYSTEM");
cmFindCommon::PathLabel cmFindCommon::PathLabel::Guess("GUESS");
-cmFindCommon::cmFindCommon()
+cmFindCommon::cmFindCommon(cmExecutionStatus& status)
+ : Makefile(&status.GetMakefile())
+ , Status(status)
{
this->FindRootPathMode = RootPathModeBoth;
this->NoDefaultPath = false;
@@ -51,7 +54,10 @@ cmFindCommon::cmFindCommon()
this->InitializeSearchPathGroups();
}
-cmFindCommon::~cmFindCommon() = default;
+void cmFindCommon::SetError(std::string const& e)
+{
+ this->Status.SetError(e);
+}
void cmFindCommon::InitializeSearchPathGroups()
{
diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h
index d95eeb1eb4..8177eacd6e 100644
--- a/Source/cmFindCommon.h
+++ b/Source/cmFindCommon.h
@@ -10,10 +10,12 @@
#include <string>
#include <vector>
-#include "cmCommand.h"
#include "cmPathLabel.h"
#include "cmSearchPath.h"
+class cmExecutionStatus;
+class cmMakefile;
+
/** \class cmFindCommon
* \brief Base class for FIND_XXX implementations.
*
@@ -21,11 +23,12 @@
* cmFindProgramCommand, cmFindPathCommand, cmFindLibraryCommand,
* cmFindFileCommand, and cmFindPackageCommand.
*/
-class cmFindCommon : public cmCommand
+class cmFindCommon
{
public:
- cmFindCommon();
- ~cmFindCommon() override;
+ cmFindCommon(cmExecutionStatus& status);
+
+ void SetError(std::string const& e);
protected:
friend class cmSearchPath;
@@ -127,6 +130,9 @@ protected:
bool SearchAppBundleFirst;
bool SearchAppBundleOnly;
bool SearchAppBundleLast;
+
+ cmMakefile* Makefile;
+ cmExecutionStatus& Status;
};
#endif
diff --git a/Source/cmFindFileCommand.cxx b/Source/cmFindFileCommand.cxx
index 9840c4f499..29a2bc49e9 100644
--- a/Source/cmFindFileCommand.cxx
+++ b/Source/cmFindFileCommand.cxx
@@ -2,7 +2,16 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmFindFileCommand.h"
-cmFindFileCommand::cmFindFileCommand()
+class cmExecutionStatus;
+
+cmFindFileCommand::cmFindFileCommand(cmExecutionStatus& status)
+ : cmFindPathCommand(status)
{
this->IncludeFileInPath = true;
}
+
+bool cmFindFile(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return cmFindFileCommand(status).InitialPass(args);
+}
diff --git a/Source/cmFindFileCommand.h b/Source/cmFindFileCommand.h
index 152b50564d..7dc6e55699 100644
--- a/Source/cmFindFileCommand.h
+++ b/Source/cmFindFileCommand.h
@@ -5,11 +5,13 @@
#include "cmConfigure.h" // IWYU pragma: keep
-#include "cm_memory.hxx"
+#include <string>
+#include <vector>
-#include "cmCommand.h"
#include "cmFindPathCommand.h"
+class cmExecutionStatus;
+
/** \class cmFindFileCommand
* \brief Define a command to search for an executable program.
*
@@ -21,14 +23,10 @@
class cmFindFileCommand : public cmFindPathCommand
{
public:
- cmFindFileCommand();
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmFindFileCommand>();
- }
+ cmFindFileCommand(cmExecutionStatus& status);
};
+bool cmFindFile(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
+
#endif
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
index 92c64c853a..529e5c8761 100644
--- a/Source/cmFindLibraryCommand.cxx
+++ b/Source/cmFindLibraryCommand.cxx
@@ -18,15 +18,15 @@
class cmExecutionStatus;
-cmFindLibraryCommand::cmFindLibraryCommand()
+cmFindLibraryCommand::cmFindLibraryCommand(cmExecutionStatus& status)
+ : cmFindBase(status)
{
this->EnvironmentPath = "LIB";
this->NamesPerDirAllowed = true;
}
// cmFindLibraryCommand
-bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn,
- cmExecutionStatus&)
+bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
{
this->VariableDocumentation = "Path to a library.";
this->CMakePathName = "LIBRARY";
@@ -490,3 +490,9 @@ std::string cmFindLibraryCommand::FindFrameworkLibraryDirsPerName()
// No framework found.
return "";
}
+
+bool cmFindLibrary(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return cmFindLibraryCommand(status).InitialPass(args);
+}
diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h
index af17d60bfd..b2f71b3b80 100644
--- a/Source/cmFindLibraryCommand.h
+++ b/Source/cmFindLibraryCommand.h
@@ -8,9 +8,6 @@
#include <string>
#include <vector>
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
#include "cmFindBase.h"
class cmExecutionStatus;
@@ -25,21 +22,9 @@ class cmExecutionStatus;
class cmFindLibraryCommand : public cmFindBase
{
public:
- cmFindLibraryCommand();
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmFindLibraryCommand>();
- }
-
- /**
- * 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;
+ cmFindLibraryCommand(cmExecutionStatus& status);
+
+ bool InitialPass(std::vector<std::string> const& args);
protected:
void AddArchitecturePaths(const char* suffix);
@@ -57,4 +42,7 @@ private:
std::string FindFrameworkLibraryDirsPerName();
};
+bool cmFindLibrary(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
+
#endif
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 913276061d..d99b20bd4b 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -85,7 +85,8 @@ void cmFindPackageCommand::Sort(std::vector<std::string>::iterator begin,
// else do not sort
}
-cmFindPackageCommand::cmFindPackageCommand()
+cmFindPackageCommand::cmFindPackageCommand(cmExecutionStatus& status)
+ : cmFindCommon(status)
{
this->CMakePathName = "PACKAGE";
this->Quiet = false;
@@ -143,8 +144,7 @@ void cmFindPackageCommand::AppendSearchPathGroups()
std::make_pair(PathLabel::SystemRegistry, cmSearchPath(this)));
}
-bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus&)
+bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
{
if (args.empty()) {
this->SetError("called with incorrect number of arguments");
@@ -2282,3 +2282,9 @@ bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in)
}
// TODO: Debug cmsys::Glob double slash problem.
+
+bool cmFindPackage(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return cmFindPackageCommand(status).InitialPass(args);
+}
diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h
index d57b38a339..78b49851c8 100644
--- a/Source/cmFindPackageCommand.h
+++ b/Source/cmFindPackageCommand.h
@@ -3,9 +3,7 @@
#ifndef cmFindPackageCommand_h
#define cmFindPackageCommand_h
-#include "cmCommand.h"
#include "cmConfigure.h" // IWYU pragma: keep
-#include "cmPolicies.h"
#include "cm_kwiml.h"
#include <cstddef>
@@ -15,7 +13,8 @@
#include <string>
#include <vector>
-#include "cm_memory.hxx"
+#include "cmFindCommon.h"
+#include "cmPolicies.h"
// IWYU insists we should forward-declare instead of including <functional>,
// but we cannot forward-declare reliably because some C++ standard libraries
@@ -28,8 +27,6 @@ namespace std {
/* clang-format on */
#endif
-#include "cmFindCommon.h"
-
class cmExecutionStatus;
class cmSearchPath;
@@ -62,22 +59,9 @@ public:
std::vector<std::string>::iterator end, SortOrderType order,
SortDirectionType dir);
- cmFindPackageCommand();
+ cmFindPackageCommand(cmExecutionStatus& status);
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmFindPackageCommand>();
- }
-
- /**
- * 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;
+ bool InitialPass(std::vector<std::string> const& args);
private:
class PathLabel : public cmFindCommon::PathLabel
@@ -246,4 +230,7 @@ struct hash<cmFindPackageCommand::ConfigFileInfo>
};
}
+bool cmFindPackage(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
+
#endif
diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx
index 41f5e5158d..f5e2631081 100644
--- a/Source/cmFindPathCommand.cxx
+++ b/Source/cmFindPathCommand.cxx
@@ -11,15 +11,15 @@
class cmExecutionStatus;
-cmFindPathCommand::cmFindPathCommand()
+cmFindPathCommand::cmFindPathCommand(cmExecutionStatus& status)
+ : cmFindBase(status)
{
this->EnvironmentPath = "INCLUDE";
this->IncludeFileInPath = false;
}
// cmFindPathCommand
-bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn,
- cmExecutionStatus&)
+bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
{
this->VariableDocumentation = "Path to a file.";
this->CMakePathName = "INCLUDE";
@@ -145,3 +145,9 @@ std::string cmFindPathCommand::FindFrameworkHeader()
}
return "";
}
+
+bool cmFindPath(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return cmFindPathCommand(status).InitialPass(args);
+}
diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h
index 89e2cef44c..8d1ea8b60e 100644
--- a/Source/cmFindPathCommand.h
+++ b/Source/cmFindPathCommand.h
@@ -8,9 +8,6 @@
#include <string>
#include <vector>
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
#include "cmFindBase.h"
class cmExecutionStatus;
@@ -25,21 +22,9 @@ class cmExecutionStatus;
class cmFindPathCommand : public cmFindBase
{
public:
- cmFindPathCommand();
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmFindPathCommand>();
- }
-
- /**
- * 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;
+ cmFindPathCommand(cmExecutionStatus& status);
+
+ bool InitialPass(std::vector<std::string> const& args);
bool IncludeFileInPath;
@@ -51,4 +36,7 @@ private:
std::string FindFrameworkHeader();
};
+bool cmFindPath(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
+
#endif
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx
index a2db65c2dc..e0a3fbfcf5 100644
--- a/Source/cmFindProgramCommand.cxx
+++ b/Source/cmFindProgramCommand.cxx
@@ -88,14 +88,14 @@ struct cmFindProgramHelper
}
};
-cmFindProgramCommand::cmFindProgramCommand()
+cmFindProgramCommand::cmFindProgramCommand(cmExecutionStatus& status)
+ : cmFindBase(status)
{
this->NamesPerDirAllowed = true;
}
// cmFindProgramCommand
-bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn,
- cmExecutionStatus&)
+bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
{
this->VariableDocumentation = "Path to a program.";
this->CMakePathName = "PROGRAM";
@@ -270,3 +270,9 @@ std::string cmFindProgramCommand::GetBundleExecutable(
return executable;
}
+
+bool cmFindProgram(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
+{
+ return cmFindProgramCommand(status).InitialPass(args);
+}
diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h
index 40e455ea39..043b43c5ea 100644
--- a/Source/cmFindProgramCommand.h
+++ b/Source/cmFindProgramCommand.h
@@ -8,9 +8,6 @@
#include <string>
#include <vector>
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
#include "cmFindBase.h"
class cmExecutionStatus;
@@ -26,21 +23,9 @@ class cmExecutionStatus;
class cmFindProgramCommand : public cmFindBase
{
public:
- cmFindProgramCommand();
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmFindProgramCommand>();
- }
-
- /**
- * 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;
+ cmFindProgramCommand(cmExecutionStatus& status);
+
+ bool InitialPass(std::vector<std::string> const& args);
private:
std::string FindProgram();
@@ -51,4 +36,7 @@ private:
std::string GetBundleExecutable(std::string const& bundlePath);
};
+bool cmFindProgram(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
+
#endif