Commit 9f61e2a2 authored by Brad King's avatar Brad King
Browse files

ENH: Centralized and globalized computation of CMake program locations. This...

ENH: Centralized and globalized computation of CMake program locations.  This eliminates startup paths that failed to produce this information.
parent ebc036bb
......@@ -126,6 +126,7 @@ int cpackDefinitionArgument(const char* argument, const char* cValue,
// this is CPack.
int main (int argc, char *argv[])
{
cmSystemTools::FindExecutableDirectory(argv[0]);
cmCPackLog log;
log.SetErrorPrefix("CPack Error: ");
log.SetWarningPrefix("CPack Warning: ");
......@@ -246,7 +247,7 @@ int main (int argc, char *argv[])
{
// find out which system cpack is running on, so it can setup the search
// paths, so FIND_XXX() commands can be used in scripts
cminst.AddCMakePaths(argv[0]);
cminst.AddCMakePaths();
std::string systemFile =
globalMF->GetModulesFile("CMakeDetermineSystem.cmake");
if (!globalMF->ReadListFile(0, systemFile.c_str()))
......
......@@ -293,7 +293,7 @@ void cmCTestScriptHandler::CreateCMake()
delete this->LocalGenerator;
}
this->CMake = new cmake;
this->CMake->AddCMakePaths(this->CTest->GetCTestExecutable());
this->CMake->AddCMakePaths();
this->GlobalGenerator = new cmGlobalGenerator;
this->GlobalGenerator->SetCMakeInstance(this->CMake);
......
......@@ -105,6 +105,7 @@ void CMakeErrorHandler(const char* message, const char* title, bool&, void* clie
int main(int argc, char** argv)
{
cmSystemTools::FindExecutableDirectory(argv[0]);
cmDocumentation doc;
if(doc.CheckOptions(argc, argv))
{
......
......@@ -19,8 +19,11 @@
#include "FL/Fl.H"
#include "FL/fl_ask.H"
#include "cmSystemTools.h"
int main(int argc, char * argv[] )
{
cmSystemTools::FindExecutableDirectory(argv[0]);
fl_message_font(FL_HELVETICA,11);
......
......@@ -7,6 +7,7 @@
#include "CMakeCommandLineInfo.h"
#include "../cmDocumentation.h"
#include "../cmake.h"
#include "../cmSystemTools.h"
//----------------------------------------------------------------------------
......@@ -101,6 +102,7 @@ BOOL CMakeSetup::InitInstance()
#endif
CMakeCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
cmSystemTools::FindExecutableDirectory(cmdInfo.GetArgV()[0]);
// Check for documentation options. If there are no arguments skip
// the check because the GUI should be displayed instead of showing
......@@ -111,7 +113,7 @@ BOOL CMakeSetup::InitInstance()
{
// Construct and print requested documentation.
cmake hcm;
hcm.AddCMakePaths(cmdInfo.GetArgV()[0]);
hcm.AddCMakePaths();
doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
std::vector<cmDocumentationEntry> commands;
std::vector<cmDocumentationEntry> compatCommands;
......
......@@ -21,6 +21,7 @@
#include "CMakeSetupDialog.h"
#include "cmDocumentation.h"
#include "cmSystemTools.h"
#include "cmake.h"
//----------------------------------------------------------------------------
......@@ -61,6 +62,7 @@ static const char * cmDocumentationOptions[][3] =
int main(int argc, char** argv)
{
cmSystemTools::FindExecutableDirectory(argv[0]);
QApplication app(argc, argv);
app.setApplicationName("CMakeSetup");
app.setOrganizationName("Kitware");
......@@ -72,7 +74,7 @@ int main(int argc, char** argv)
{
// Construct and print requested documentation.
cmake hcm;
hcm.AddCMakePaths(app.argv()[0]);
hcm.AddCMakePaths();
doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
std::vector<cmDocumentationEntry> commands;
std::vector<cmDocumentationEntry> compatCommands;
......
......@@ -1774,7 +1774,7 @@ void cmCTest::HandleScriptArguments(size_t &i,
// the main entry point of ctest, called from main
int cmCTest::Run(std::vector<std::string> &args, std::string* output)
{
this->FindRunningCMake(args[0].c_str());
this->FindRunningCMake();
const char* ctestExec = "ctest";
bool cmakeAndTest = false;
bool performSomeTest = true;
......@@ -1970,70 +1970,25 @@ int cmCTest::Run(std::vector<std::string> &args, std::string* output)
}
//----------------------------------------------------------------------
void cmCTest::FindRunningCMake(const char* arg0)
void cmCTest::FindRunningCMake()
{
// Find our own executable.
std::vector<cmStdString> failures;
this->CTestSelf = arg0;
cmSystemTools::ConvertToUnixSlashes(this->CTestSelf);
failures.push_back(this->CTestSelf);
this->CTestSelf = cmSystemTools::FindProgram(this->CTestSelf.c_str());
this->CTestSelf = cmSystemTools::GetExecutableDirectory();
this->CTestSelf += "/ctest";
this->CTestSelf += cmSystemTools::GetExecutableExtension();
if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
{
failures.push_back(this->CTestSelf);
this->CTestSelf = "/usr/local/bin/ctest";
cmSystemTools::Error("CTest executable cannot be found at ",
this->CTestSelf.c_str());
}
if(!cmSystemTools::FileExists(this->CTestSelf.c_str()))
{
failures.push_back(this->CTestSelf);
cmOStringStream msg;
msg << "CTEST can not find the command line program ctest.\n";
msg << " argv[0] = \"" << arg0 << "\"\n";
msg << " Attempted paths:\n";
std::vector<cmStdString>::iterator i;
for(i=failures.begin(); i != failures.end(); ++i)
{
msg << " \"" << i->c_str() << "\"\n";
}
cmSystemTools::Error(msg.str().c_str());
}
std::string dir;
std::string file;
if(cmSystemTools::SplitProgramPath(this->CTestSelf.c_str(),
dir, file, true))
{
this->CMakeSelf = dir += "/cmake";
this->CMakeSelf += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(this->CMakeSelf.c_str()))
{
return;
}
}
failures.push_back(this->CMakeSelf);
#ifdef CMAKE_BUILD_DIR
std::string intdir = ".";
#ifdef CMAKE_INTDIR
intdir = CMAKE_INTDIR;
#endif
this->CMakeSelf = CMAKE_BUILD_DIR;
this->CMakeSelf += "/bin/";
this->CMakeSelf += intdir;
this->CMakeSelf = cmSystemTools::GetExecutableDirectory();
this->CMakeSelf += "/cmake";
this->CMakeSelf += cmSystemTools::GetExecutableExtension();
#endif
if(!cmSystemTools::FileExists(this->CMakeSelf.c_str()))
{
failures.push_back(this->CMakeSelf);
cmOStringStream msg;
msg << "CTEST can not find the command line program cmake.\n";
msg << " argv[0] = \"" << arg0 << "\"\n";
msg << " Attempted paths:\n";
std::vector<cmStdString>::iterator i;
for(i=failures.begin(); i != failures.end(); ++i)
{
msg << " \"" << i->c_str() << "\"\n";
}
cmSystemTools::Error(msg.str().c_str());
cmSystemTools::Error("CMake executable cannot be found at ",
this->CMakeSelf.c_str());
}
}
......
......@@ -398,7 +398,7 @@ private:
const VectorOfStrings& files);
///! Find the running cmake
void FindRunningCMake(const char* arg0);
void FindRunningCMake();
//! Check if the argument is the one specified
bool CheckArgument(const std::string& arg, const char* varg1,
......
......@@ -121,6 +121,7 @@ int DumpForCoverage(const char* outname)
int main(int ac, char** av)
{
cmSystemTools::EnableMSVCDebugHook();
cmSystemTools::FindExecutableDirectory(av[0]);
const char* outname = "cmake.html";
bool coverage = false;
if(ac > 1)
......
......@@ -2064,3 +2064,26 @@ bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile)
#endif
return true;
}
//----------------------------------------------------------------------------
static std::string cmSystemToolsExecutableDirectory;
void cmSystemTools::FindExecutableDirectory(const char* argv0)
{
std::string errorMsg;
std::string exe;
if(cmSystemTools::FindProgramPath(argv0, exe, errorMsg))
{
cmSystemToolsExecutableDirectory =
cmSystemTools::GetFilenamePath(exe.c_str());
}
else
{
// ???
}
}
//----------------------------------------------------------------------------
const char* cmSystemTools::GetExecutableDirectory()
{
return cmSystemToolsExecutableDirectory.c_str();
}
......@@ -350,6 +350,14 @@ public:
the first argument to that named by the second. */
static bool CopyFileTime(const char* fromFile, const char* toFile);
/** Find the directory containing the running executable. Save it
in a global location to be queried by GetExecutableDirectory
later. */
static void FindExecutableDirectory(const char* argv0);
/** Get the directory containing the currently running executable. */
static const char* GetExecutableDirectory();
private:
static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole;
......
......@@ -739,56 +739,16 @@ void cmake::SetDirectoriesFromFile(const char* arg)
// at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
// cache
int cmake::AddCMakePaths(const char *arg0)
int cmake::AddCMakePaths()
{
// Find the cmake executable
std::vector<cmStdString> failures;
std::string cMakeSelf = arg0;
cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
if ((strstr(arg0, "cpack")!=0) || (strstr(arg0, "ctest")!=0))
{
// when called from cpack or ctest CMAKE_COMMAND would otherwise point
// to cpack or ctest and not cmake
cMakeSelf = cmSystemTools::GetFilenamePath(cMakeSelf) +
"/cmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
}
failures.push_back(cMakeSelf);
cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
{
#ifdef CMAKE_BUILD_DIR
std::string intdir = ".";
#ifdef CMAKE_INTDIR
intdir = CMAKE_INTDIR;
#endif
cMakeSelf = CMAKE_BUILD_DIR;
cMakeSelf += "/bin/";
cMakeSelf += intdir;
std::string cMakeSelf = cmSystemTools::GetExecutableDirectory();
cMakeSelf += "/cmake";
cMakeSelf += cmSystemTools::GetExecutableExtension();
#endif
}
#ifdef CMAKE_PREFIX
if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
{
failures.push_back(cMakeSelf);
cMakeSelf = CMAKE_PREFIX "/bin/cmake";
}
#endif
if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
{
failures.push_back(cMakeSelf);
cmOStringStream msg;
msg << "CMAKE can not find the command line program cmake.\n";
msg << " argv[0] = \"" << arg0 << "\"\n";
msg << " Attempted paths:\n";
std::vector<cmStdString>::iterator i;
for(i=failures.begin(); i != failures.end(); ++i)
{
msg << " \"" << i->c_str() << "\"\n";
}
cmSystemTools::Error(msg.str().c_str());
cmSystemTools::Error("CMake executable cannot be found at ",
cMakeSelf.c_str());
return 0;
}
// Save the value in the cache
......@@ -2157,7 +2117,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
}
else
{
this->AddCMakePaths(this->CMakeCommand.c_str());
this->AddCMakePaths();
}
// Add any cache args
......@@ -2376,7 +2336,7 @@ int cmake::LoadCache()
}
// setup CMAKE_ROOT and CMAKE_COMMAND
if(!this->AddCMakePaths(this->CMakeCommand.c_str()))
if(!this->AddCMakePaths())
{
return -3;
}
......@@ -3503,7 +3463,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
// we have to find the module directory, so we can copy the files
this->AddCMakePaths(args[0].c_str());
this->AddCMakePaths();
std::string modulesPath =
this->CacheManager->GetCacheValue("CMAKE_ROOT");
modulesPath += "/Modules";
......
......@@ -288,7 +288,7 @@ class cmake
/**
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
*/
int AddCMakePaths(const char *arg0);
int AddCMakePaths();
/**
* Get the file comparison class
......
......@@ -273,6 +273,7 @@ static void cmakemainProgressCallback(const char *m, float prog,
int main(int ac, char** av)
{
cmSystemTools::EnableMSVCDebugHook();
cmSystemTools::FindExecutableDirectory(av[0]);
int ret = do_cmake(ac, av);
#ifdef CMAKE_BUILD_WITH_CMAKE
cmDynamicLoader::FlushCache();
......@@ -299,7 +300,7 @@ int do_cmake(int ac, char** av)
{
// Construct and print requested documentation.
cmake hcm;
hcm.AddCMakePaths(av[0]);
hcm.AddCMakePaths();
doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
// the command line args are processed here so that you can do
......
......@@ -210,6 +210,7 @@ int main (int argc, char *argv[])
{
cmSystemTools::DoNotInheritStdPipes();
cmSystemTools::EnableMSVCDebugHook();
cmSystemTools::FindExecutableDirectory(argv[0]);
int nocwd = 0;
cmCTest inst;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment