Explorar o código

cmake: initialize with Role that controls which commands to register

Daniel Pfeifer %!s(int64=8) %!d(string=hai) anos
pai
achega
c36d63cd48

+ 1 - 1
Source/CPack/cmCPackGenerator.cxx

@@ -620,7 +620,7 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
                           << installComponent << std::endl);
                           << installComponent << std::endl);
         }
         }
 
 
-        cmake cm;
+        cmake cm(cmake::RoleScript);
         cm.SetHomeDirectory("");
         cm.SetHomeDirectory("");
         cm.SetHomeOutputDirectory("");
         cm.SetHomeOutputDirectory("");
         cm.GetCurrentSnapshot().SetDefaultDefinitions();
         cm.GetCurrentSnapshot().SetDefaultDefinitions();

+ 1 - 1
Source/CPack/cpack.cxx

@@ -189,7 +189,7 @@ int main(int argc, char const* const* argv)
   cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
   cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
               "Read CPack config file: " << cpackConfigFile << std::endl);
               "Read CPack config file: " << cpackConfigFile << std::endl);
 
 
-  cmake cminst;
+  cmake cminst(cmake::RoleScript);
   cminst.SetHomeDirectory("");
   cminst.SetHomeDirectory("");
   cminst.SetHomeOutputDirectory("");
   cminst.SetHomeOutputDirectory("");
   cminst.GetCurrentSnapshot().SetDefaultDefinitions();
   cminst.GetCurrentSnapshot().SetDefaultDefinitions();

+ 1 - 1
Source/CTest/cmCTestBuildAndTestHandler.cxx

@@ -167,7 +167,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
     return 1;
     return 1;
   }
   }
 
 
-  cmake cm;
+  cmake cm(cmake::RoleProject);
   cm.SetHomeDirectory("");
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.SetHomeOutputDirectory("");
   std::string cmakeOutString;
   std::string cmakeOutString;

+ 1 - 1
Source/CTest/cmCTestLaunch.cxx

@@ -623,7 +623,7 @@ int cmCTestLaunch::Main(int argc, const char* const argv[])
 
 
 void cmCTestLaunch::LoadConfig()
 void cmCTestLaunch::LoadConfig()
 {
 {
-  cmake cm;
+  cmake cm(cmake::RoleScript);
   cm.SetHomeDirectory("");
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cm.GetCurrentSnapshot().SetDefaultDefinitions();

+ 1 - 1
Source/CTest/cmCTestScriptHandler.cxx

@@ -275,7 +275,7 @@ void cmCTestScriptHandler::CreateCMake()
     delete this->GlobalGenerator;
     delete this->GlobalGenerator;
     delete this->Makefile;
     delete this->Makefile;
   }
   }
-  this->CMake = new cmake;
+  this->CMake = new cmake(cmake::RoleScript);
   this->CMake->SetHomeDirectory("");
   this->CMake->SetHomeDirectory("");
   this->CMake->SetHomeOutputDirectory("");
   this->CMake->SetHomeOutputDirectory("");
   this->CMake->GetCurrentSnapshot().SetDefaultDefinitions();
   this->CMake->GetCurrentSnapshot().SetDefaultDefinitions();

+ 1 - 1
Source/CTest/cmCTestTestHandler.cxx

@@ -1650,7 +1650,7 @@ void cmCTestTestHandler::GetListOfTests()
   }
   }
   cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
   cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
                      "Constructing a list of tests" << std::endl, this->Quiet);
                      "Constructing a list of tests" << std::endl, this->Quiet);
-  cmake cm;
+  cmake cm(cmake::RoleScript);
   cm.SetHomeDirectory("");
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cm.GetCurrentSnapshot().SetDefaultDefinitions();

+ 1 - 1
Source/CursesDialog/ccmake.cxx

