summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2007-12-13 17:56:50 -0500
committerBrad King <brad.king@kitware.com>2007-12-13 17:56:50 -0500
commit9f61e2a235fc04e57237dc932aee61b264ef8916 (patch)
tree482f697639a0e55198f198eaf67282f088dee202
parentebc036bbdaa602c9276ad91469a305b42fda7cbc (diff)
downloadcmake-9f61e2a235fc04e57237dc932aee61b264ef8916.tar.gz
ENH: Centralized and globalized computation of CMake program locations. This eliminates startup paths that failed to produce this information.
-rw-r--r--Source/CPack/cpack.cxx3
-rw-r--r--Source/CTest/cmCTestScriptHandler.cxx2
-rw-r--r--Source/CursesDialog/ccmake.cxx1
-rw-r--r--Source/FLTKDialog/FLTKDialog.cxx3
-rw-r--r--Source/MFCDialog/CMakeSetup.cpp4
-rw-r--r--Source/QtDialog/CMakeSetup.cxx4
-rw-r--r--Source/cmCTest.cxx67
-rw-r--r--Source/cmCTest.h2
-rw-r--r--Source/cmDumpDocumentation.cxx1
-rw-r--r--Source/cmSystemTools.cxx23
-rw-r--r--Source/cmSystemTools.h8
-rw-r--r--Source/cmake.cxx54
-rw-r--r--Source/cmake.h2
-rw-r--r--Source/cmakemain.cxx3
-rw-r--r--Source/ctest.cxx1
15 files changed, 68 insertions, 110 deletions
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
index 4da903ec97..b36e2303bd 100644
--- a/Source/CPack/cpack.cxx
+++ b/Source/CPack/cpack.cxx
@@ -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()))
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx
index 64cf92d613..c30e2818eb 100644
--- a/Source/CTest/cmCTestScriptHandler.cxx
+++ b/Source/CTest/cmCTestScriptHandler.cxx
@@ -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);
diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx
index 7f9b3f6bd7..a2f86a3a27 100644
--- a/Source/CursesDialog/ccmake.cxx
+++ b/Source/CursesDialog/ccmake.cxx
@@ -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))
{
diff --git a/Source/FLTKDialog/FLTKDialog.cxx b/Source/FLTKDialog/FLTKDialog.cxx
index dedb2e414c..df7df772b6 100644
--- a/Source/FLTKDialog/FLTKDialog.cxx
+++ b/Source/FLTKDialog/FLTKDialog.cxx
@@ -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);
diff --git a/Source/MFCDialog/CMakeSetup.cpp b/Source/MFCDialog/CMakeSetup.cpp
index 6d25ba2a44..8d318a6bfc 100644
--- a/Source/MFCDialog/CMakeSetup.cpp
+++ b/Source/MFCDialog/CMakeSetup.cpp
@@ -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;
diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx
index c7f5f54879..3543903102 100644
--- a/Source/QtDialog/CMakeSetup.cxx
+++ b/Source/QtDialog/CMakeSetup.cxx
@@ -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;
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index 75c2fa7523..97132ae862 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -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());
}
}
diff --git a/Source/cmCTest.h b/Source/cmCTest.h
index 99ccf0ac2d..2a1169a8df 100644
--- a/Source/cmCTest.h
+++ b/Source/cmCTest.h
@@ -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,
diff --git a/Source/cmDumpDocumentation.cxx b/Source/cmDumpDocumentation.cxx
index b59b114541..838dbe91ae 100644
--- a/Source/cmDumpDocumentation.cxx
+++ b/Source/cmDumpDocumentation.cxx
@@ -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)
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 52031ea244..52e1ca24b9 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -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();
+}
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 9007537849..bbc9ba65c5 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -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;
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index a3c95be8a1..fd59808738 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -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";
diff --git a/Source/cmake.h b/Source/cmake.h
index be03bdf604..265fc0a830 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -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
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index ebc547a736..839c3f35fe 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -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
diff --git a/Source/ctest.cxx b/Source/ctest.cxx
index 27971cfd4e..11e8dd2f82 100644
--- a/Source/ctest.cxx
+++ b/Source/ctest.cxx
@@ -210,6 +210,7 @@ int main (int argc, char *argv[])
{
cmSystemTools::DoNotInheritStdPipes();
cmSystemTools::EnableMSVCDebugHook();
+ cmSystemTools::FindExecutableDirectory(argv[0]);
int nocwd = 0;
cmCTest inst;