diff options
author | Brad King <brad.king@kitware.com> | 2003-08-05 20:36:15 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2003-08-05 20:36:15 (GMT) |
commit | 1e077d436e4fe2642e85bdb166b2983610d8d308 (patch) | |
tree | 192231528ee9f516551b69546ceff7ffc35fb13f /Source | |
parent | 8830b45b886a92614fef2fda7c86eeefe61b3d2f (diff) | |
download | CMake-1e077d436e4fe2642e85bdb166b2983610d8d308.zip CMake-1e077d436e4fe2642e85bdb166b2983610d8d308.tar.gz CMake-1e077d436e4fe2642e85bdb166b2983610d8d308.tar.bz2 |
ENH#61: cmake and ccmake now support passing the path to a CMakeCache.txt file as an argument. Its settings will be loaded.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmake.cxx | 100 | ||||
-rw-r--r-- | Source/cmake.h | 2 |
2 files changed, 94 insertions, 8 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 6eaba36..8747cc8 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -329,14 +329,7 @@ void cmake::SetArgs(const std::vector<std::string>& args) else { directoriesSet = true; - this->SetHomeOutputDirectory - (cmSystemTools::GetCurrentWorkingDirectory().c_str()); - this->SetStartOutputDirectory - (cmSystemTools::GetCurrentWorkingDirectory().c_str()); - this->SetHomeDirectory - (cmSystemTools::CollapseFullPath(arg.c_str()).c_str()); - this->SetStartDirectory - (cmSystemTools::CollapseFullPath(arg.c_str()).c_str()); + this->SetDirectoriesFromFile(arg.c_str()); } } if(!directoriesSet) @@ -357,6 +350,97 @@ void cmake::SetArgs(const std::vector<std::string>& args) } } +//---------------------------------------------------------------------------- +void cmake::SetDirectoriesFromFile(const char* arg) +{ + // Check if the argument refers to a CMakeCache.txt or + // CMakeLists.txt file. + std::string listPath; + std::string cachePath; + bool argIsFile = false; + if(cmSystemTools::FileIsDirectory(arg)) + { + std::string path = cmSystemTools::CollapseFullPath(arg); + cmSystemTools::ConvertToUnixSlashes(path); + std::string cacheFile = path; + cacheFile += "/CMakeCache.txt"; + std::string listFile = path; + listFile += "/CMakeLists.txt"; + if(cmSystemTools::FileExists(cacheFile.c_str())) + { + cachePath = path; + } + if(cmSystemTools::FileExists(listFile.c_str())) + { + listPath = path; + } + } + else if(cmSystemTools::FileExists(arg)) + { + argIsFile = true; + std::string fullPath = cmSystemTools::CollapseFullPath(arg); + std::string name = cmSystemTools::GetFilenameName(fullPath.c_str()); + name = cmSystemTools::LowerCase(name); + if(name == "cmakecache.txt") + { + cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str()); + } + else if(name == "cmakelists.txt") + { + listPath = cmSystemTools::GetFilenamePath(fullPath.c_str()); + } + } + + // If there is a CMakeCache.txt file, use its settings. + if(cachePath.length() > 0) + { + cmCacheManager* cachem = this->GetCacheManager(); + cmCacheManager::CacheIterator it = cachem->NewIterator(); + if(cachem->LoadCache(cachePath.c_str()) && it.Find("CMAKE_HOME_DIRECTORY")) + { + this->SetHomeOutputDirectory(cachePath.c_str()); + this->SetStartOutputDirectory(cachePath.c_str()); + this->SetHomeDirectory(it.GetValue()); + this->SetStartDirectory(it.GetValue()); + return; + } + } + + // If there is a CMakeLists.txt file, use it as the source tree. + if(listPath.length() > 0) + { + this->SetHomeDirectory(listPath.c_str()); + this->SetStartDirectory(listPath.c_str()); + + if(argIsFile) + { + // Source CMakeLists.txt file given. It was probably dropped + // onto the executable in a GUI. Default to an in-source build. + this->SetHomeOutputDirectory(listPath.c_str()); + this->SetStartOutputDirectory(listPath.c_str()); + } + else + { + // Source directory given on command line. Use current working + // directory as build tree. + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + this->SetHomeOutputDirectory(cwd.c_str()); + this->SetStartOutputDirectory(cwd.c_str()); + } + return; + } + + // We didn't find a CMakeLists.txt or CMakeCache.txt file from the + // argument. Assume it is the path to the source tree, and use the + // current working directory as the build tree. + std::string full = cmSystemTools::CollapseFullPath(arg); + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + this->SetHomeDirectory(full.c_str()); + this->SetStartDirectory(full.c_str()); + this->SetHomeOutputDirectory(cwd.c_str()); + this->SetStartOutputDirectory(cwd.c_str()); +} + // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the cache int cmake::AddCMakePaths(const char *arg0) { diff --git a/Source/cmake.h b/Source/cmake.h index fc7b4ac..5022518 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -273,6 +273,8 @@ protected: */ int AddCMakePaths(const char *arg0); + void SetDirectoriesFromFile(const char* arg); + cmVariableWatch* m_VariableWatch; private: |