@@ -81,7 +81,7 @@ int main(int argc, char const* const* argv)
   cmDocumentation doc;
   cmDocumentation doc;
   doc.addCMakeStandardDocSections();
   doc.addCMakeStandardDocSections();
   if (doc.CheckOptions(argc, argv)) {
   if (doc.CheckOptions(argc, argv)) {
-    cmake hcm;
+    cmake hcm(cmake::RoleInternal);
     hcm.SetHomeDirectory("");
     hcm.SetHomeDirectory("");
     hcm.SetHomeOutputDirectory("");
     hcm.SetHomeOutputDirectory("");
     hcm.AddCMakePaths();
     hcm.AddCMakePaths();

+ 1 - 1
Source/CursesDialog/cmCursesMainForm.cxx

@@ -40,7 +40,7 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
     "Welcome to ccmake, curses based user interface for CMake.");
     "Welcome to ccmake, curses based user interface for CMake.");
   this->HelpMessage.push_back("");
   this->HelpMessage.push_back("");
   this->HelpMessage.push_back(s_ConstHelpMessage);
   this->HelpMessage.push_back(s_ConstHelpMessage);
-  this->CMakeInstance = new cmake;
+  this->CMakeInstance = new cmake(cmake::RoleProject);
   this->CMakeInstance->SetCMakeEditCommand(
   this->CMakeInstance->SetCMakeEditCommand(
     cmSystemTools::GetCMakeCursesCommand());
     cmSystemTools::GetCMakeCursesCommand());
 
 

+ 1 - 1
Source/QtDialog/CMakeSetup.cxx

@@ -59,7 +59,7 @@ int main(int argc, char** argv)
   doc.addCMakeStandardDocSections();
   doc.addCMakeStandardDocSections();
   if (argc2 > 1 && doc.CheckOptions(argc2, argv2)) {
   if (argc2 > 1 && doc.CheckOptions(argc2, argv2)) {
     // Construct and print requested documentation.
     // Construct and print requested documentation.
-    cmake hcm;
+    cmake hcm(cmake::RoleInternal);
     hcm.SetHomeDirectory("");
     hcm.SetHomeDirectory("");
     hcm.SetHomeOutputDirectory("");
     hcm.SetHomeOutputDirectory("");
     hcm.AddCMakePaths();
     hcm.AddCMakePaths();

+ 1 - 1
Source/QtDialog/QCMake.cxx

@@ -27,7 +27,7 @@ QCMake::QCMake(QObject* p)
   cmSystemTools::SetStdoutCallback(QCMake::stdoutCallback, this);
   cmSystemTools::SetStdoutCallback(QCMake::stdoutCallback, this);
   cmSystemTools::SetStderrCallback(QCMake::stderrCallback, this);
   cmSystemTools::SetStderrCallback(QCMake::stderrCallback, this);
 
 
-  this->CMakeInstance = new cmake;
+  this->CMakeInstance = new cmake(cmake::RoleProject);
   this->CMakeInstance->SetCMakeEditCommand(
   this->CMakeInstance->SetCMakeEditCommand(
     cmSystemTools::GetCMakeGUICommand());
     cmSystemTools::GetCMakeGUICommand());
   this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
   this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);

+ 1 - 1
Source/cmCTest.cxx

@@ -416,7 +416,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
     }
     }
   }
   }
 
 
-  cmake cm;
+  cmake cm(cmake::RoleScript);
   cm.SetHomeDirectory("");
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cm.GetCurrentSnapshot().SetDefaultDefinitions();

+ 1 - 1
Source/cmGlobalNinjaGenerator.cxx

@@ -1903,7 +1903,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
     }
     }
   }
   }
 
 
