diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index d4b29f5..d4b9912 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -544,10 +544,22 @@ void cmake::SetArgs(const std::vector<std::string>& args)
       {
       // There is no local generate anymore.  Ignore -O option.
       }
+    //this will set the output directory to the path specified
     else if(arg.find("-B",0) == 0)
       {
       directoriesSet = true;
       std::string path = arg.substr(2);
+    
+      if (path.empty())
+        {
+        if(++i >= args.size())
+          {
+          cmSystemTools::Error("No path specified for -B");
+          return;
+          }
+        path = args[i];
+        }
+    
       path = cmSystemTools::CollapseFullPath(path.c_str());
       cmSystemTools::ConvertToUnixSlashes(path);
       this->SetHomeOutputDirectory(path.c_str());
@@ -753,23 +765,26 @@ void cmake::SetDirectoriesFromFile(const char* arg)
     {
     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
+    
+    if (this->HomeOutputDirectory.empty())
       {
-      // 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());
+        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());
+        }
+        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(this->HomeOutputDirectory.c_str());
+        return;
       }
-    return;
     }
 
   // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
@@ -779,8 +794,11 @@ void cmake::SetDirectoriesFromFile(const char* 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());
+  
+  if (this->HomeOutputDirectory.empty())
+    this->SetHomeOutputDirectory(cwd.c_str());
+  
+  this->SetStartOutputDirectory(this->HomeOutputDirectory.c_str());
 }
 
 // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the