summaryrefslogtreecommitdiffstats
path: root/Source/MFCDialog
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2003-07-23 21:28:44 (GMT)
committerBrad King <brad.king@kitware.com>2003-07-23 21:28:44 (GMT)
commit6849cbdfcbedf61c7e76ea49b6c5800107bdf420 (patch)
treeb93d7d6419cb87c5cf8c82d540a65cfdf918586a /Source/MFCDialog
parentfde552ea6e43b9950029883076377f750bd60ce7 (diff)
downloadCMake-6849cbdfcbedf61c7e76ea49b6c5800107bdf420.zip
CMake-6849cbdfcbedf61c7e76ea49b6c5800107bdf420.tar.gz
CMake-6849cbdfcbedf61c7e76ea49b6c5800107bdf420.tar.bz2
ENH: Improved behavior when run with arguments from the command line.
Diffstat (limited to 'Source/MFCDialog')
-rw-r--r--Source/MFCDialog/CMakeSetupDialog.cpp104
-rw-r--r--Source/MFCDialog/CMakeSetupDialog.h5
2 files changed, 73 insertions, 36 deletions
diff --git a/Source/MFCDialog/CMakeSetupDialog.cpp b/Source/MFCDialog/CMakeSetupDialog.cpp
index 78a096e..87afc06 100644
--- a/Source/MFCDialog/CMakeSetupDialog.cpp
+++ b/Source/MFCDialog/CMakeSetupDialog.cpp
@@ -1343,51 +1343,87 @@ void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
}
// Handle param or single dropped file.
-// If the dropped file is a build directory or any file in a
-// build directory, set the source dir from the cache file,
-// otherwise set the source and build dirs to this file (or dir).
-
-void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* buffer)
+void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* arg)
{
- // Get the path to this file
-
- std::string path = buffer;
- if (!cmSystemTools::FileIsDirectory(path.c_str()))
+ // 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))
{
- path = cmSystemTools::GetFilenamePath(path);
+ 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
+ else if(cmSystemTools::FileExists(arg))
{
- cmSystemTools::ConvertToUnixSlashes(path);
+ 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());
+ }
}
-
- // Check if it's a build dir and grab the cache
-
- std::string cache_file = path;
- cache_file += "/CMakeCache.txt";
-
- cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
-
- cmCacheManager::CacheIterator it =
- cachem->NewIterator();
-
- if (cmSystemTools::FileExists(cache_file.c_str()) &&
- cachem->LoadCache(path.c_str()) &&
- it.Find("CMAKE_HOME_DIRECTORY"))
+
+ // If there is a CMakeCache.txt file, use its settings.
+ if(cachePath.length() > 0)
{
- path = cmSystemTools::ConvertToOutputPath(path.c_str());
- this->m_WhereBuild = path.c_str();
-
- path = cmSystemTools::ConvertToOutputPath(it.GetValue());
- this->m_WhereSource = path.c_str();
+ cmCacheManager* cachem = m_CMakeInstance->GetCacheManager();
+ cmCacheManager::CacheIterator it = cachem->NewIterator();
+ if(cachem->LoadCache(cachePath.c_str()) && it.Find("CMAKE_HOME_DIRECTORY"))
+ {
+ std::string path = cmSystemTools::ConvertToOutputPath(cachePath.c_str());
+ m_WhereBuild = path.c_str();
+
+ path = cmSystemTools::ConvertToOutputPath(it.GetValue());
+ m_WhereSource = path.c_str();
+ return;
+ }
}
- else
+
+ // If there is a CMakeLists.txt file, use it as the source tree.
+ if(listPath.length() > 0)
{
- path = cmSystemTools::ConvertToOutputPath(path.c_str());
- this->m_WhereSource = this->m_WhereBuild = path.c_str();
+ std::string path = cmSystemTools::ConvertToOutputPath(listPath.c_str());
+ m_WhereSource = path.c_str();
+
+ if(argIsFile)
+ {
+ // Source CMakeLists.txt file given. It was probably dropped
+ // onto the window or executable. Default to an in-source
+ // build.
+ m_WhereBuild = path.c_str();
+ }
+ else
+ {
+ // Source directory given on command line. Use current working
+ // directory as build tree.
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ path = cmSystemTools::ConvertToOutputPath(cwd.c_str());
+ m_WhereBuild = path.c_str();
+ }
}
}
+
// The framework calls this member function when the user releases the
// left mouse button over a window that has registered itself as the
// recipient of dropped files.
diff --git a/Source/MFCDialog/CMakeSetupDialog.h b/Source/MFCDialog/CMakeSetupDialog.h
index 5d475eb..a4a6983 100644
--- a/Source/MFCDialog/CMakeSetupDialog.h
+++ b/Source/MFCDialog/CMakeSetupDialog.h
@@ -97,8 +97,9 @@ protected:
void FillCacheManagerFromCacheGUI();
// Create a shortcut on the desktop with the current Source/Build dir.
int CreateShortcut();
- // Handle param or single dropped file.
- void ChangeDirectoriesFromFile(const char *file);
+
+ // Set initial directories from a file path.
+ void ChangeDirectoriesFromFile(const char* arg);
HICON m_hIcon;
CString m_RegistryKey;