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(s_ConstHelpMessage);
this->CMakeInstance = new cmake;
this->CMakeInstance->SetCMakeEditCommand("ccmake");
// create the arguments for the cmake object
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_CMakeInstance = new cmake;
m_CMakeInstance->SetCMakeEditCommand("CMakeSetup");
m_CMakeInstance->SetProgressCallback(updateProgress, (void *)this);
//{{AFX_DATA_INIT(CMakeSetupDialog)

View File

@ -26,6 +26,7 @@
#include "cmSystemTools.h"
#include "cmake.h"
#include "cmVersion.h"
#include <cmsys/CommandLineArguments.hxx>
//----------------------------------------------------------------------------
static const char * cmDocumentationName[][3] =
@ -125,20 +126,39 @@ int main(int argc, char** argv)
dialog.setWindowTitle(title);
dialog.show();
// for now: args support specifying build and/or source directory
QStringList args = app.arguments();
if(args.count() == 2)
cmsys::CommandLineArguments arg;
arg.Initialize(argc, argv);
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");
QFileInfo srcFileInfo(args[1], "CMakeLists.txt");
if(buildFileInfo.exists())
dialog.setSourceDirectory(sourceDirectory.c_str());
dialog.setBinaryDirectory(binaryDirectory.c_str());
}
else
{
QStringList args = app.arguments();
if(args.count() == 2)
{
dialog.setBinaryDirectory(buildFileInfo.absolutePath());
}
else if(srcFileInfo.exists())
{
dialog.setSourceDirectory(srcFileInfo.absolutePath());
dialog.setBinaryDirectory(QDir::currentPath());
QFileInfo buildFileInfo(args[1], "CMakeCache.txt");
QFileInfo srcFileInfo(args[1], "CMakeLists.txt");
if(buildFileInfo.exists())
{
dialog.setBinaryDirectory(buildFileInfo.absolutePath());
}
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);
this->CMakeInstance = new cmake;
this->CMakeInstance->SetCMakeEditCommand("cmake-gui");
this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
std::vector<std::string> generators;

View File

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

View File

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