From f717e1fccf2968ffeba36dc84e428abd4f8db5c0 Mon Sep 17 00:00:00 2001
From: Regina Pfeifer <regina@mailbox.org>
Date: Thu, 12 Sep 2019 10:06:03 +0200
Subject: cmCreateTestSourceList: Port away from cmCommand

Ref: #19499
---
 Source/cmCommands.cxx             |  3 +--
 Source/cmCreateTestSourceList.cxx | 39 +++++++++++++++++----------------------
 Source/cmCreateTestSourceList.h   | 29 ++---------------------------
 3 files changed, 20 insertions(+), 51 deletions(-)

diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 1f6b1a2..f675a93 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -223,8 +223,7 @@ void GetProjectCommands(cmState* state)
   state->AddBuiltinCommand("add_subdirectory", cmAddSubDirectoryCommand);
   state->AddBuiltinCommand("add_test", cmAddTestCommand);
   state->AddBuiltinCommand("build_command", cmBuildCommand);
-  state->AddBuiltinCommand("create_test_sourcelist",
-                           cm::make_unique<cmCreateTestSourceList>());
+  state->AddBuiltinCommand("create_test_sourcelist", cmCreateTestSourceList);
   state->AddBuiltinCommand("define_property",
                            cm::make_unique<cmDefinePropertyCommand>());
   state->AddBuiltinCommand("enable_language",
diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx
index da23519..9d492ba 100644
--- a/Source/cmCreateTestSourceList.cxx
+++ b/Source/cmCreateTestSourceList.cxx
@@ -4,19 +4,17 @@
 
 #include <algorithm>
 
+#include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
-class cmExecutionStatus;
-
-// cmCreateTestSourceList
-bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
-                                         cmExecutionStatus&)
+bool cmCreateTestSourceList(std::vector<std::string> const& args,
+                            cmExecutionStatus& status)
 {
   if (args.size() < 3) {
-    this->SetError("called with wrong number of arguments.");
+    status.SetError("called with wrong number of arguments.");
     return false;
   }
 
@@ -29,14 +27,14 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
     if (*i == "EXTRA_INCLUDE") {
       ++i;
       if (i == args.end()) {
-        this->SetError("incorrect arguments to EXTRA_INCLUDE");
+        status.SetError("incorrect arguments to EXTRA_INCLUDE");
         return false;
       }
       extraInclude = cmStrCat("#include \"", *i, "\"\n");
     } else if (*i == "FUNCTION") {
       ++i;
       if (i == args.end()) {
-        this->SetError("incorrect arguments to FUNCTION");
+        status.SetError("incorrect arguments to FUNCTION");
         return false;
       }
       function = cmStrCat(*i, "(&ac, &av);\n");
@@ -54,12 +52,12 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
   // Name of the test driver
   // make sure they specified an extension
   if (cmSystemTools::GetFilenameExtension(*i).size() < 2) {
-    this->SetError(
+    status.SetError(
       "You must specify a file extension for the test driver file.");
     return false;
   }
-  std::string driver =
-    cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', *i);
+  cmMakefile& mf = status.GetMakefile();
+  std::string driver = cmStrCat(mf.GetCurrentBinaryDirectory(), '/', *i);
   ++i;
 
   std::string configFile = cmSystemTools::GetCMakeRoot();
@@ -121,35 +119,32 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
     numTests++;
   }
   if (!extraInclude.empty()) {
-    this->Makefile->AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES",
-                                  extraInclude);
+    mf.AddDefinition("CMAKE_TESTDRIVER_EXTRA_INCLUDES", extraInclude);
   }
   if (!function.empty()) {
-    this->Makefile->AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", function);
+    mf.AddDefinition("CMAKE_TESTDRIVER_ARGVC_FUNCTION", function);
   }
-  this->Makefile->AddDefinition("CMAKE_FORWARD_DECLARE_TESTS",
-                                forwardDeclareCode);
-  this->Makefile->AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES",
-                                functionMapCode);
+  mf.AddDefinition("CMAKE_FORWARD_DECLARE_TESTS", forwardDeclareCode);
+  mf.AddDefinition("CMAKE_FUNCTION_TABLE_ENTIRES", functionMapCode);
   bool res = true;
-  if (!this->Makefile->ConfigureFile(configFile, driver, false, true, false)) {
+  if (!mf.ConfigureFile(configFile, driver, false, true, false)) {
     res = false;
   }
 
   // Construct the source list.
   std::string sourceListValue;
   {
-    cmSourceFile* sf = this->Makefile->GetOrCreateSource(driver);
+    cmSourceFile* sf = mf.GetOrCreateSource(driver);
     sf->SetProperty("ABSTRACT", "0");
     sourceListValue = args[1];
   }
   for (i = testsBegin; i != tests.end(); ++i) {
-    cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
+    cmSourceFile* sf = mf.GetOrCreateSource(*i);
     sf->SetProperty("ABSTRACT", "0");
     sourceListValue += ";";
     sourceListValue += *i;
   }
 
-  this->Makefile->AddDefinition(sourceList, sourceListValue);
+  mf.AddDefinition(sourceList, sourceListValue);
   return res;
 }
diff --git a/Source/cmCreateTestSourceList.h b/Source/cmCreateTestSourceList.h
index 5aa6af4..19503f4 100644
--- a/Source/cmCreateTestSourceList.h
+++ b/Source/cmCreateTestSourceList.h
@@ -8,34 +8,9 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmCreateTestSourceList
- * \brief Test driver generation command
- *
- */
-
-class cmCreateTestSourceList : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmCreateTestSourceList>();
-  }
-
-  /**
-   * 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 cmCreateTestSourceList(std::vector<std::string> const& args,
+                            cmExecutionStatus& status);
 
 #endif
-- 
cgit v0.12