From 2a68d21e8550b64641769b11691d74ae9bb37217 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Tue, 17 Sep 2002 13:59:58 -0400 Subject: cleaned up some of the cmake interface --- Source/MFCDialog/CMakeSetupDialog.cpp | 4 ++- Source/cmMakefile.cxx | 5 ++-- Source/cmake.cxx | 50 ++++++++++++++++++++--------------- Source/cmake.h | 33 ++++++++++++++--------- Source/cmakewizard.cxx | 5 +++- 5 files changed, 60 insertions(+), 37 deletions(-) diff --git a/Source/MFCDialog/CMakeSetupDialog.cpp b/Source/MFCDialog/CMakeSetupDialog.cpp index 4dec7f3..dd1bcc8 100644 --- a/Source/MFCDialog/CMakeSetupDialog.cpp +++ b/Source/MFCDialog/CMakeSetupDialog.cpp @@ -580,7 +580,9 @@ void CMakeSetupDialog::RunCMake(bool generateProjectFiles) m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild); m_CMakeInstance->SetGlobalGenerator( m_CMakeInstance->CreateGlobalGenerator(m_GeneratorChoiceString)); - if(m_CMakeInstance->Configure(m_PathToExecutable) != 0) + m_CMakeInstance->SetCMakeCommand(m_PathToExecutable); + m_CMakeInstance->LoadCache(); + if(m_CMakeInstance->Configure() != 0) { cmSystemTools::Error( "Error in configuration process, project files may be invalid"); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index fb4e06a..f1d706e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1352,7 +1352,6 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir, // be run that way but the cmake object requires a vailid path std::string cmakeCommand = this->GetDefinition("CMAKE_COMMAND"); cmake cm; - cm.AddCMakePaths(cmakeCommand.c_str()); cm.SetIsInTryCompile(true); cmGlobalGenerator *gg = cm.CreateGlobalGenerator(m_LocalGenerator->GetGlobalGenerator()->GetName()); @@ -1371,12 +1370,14 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir, cm.SetHomeOutputDirectory(bindir); cm.SetStartDirectory(srcdir); cm.SetStartOutputDirectory(bindir); + cm.SetCMakeCommand(cmakeCommand.c_str()); + cm.LoadCache(); // to save time we pass the EnableLanguage info directly gg->EnableLanguagesFromGenerator(m_LocalGenerator->GetGlobalGenerator(), this); - if (cm.Configure(cmakeCommand.c_str()) != 0) + if (cm.Configure() != 0) { cmSystemTools::Error( "Internal CMake error, TryCompile configure of cmake failed"); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 2c86c4d..9042b4a 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -625,15 +625,8 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg) gg->SetCMakeInstance(this); } -int cmake::Configure(const char *arg0, const std::vector* args) +int cmake::Configure() { - // Read in the cache, but not for a try compile - // because there will be no cache - if (!m_InTryCompile) - { - m_CacheManager->LoadCache(this->GetHomeOutputDirectory()); - } - // do a sanity check on some values if(m_CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY")) { @@ -661,18 +654,6 @@ int cmake::Configure(const char *arg0, const std::vector* args) cmCacheManager::INTERNAL); } - // extract command line arguments that might add cache entries - if (args) - { - this->SetCacheArgs(*args); - } - - // setup CMAKE_ROOT and CMAKE_COMMAND - if(!this->AddCMakePaths(arg0)) - { - return -3; - } - // no generator specified on the command line if(!m_GlobalGenerator) { @@ -785,6 +766,15 @@ int cmake::Run(const std::vector& args) // Process the arguments this->SetArgs(args); + // set the cmake command + m_CMakeCommand = args[0]; + + // load the cache + this->LoadCache(); + + // Add any cache args + this->SetCacheArgs(args); + // if we are local do the local thing, otherwise do global if (m_Local) { @@ -792,7 +782,7 @@ int cmake::Run(const std::vector& args) } // otherwise global - int ret = this->Configure(args[0].c_str(),&args); + int ret = this->Configure(); if (ret) { return ret; @@ -892,3 +882,21 @@ void cmake::AddDefaultCommands() } } +int cmake::LoadCache() +{ + m_CacheManager->LoadCache(this->GetHomeOutputDirectory()); + + if (m_CMakeCommand.size() < 2) + { + cmSystemTools::Error("cmake command was not specified prior to loading the cache in cmake.cxx"); + return -1; + } + + // setup CMAKE_ROOT and CMAKE_COMMAND + if(!this->AddCMakePaths(m_CMakeCommand.c_str())) + { + return -3; + } + return 0; +} + diff --git a/Source/cmake.h b/Source/cmake.h index 3cf1a51..d2ac956 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -119,7 +119,15 @@ class cmake * GlobalGenerator. This in turn will read in an process all the CMakeList * files for the tree. It will not produce any actual Makefiles, or * workspaces. Generate does that. */ - int Configure(const char *cmakeexec, const std::vector *args = 0); + int Configure(); + + /** + * Configure the cmMakefiles. This routine will create a GlobalGenerator if + * one has not already been set. It will then Call Configure on the + * GlobalGenerator. This in turn will read in an process all the CMakeList + * files for the tree. It will not produce any actual Makefiles, or + * workspaces. Generate does that. */ + int LoadCache(); ///! Create a GlobalGenerator cmGlobalGenerator* CreateGlobalGenerator(const char* name); @@ -136,6 +144,9 @@ class cmake ///! get the cmCachemManager used by this invocation of cmake cmCacheManager *GetCacheManager() { return m_CacheManager; } + ///! set the cmake command this instance of cmake should use + void SetCMakeCommand(const char* cmd) { m_CMakeCommand = cmd; } + /** * Given a variable name, return its value (as a string). */ @@ -164,10 +175,7 @@ class cmake * Is cmake in the process of a local cmake invocation. If so, we know the * cache is already configured and ready to go. */ - bool GetLocal() - { - return m_Local; - } + bool GetLocal() { return m_Local; } ///! Display command line useage void Usage(const char *program); @@ -181,10 +189,8 @@ class cmake ///! Is this cmake running as a result of a TRY_COMPILE command void SetIsInTryCompile(bool i) { m_InTryCompile = i; } - /** - * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries - */ - int AddCMakePaths(const char *arg0); + ///! Parse command line arguments that might set cache values + void SetCacheArgs(const std::vector&); protected: typedef std::map RegisteredCommandsMap; @@ -198,18 +204,21 @@ protected: std::string m_cmStartDirectory; std::string m_StartOutputDirectory; - ///! Parse command line arguments that might set cache values - void SetCacheArgs(const std::vector&); - ///! read in a cmake list file to initialize the cache void ReadListFile(const char *path); ///! used by Run int LocalGenerate(); + /** + * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries + */ + int AddCMakePaths(const char *arg0); + private: bool m_Verbose; bool m_Local; bool m_InTryCompile; + std::string m_CMakeCommand; }; diff --git a/Source/cmakewizard.cxx b/Source/cmakewizard.cxx index 608b46c..db86ef1 100644 --- a/Source/cmakewizard.cxx +++ b/Source/cmakewizard.cxx @@ -89,6 +89,9 @@ void cmakewizard::RunWizard(std::vector const& args) cmSystemTools::DisableRunCommandOutput(); cmake make; make.SetArgs(args); + make.SetCMakeCommand(args[0].c_str()); + make.LoadCache(); + make.SetCacheArgs(args); std::map askedCache; bool asked = false; // continue asking questions until no new questions are asked @@ -98,7 +101,7 @@ void cmakewizard::RunWizard(std::vector const& args) // run cmake this->ShowMessage("Please wait while cmake processes CMakeLists.txt files....\n"); - make.Configure(args[0].c_str(),&args); + make.Configure(); this->ShowMessage("\n"); // load the cache from disk cmCacheManager *cachem = make.GetCacheManager(); -- cgit v0.12