-  cmake cm;
+  cmake cm(cmake::RoleInternal);
   cm.SetHomeDirectory(dir_top_src);
   cm.SetHomeDirectory(dir_top_src);
   cm.SetHomeOutputDirectory(dir_top_bld);
   cm.SetHomeOutputDirectory(dir_top_bld);
   CM_AUTO_PTR<cmGlobalNinjaGenerator> ggd(
   CM_AUTO_PTR<cmGlobalNinjaGenerator> ggd(

+ 1 - 1
Source/cmGraphVizWriter.cxx

@@ -61,7 +61,7 @@ cmGraphVizWriter::cmGraphVizWriter(
 void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
 void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
                                     const char* fallbackSettingsFileName)
                                     const char* fallbackSettingsFileName)
 {
 {
-  cmake cm;
+  cmake cm(cmake::RoleScript);
   cm.SetHomeDirectory("");
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cm.GetCurrentSnapshot().SetDefaultDefinitions();

+ 1 - 1
Source/cmMakefile.cxx

@@ -3187,7 +3187,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
   // make sure the same generator is used
   // make sure the same generator is used
   // use this program as the cmake to be run, it should not
   // use this program as the cmake to be run, it should not
   // be run that way but the cmake object requires a vailid path
   // be run that way but the cmake object requires a vailid path
-  cmake cm;
+  cmake cm(cmake::RoleProject);
   cm.SetIsInTryCompile(true);
   cm.SetIsInTryCompile(true);
   cmGlobalGenerator* gg =
   cmGlobalGenerator* gg =
     cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName());
     cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName());

+ 1 - 1
Source/cmQtAutoGenerators.cxx

@@ -286,7 +286,7 @@ cmQtAutoGenerators::cmQtAutoGenerators()
 bool cmQtAutoGenerators::Run(const std::string& targetDirectory,
 bool cmQtAutoGenerators::Run(const std::string& targetDirectory,
                              const std::string& config)
                              const std::string& config)
 {
 {
-  cmake cm;
+  cmake cm(cmake::RoleScript);
   cm.SetHomeOutputDirectory(targetDirectory);
   cm.SetHomeOutputDirectory(targetDirectory);
   cm.SetHomeDirectory(targetDirectory);
   cm.SetHomeDirectory(targetDirectory);
   cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cm.GetCurrentSnapshot().SetDefaultDefinitions();

+ 1 - 1
Source/cmServerProtocol.cxx

@@ -215,7 +215,7 @@ bool cmServerProtocol::Activate(cmServer* server,
 {
 {
   assert(server);
   assert(server);
   this->m_Server = server;
   this->m_Server = server;
-  this->m_CMakeInstance = std::make_unique<cmake>();
+  this->m_CMakeInstance = std::make_unique<cmake>(cmake::RoleProject);
   const bool result = this->DoActivate(request, errorMessage);
   const bool result = this->DoActivate(request, errorMessage);
   if (!result) {
   if (!result) {
     this->m_CMakeInstance = CM_NULLPTR;
     this->m_CMakeInstance = CM_NULLPTR;

+ 11 - 4
Source/cmake.cxx

@@ -136,7 +136,7 @@ void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/,
   cm->MarkCliAsUsed(variable);
   cm->MarkCliAsUsed(variable);
 }
 }
 
 
-cmake::cmake()
+cmake::cmake(Role role)
 {
 {
   this->Trace = false;
   this->Trace = false;
   this->TraceExpand = false;
   this->TraceExpand = false;
@@ -174,8 +174,12 @@ cmake::cmake()
 
 
   this->AddDefaultGenerators();
   this->AddDefaultGenerators();
   this->AddDefaultExtraGenerators();
   this->AddDefaultExtraGenerators();
-  this->AddScriptingCommands();
-  this->AddProjectCommands();
+  if (role == RoleScript || role == RoleProject) {
+    this->AddScriptingCommands();
+  }
+  if (role == RoleProject) {
+    this->AddProjectCommands();
+  }
 
 
   // Make sure we can capture the build tool output.
   // Make sure we can capture the build tool output.
   cmSystemTools::EnableVSConsoleOutput();
   cmSystemTools::EnableVSConsoleOutput();
@@ -1888,7 +1892,7 @@ int cmake::CheckBuildSystem()
 
 
   // Read the rerun check file and use it to decide whether to do the
   // Read the rerun check file and use it to decide whether to do the
   // global generate.
   // global generate.
-  cmake cm;
+  cmake cm(RoleScript); // Actually, all we need is the `set` command.
   cm.SetHomeDirectory("");
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.GetCurrentSnapshot().SetDefaultDefinitions();
   cm.GetCurrentSnapshot().SetDefaultDefinitions();
@@ -2419,6 +2423,9 @@ int cmake::Build(const std::string& dir, const std::string& target,
     std::string homeOutputOrig = this->GetHomeOutputDirectory();
     std::string homeOutputOrig = this->GetHomeOutputDirectory();
     this->SetDirectoriesFromFile(cachePath.c_str());
     this->SetDirectoriesFromFile(cachePath.c_str());
 
 
+    this->AddScriptingCommands();
+    this->AddProjectCommands();
+
     int ret = this->Configure();
     int ret = this->Configure();
     if (ret) {
     if (ret) {
       cmSystemTools::Message("CMake Configure step failed.  "
       cmSystemTools::Message("CMake Configure step failed.  "

+ 8 - 1
Source/cmake.h

@@ -58,6 +58,13 @@ class cmake
   CM_DISABLE_COPY(cmake)
   CM_DISABLE_COPY(cmake)
 
 
 public:
 public:
+  enum Role
+  {
+    RoleInternal, // no commands
+    RoleScript,   // script commands
+    RoleProject   // all commands
+  };
+
   enum MessageType
   enum MessageType
   {
   {
     AUTHOR_WARNING,
     AUTHOR_WARNING,
@@ -112,7 +119,7 @@ public:
   typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
   typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
 
 
   /// Default constructor
   /// Default constructor
-  cmake();
+  cmake(Role role);
   /// Destructor
   /// Destructor
   ~cmake();
   ~cmake();
 
 

+ 4 - 4
Source/cmakemain.cxx

@@ -201,7 +201,7 @@ int do_cmake(int ac, char const* const* av)
   doc.addCMakeStandardDocSections();
   doc.addCMakeStandardDocSections();
   if (doc.CheckOptions(ac, av)) {
   if (doc.CheckOptions(ac, av)) {
     // Construct and print requested documentation.
     // Construct and print requested documentation.
-    cmake hcm;
+    cmake hcm(cmake::RoleInternal);
     hcm.SetHomeDirectory("");
     hcm.SetHomeDirectory("");
     hcm.SetHomeOutputDirectory("");
     hcm.SetHomeOutputDirectory("");
     hcm.AddCMakePaths();
     hcm.AddCMakePaths();
@@ -283,13 +283,13 @@ int do_cmake(int ac, char const* const* av)
     }
     }
   }
   }
   if (sysinfo) {
   if (sysinfo) {
-    cmake cm;
+    cmake cm(cmake::RoleProject);
     cm.SetHomeDirectory("");
     cm.SetHomeDirectory("");
     cm.SetHomeOutputDirectory("");
     cm.SetHomeOutputDirectory("");
     int ret = cm.GetSystemInformation(args);
     int ret = cm.GetSystemInformation(args);
     return ret;
     return ret;
   }
   }
-  cmake cm;
+  cmake cm(cmake::RoleProject);
   cm.SetHomeDirectory("");
   cm.SetHomeDirectory("");
   cm.SetHomeOutputDirectory("");
   cm.SetHomeOutputDirectory("");
   cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void*)&cm);
   cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void*)&cm);
@@ -407,7 +407,7 @@ static int do_build(int ac, char const* const* av)
     return 1;
     return 1;
   }
   }
 
 
-  cmake cm;
+  cmake cm(cmake::RoleInternal);
   cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void*)&cm);
   cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void*)&cm);
   cm.SetProgressCallback(cmakemainProgressCallback, (void*)&cm);
   cm.SetProgressCallback(cmakemainProgressCallback, (void*)&cm);
   return cm.Build(dir, target, config, nativeOptions, clean);
   return cm.Build(dir, target, config, nativeOptions, clean);

+ 2 - 2
Source/cmcmd.cxx

@@ -583,7 +583,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
         std::cerr << "-E capabilities accepts no additional arguments\n";
         std::cerr << "-E capabilities accepts no additional arguments\n";
         return 1;
         return 1;
       }
       }
-      cmake cm;
+      cmake cm(cmake::RoleInternal);
 #if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
 #if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
       std::cout << cm.ReportCapabilities(true);
       std::cout << cm.ReportCapabilities(true);
 #else
 #else
@@ -760,7 +760,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       const bool verbose = isCMakeVerbose();
       const bool verbose = isCMakeVerbose();
 
 
       // Create a cmake object instance to process dependencies.
       // Create a cmake object instance to process dependencies.
-      cmake cm;
+      cmake cm(cmake::RoleScript); // All we need is the `set` command.
       std::string gen;
       std::string gen;
       std::string homeDir;
       std::string homeDir;
       std::string startDir;
       std::string startDir;