Pārlūkot izejas kodu

cmLinkDirectoriesCommand: Port away from cmCommand

Regina Pfeifer 6 gadi atpakaļ
vecāks
revīzija
fcfec154ac

+ 1 - 2
Source/cmCommands.cxx

@@ -237,8 +237,7 @@ void GetProjectCommands(cmState* state)
   state->AddBuiltinCommand("install", cm::make_unique<cmInstallCommand>());
   state->AddBuiltinCommand("install_files", cmInstallFilesCommand);
   state->AddBuiltinCommand("install_targets", cmInstallTargetsCommand);
-  state->AddBuiltinCommand("link_directories",
-                           cm::make_unique<cmLinkDirectoriesCommand>());
+  state->AddBuiltinCommand("link_directories", cmLinkDirectoriesCommand);
   state->AddBuiltinCommand("project", cm::make_unique<cmProjectCommand>());
   state->AddBuiltinCommand("set_source_files_properties",
                            cmSetSourceFilesPropertiesCommand);

+ 15 - 15
Source/cmLinkDirectoriesCommand.cxx

@@ -4,6 +4,7 @@
 
 #include <sstream>
 
+#include "cmExecutionStatus.h"
 #include "cmGeneratorExpression.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
@@ -11,17 +12,18 @@
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
-class cmExecutionStatus;
+static void AddLinkDir(cmMakefile& mf, std::string const& dir,
+                       std::vector<std::string>& directories);
 
-// cmLinkDirectoriesCommand
-bool cmLinkDirectoriesCommand::InitialPass(
-  std::vector<std::string> const& args, cmExecutionStatus&)
+bool cmLinkDirectoriesCommand(std::vector<std::string> const& args,
+                              cmExecutionStatus& status)
 {
   if (args.empty()) {
     return true;
   }
 
-  bool before = this->Makefile->IsOn("CMAKE_LINK_DIRECTORIES_BEFORE");
+  cmMakefile& mf = status.GetMakefile();
+  bool before = mf.IsOn("CMAKE_LINK_DIRECTORIES_BEFORE");
 
   auto i = args.cbegin();
   if ((*i) == "BEFORE") {
@@ -34,16 +36,16 @@ bool cmLinkDirectoriesCommand::InitialPass(
 
   std::vector<std::string> directories;
   for (; i != args.cend(); ++i) {
-    this->AddLinkDir(*i, directories);
+    AddLinkDir(mf, *i, directories);
   }
 
-  this->Makefile->AddLinkDirectory(cmJoin(directories, ";"), before);
+  mf.AddLinkDirectory(cmJoin(directories, ";"), before);
 
   return true;
 }
 
-void cmLinkDirectoriesCommand::AddLinkDir(
-  std::string const& dir, std::vector<std::string>& directories)
+static void AddLinkDir(cmMakefile& mf, std::string const& dir,
+                       std::vector<std::string>& directories)
 {
   std::string unixPath = dir;
   cmSystemTools::ConvertToUnixSlashes(unixPath);
@@ -56,10 +58,10 @@ void cmLinkDirectoriesCommand::AddLinkDir(
       << "  " << unixPath << "\n"
       << "as a link directory.\n";
     /* clang-format on */
-    switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015)) {
+    switch (mf.GetPolicyStatus(cmPolicies::CMP0015)) {
       case cmPolicies::WARN:
         e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015);
-        this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
+        mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
         break;
       case cmPolicies::OLD:
         // OLD behavior does not convert
@@ -67,7 +69,7 @@ void cmLinkDirectoriesCommand::AddLinkDir(
       case cmPolicies::REQUIRED_IF_USED:
       case cmPolicies::REQUIRED_ALWAYS:
         e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0015);
-        this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+        mf.IssueMessage(MessageType::FATAL_ERROR, e.str());
         CM_FALLTHROUGH;
       case cmPolicies::NEW:
         // NEW behavior converts
@@ -75,9 +77,7 @@ void cmLinkDirectoriesCommand::AddLinkDir(
         break;
     }
     if (convertToAbsolute) {
-      std::string tmp =
-        cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', unixPath);
-      unixPath = tmp;
+      unixPath = cmStrCat(mf.GetCurrentSourceDirectory(), '/', unixPath);
     }
   }
   directories.push_back(unixPath);

+ 2 - 34
Source/cmLinkDirectoriesCommand.h

@@ -8,41 +8,9 @@
 #include <string>
 #include <vector>
 
-#include <cm/memory>
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmLinkDirectoriesCommand
- * \brief Define a list of directories containing files to link.
- *
- * cmLinkDirectoriesCommand is used to specify a list
- * of directories containing files to link into executable(s).
- * Note that the command supports the use of CMake built-in variables
- * such as CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR.
- */
-class cmLinkDirectoriesCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmLinkDirectoriesCommand>();
-  }
-
-  /**
-   * 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;
-
-private:
-  void AddLinkDir(std::string const& dir,
-                  std::vector<std::string>& directories);
-};
+bool cmLinkDirectoriesCommand(std::vector<std::string> const& args,
+                              cmExecutionStatus& status);
 
 #endif