فهرست منبع

cmFind*: Port away from cmCommand

Regina Pfeifer 6 سال پیش
والد
کامیت
8a18bb7cdf

+ 5 - 8
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);

+ 4 - 1
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;

+ 5 - 1
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.

+ 8 - 2
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()
 {

+ 10 - 4
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

+ 10 - 1
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);
+}

+ 8 - 10
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

+ 9 - 3
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);
+}

+ 6 - 18
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

+ 9 - 3
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);
+}

+ 7 - 20
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

+ 9 - 3
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);
+}

+ 6 - 18
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

+ 9 - 3
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);
+}

+ 6 - 18
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