summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2002-11-06 17:04:24 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2002-11-06 17:04:24 (GMT)
commit3d4a2fdc52fa01353653afc8835653559f14e10b (patch)
treea49befb7d4509bf93fe23e908fbe8496fb90faf2 /Source
parent0b7d51d79fb2621e84b1d2de16846426304e5f97 (diff)
downloadCMake-3d4a2fdc52fa01353653afc8835653559f14e10b.zip
CMake-3d4a2fdc52fa01353653afc8835653559f14e10b.tar.gz
CMake-3d4a2fdc52fa01353653afc8835653559f14e10b.tar.bz2
In certain cases, try to guess the source directory, so that you can run cmake or ccmake without specifying source dir
Diffstat (limited to 'Source')
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx2
-rw-r--r--Source/cmake.cxx40
-rw-r--r--Source/cmake.h2
3 files changed, 39 insertions, 5 deletions
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
index 38202fd..e090cf9 100644
--- a/Source/CursesDialog/cmCursesMainForm.cxx
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -992,7 +992,7 @@ void cmCursesMainForm::HandleInput()
void cmCursesMainForm::LoadCache(const char *)
{
- m_CMakeInstance->LoadCache();
+ m_CMakeInstance->LoadCache(true);
m_CMakeInstance->SetCacheArgs(m_Args);
}
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 340ee32..e61308d 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -809,7 +809,9 @@ int cmake::Configure()
int cmake::Run(const std::vector<std::string>& args)
{
// a quick check for args
- if(args.size() == 1 && !cmSystemTools::FileExists("CMakeLists.txt"))
+ if(args.size() == 1 &&
+ !cmSystemTools::FileExists("CMakeLists.txt") &&
+ !cmSystemTools::FileExists("CMakeCache.txt"))
{
this->Usage(args[0].c_str());
return -1;
@@ -836,7 +838,7 @@ int cmake::Run(const std::vector<std::string>& args)
m_CMakeCommand = args[0];
// load the cache
- this->LoadCache();
+ this->LoadCache(true);
// Add any cache args
this->SetCacheArgs(args);
@@ -948,7 +950,7 @@ void cmake::AddDefaultCommands()
}
}
-int cmake::LoadCache()
+int cmake::LoadCache(bool fix_paths)
{
m_CacheManager->LoadCache(this->GetHomeOutputDirectory());
@@ -963,6 +965,38 @@ int cmake::LoadCache()
{
return -3;
}
+
+ if ( fix_paths && cmSystemTools::FileExists("CMakeCache.txt") )
+ {
+ // If we are in directory that has CMakeCache inside and we are
+ // fixing paths then we might have to modify home directory and
+ // start directory.
+ const char* home = this->GetHomeDirectory();
+ const char* startdirectory = this->GetStartDirectory();
+ const char* cachehome = this->GetCacheDefinition("CMAKE_HOME_DIRECTORY");
+ if ( cachehome && strcmp(home, cachehome) != 0 )
+ {
+ // If cachehome exists (it was in the cache), and the current
+ // home is not the same as the one from cache (which means we
+ // are not doing in source build), then fix home and start
+ // directory.
+ home = cachehome;
+ startdirectory = cachehome;
+ }
+ // If cachehome is not set and cmakelists.txt does not exists,
+ // that means we are doing out of source build and the
+ // cmakecache.txt was edited manually and we cannot find the right
+ // source directory.
+ if ( !cachehome && !cmSystemTools::FileExists("CMakeLists.txt") )
+ {
+ cmSystemTools::Error("Source directory not specified");
+ return -4;
+ }
+ // Ok, let's set the home and start directory.
+ this->SetHomeDirectory(home);
+ this->SetStartDirectory(startdirectory);
+ }
+
return 0;
}
diff --git a/Source/cmake.h b/Source/cmake.h
index 749e448..2f30e4f 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -146,7 +146,7 @@ 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 LoadCache();
+ int LoadCache(bool fix_paths = false);
///! Create a GlobalGenerator
cmGlobalGenerator* CreateGlobalGenerator(const char* name);