ENH: fix make edit_cache for cmake-gui

This commit is contained in:
Bill Hoffman 2008-02-12 09:49:42 -05:00
parent 88eca37d4e
commit 3fa087c8ab
6 changed files with 72 additions and 25 deletions

View File

@ -48,6 +48,7 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
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;
this->CMakeInstance->SetCMakeEditCommand("ccmake");
// create the arguments for the cmake object // create the arguments for the cmake object
std::string whereCMake = cmSystemTools::GetProgramPath(this->Args[0].c_str()); std::string whereCMake = cmSystemTools::GetProgramPath(this->Args[0].c_str());

View File

@ -170,6 +170,7 @@ CMakeSetupDialog::CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
m_CacheEntriesList.m_CMakeSetupDialog = this; m_CacheEntriesList.m_CMakeSetupDialog = this;
m_CMakeInstance = new cmake; m_CMakeInstance = new cmake;
m_CMakeInstance->SetCMakeEditCommand("CMakeSetup");
m_CMakeInstance->SetProgressCallback(updateProgress, (void *)this); m_CMakeInstance->SetProgressCallback(updateProgress, (void *)this);
//{{AFX_DATA_INIT(CMakeSetupDialog) //{{AFX_DATA_INIT(CMakeSetupDialog)

View File

@ -26,6 +26,7 @@
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmake.h" #include "cmake.h"
#include "cmVersion.h" #include "cmVersion.h"
#include <cmsys/CommandLineArguments.hxx>
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
static const char * cmDocumentationName[][3] = static const char * cmDocumentationName[][3] =
@ -125,20 +126,39 @@ int main(int argc, char** argv)
dialog.setWindowTitle(title); dialog.setWindowTitle(title);
dialog.show(); dialog.show();
// for now: args support specifying build and/or source directory cmsys::CommandLineArguments arg;
QStringList args = app.arguments(); arg.Initialize(argc, argv);
if(args.count() == 2) std::string binaryDirectory;
std::string sourceDirectory;
typedef cmsys::CommandLineArguments argT;
arg.AddArgument("-B", argT::CONCAT_ARGUMENT,
&binaryDirectory, "Binary Directory");
arg.AddArgument("-H", argT::CONCAT_ARGUMENT,
&sourceDirectory, "Source Directory");
// do not complain about unknown options
arg.StoreUnusedArguments(true);
arg.Parse();
if(!sourceDirectory.empty() && !binaryDirectory.empty())
{ {
QFileInfo buildFileInfo(args[1], "CMakeCache.txt"); dialog.setSourceDirectory(sourceDirectory.c_str());
QFileInfo srcFileInfo(args[1], "CMakeLists.txt"); dialog.setBinaryDirectory(binaryDirectory.c_str());
if(buildFileInfo.exists()) }
else
{
QStringList args = app.arguments();
if(args.count() == 2)
{ {
dialog.setBinaryDirectory(buildFileInfo.absolutePath()); QFileInfo buildFileInfo(args[1], "CMakeCache.txt");
} QFileInfo srcFileInfo(args[1], "CMakeLists.txt");
else if(srcFileInfo.exists()) if(buildFileInfo.exists())
{ {
dialog.setSourceDirectory(srcFileInfo.absolutePath()); dialog.setBinaryDirectory(buildFileInfo.absolutePath());
dialog.setBinaryDirectory(QDir::currentPath()); }
else if(srcFileInfo.exists())
{
dialog.setSourceDirectory(srcFileInfo.absolutePath());
dialog.setBinaryDirectory(QDir::currentPath());
}
} }
} }

View File

@ -47,6 +47,7 @@ QCMake::QCMake(QObject* p)
cmSystemTools::SetErrorCallback(QCMake::errorCallback, this); cmSystemTools::SetErrorCallback(QCMake::errorCallback, this);
this->CMakeInstance = new cmake; this->CMakeInstance = new cmake;
this->CMakeInstance->SetCMakeEditCommand("cmake-gui");
this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this); this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
std::vector<std::string> generators; std::vector<std::string> generators;

View File

@ -756,20 +756,39 @@ int cmake::AddCMakePaths()
this->CacheManager->AddCacheEntry this->CacheManager->AddCacheEntry
("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.", ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.",
cmCacheManager::INTERNAL); cmCacheManager::INTERNAL);
// if the edit command is not yet in the cache,
// Find and save the command to edit the cache // or if CMakeEditCommand has been set on this object,
std::string editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) + // then set the CMAKE_EDIT_COMMAND in the cache
"/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf); // This will mean that the last gui to edit the cache
if( !cmSystemTools::FileExists(editCacheCommand.c_str())) // will be the one that make edit_cache uses.
if(!this->GetCacheDefinition("CMAKE_EDIT_COMMAND")
|| !this->CMakeEditCommand.empty())
{ {
editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) + // Find and save the command to edit the cache
"/CMakeSetup" + cmSystemTools::GetFilenameExtension(cMakeSelf); std::string editCacheCommand;
} if(!this->CMakeEditCommand.empty())
if(cmSystemTools::FileExists(editCacheCommand.c_str())) {
{ editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf)
this->CacheManager->AddCacheEntry + std::string("/")
("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(), + this->CMakeEditCommand
"Path to cache edit program executable.", cmCacheManager::INTERNAL); + cmSystemTools::GetFilenameExtension(cMakeSelf);
}
if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
{
editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
"/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
}
if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
{
editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
"/CMakeSetup" + cmSystemTools::GetFilenameExtension(cMakeSelf);
}
if(cmSystemTools::FileExists(editCacheCommand.c_str()))
{
this->CacheManager->AddCacheEntry
("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
"Path to cache edit program executable.", cmCacheManager::INTERNAL);
}
} }
std::string ctestCommand = cmSystemTools::GetFilenamePath(cMakeSelf) + std::string ctestCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
"/ctest" + cmSystemTools::GetFilenameExtension(cMakeSelf); "/ctest" + cmSystemTools::GetFilenameExtension(cMakeSelf);

View File

@ -329,6 +329,10 @@ class cmake
// Define the properties // Define the properties
static void DefineProperties(cmake *cm); static void DefineProperties(cmake *cm);
void SetCMakeEditCommand(const char* s)
{
this->CMakeEditCommand = s;
}
protected: protected:
int HandleDeleteCacheVariables(const char* var); int HandleDeleteCacheVariables(const char* var);
cmPropertyMap Properties; cmPropertyMap Properties;
@ -413,6 +417,7 @@ private:
bool InTryCompile; bool InTryCompile;
bool ScriptMode; bool ScriptMode;
bool DebugOutput; bool DebugOutput;
std::string CMakeEditCommand;
std::string CMakeCommand; std::string CMakeCommand;
std::string CXXEnvironment; std::string CXXEnvironment;
std::string CCEnvironment; std::string CCEnvironment;