Index: Source/cmake.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.h,v
retrieving revision 1.71
diff -c -3 -p -r1.71 cmake.h
*** Source/cmake.h	6 Oct 2006 15:11:59 -0000	1.71
--- Source/cmake.h	23 Oct 2006 19:56:31 -0000
*************** class cmake
*** 121,126 ****
--- 121,132 ----
    //@}
  
    /**
+    * Configure the top-level source and build trees.
+    */
+   void SetupSourceAndBuildTree(const char* source_dir,
+                                const char* binary_dir);
+ 
+   /**
     * Dump documentation to a file. If 0 is returned, the
     * operation failed.
     */
Index: Source/cmake.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmake.cxx,v
retrieving revision 1.270
diff -c -3 -p -r1.270 cmake.cxx
*** Source/cmake.cxx	16 Oct 2006 16:49:26 -0000	1.270
--- Source/cmake.cxx	23 Oct 2006 19:56:31 -0000
*************** void cmake::SetArgs(const std::vector<st
*** 486,499 ****
      }
    if(!directoriesSet)
      {
!     this->SetHomeOutputDirectory
!       (cmSystemTools::GetCurrentWorkingDirectory().c_str());
!     this->SetStartOutputDirectory
!       (cmSystemTools::GetCurrentWorkingDirectory().c_str());
!     this->SetHomeDirectory
!       (cmSystemTools::GetCurrentWorkingDirectory().c_str());
!     this->SetStartDirectory
!       (cmSystemTools::GetCurrentWorkingDirectory().c_str());
      }
  
    this->SetStartDirectory(this->GetHomeDirectory());
--- 486,493 ----
      }
    if(!directoriesSet)
      {
!     std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
!     this->SetupSourceAndBuildTree(cwd.c_str(), cwd.c_str());
      }
  
    this->SetStartDirectory(this->GetHomeDirectory());
*************** void cmake::SetDirectoriesFromFile(const
*** 577,599 ****
    // 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;
      }
--- 571,588 ----
    // If there is a CMakeLists.txt file, use it as the source tree.
    if(listPath.length() > 0)
      {
      if(argIsFile)
        {
        // Source CMakeLists.txt file given.  It was probably dropped
        // onto the executable in a GUI.  Default to an in-source build.
!       this->SetupSourceAndBuildTree(listPath.c_str(), listPath.c_str());
        }
      else
        {
        // Source directory given on command line.  Use current working
        // directory as build tree.
        std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
!       this->SetupSourceAndBuildTree(listPath.c_str(), cwd.c_str());
        }
      return;
      }
*************** void cmake::SetDirectoriesFromFile(const
*** 603,612 ****
    // 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
--- 592,661 ----
    // current working directory as the build tree.
    std::string full = cmSystemTools::CollapseFullPath(arg);
    std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
!   this->SetupSourceAndBuildTree(full.c_str(), cwd.c_str());
! }
! 
! //----------------------------------------------------------------------------
! void cmake::SetupSourceAndBuildTree(const char* source_dir,
!                                     const char* binary_dir)
! {
!   std::string source_directory = source_dir;
!   std::string binary_directory = binary_dir;
!   if(cmSystemTools::ComparePath(source_dir, binary_dir))
!     {
!     // In-source build.
!     std::string project_file = source_dir;
!     project_file += "/InSource.cmake";
!     if(cmSystemTools::FileExists(project_file.c_str()))
!       {
!       cmake cm;
!       cm.SetHomeDirectory(source_directory.c_str());
!       cm.SetStartDirectory(source_directory.c_str());
!       cm.SetHomeOutputDirectory(binary_directory.c_str());
!       cm.SetStartOutputDirectory(binary_directory.c_str());
!       cmGlobalGenerator gg;
!       gg.SetCMakeInstance(&cm);
!       std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
!       lg->SetGlobalGenerator(&gg);
!       cmMakefile* mf = lg->GetMakefile();
!       mf->SetHomeOutputDirectory(cm.GetHomeOutputDirectory());
!       mf->SetStartOutputDirectory(cm.GetStartOutputDirectory());
!       mf->SetHomeDirectory(cm.GetHomeDirectory());
!       mf->SetStartDirectory(cm.GetStartDirectory());
!       if(mf->ReadListFile(0, project_file.c_str()))
!         {
!         if(cmSystemTools::GetErrorOccuredFlag())
!           {
!           cmSystemTools::SetFatalErrorOccured();
!           }
!         else if(
!           const char* bd = mf->GetDefinition("CMAKE_IN_SOURCE_BINARY_DIR"))
!           {
!           if(cmSystemTools::FileIsFullPath(bd))
!             {
!             binary_directory = bd;
!             }
!           else
!             {
!             binary_directory += "/";
!             binary_directory += bd;
!             binary_directory =
!               cmSystemTools::CollapseFullPath(binary_directory.c_str());
!             }
!           }
!         }
!       else
!         {
!         cmSystemTools::Error("Error reading ", project_file.c_str());
!         cmSystemTools::SetFatalErrorOccured();
!         }
!       }
!     }
! 
!   this->SetHomeDirectory(source_directory.c_str());
!   this->SetStartDirectory(source_directory.c_str());
!   this->SetHomeOutputDirectory(binary_directory.c_str());
!   this->SetStartOutputDirectory(binary_directory.c_str());
  }
  
  // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
*************** int cmake::Run(const std::vector<std::st
*** 1718,1724 ****
    this->SetArgs(args);
    if(cmSystemTools::GetErrorOccuredFlag())
      {
-     CMakeCommandUsage(args[0].c_str());
      return -1;
      }
  
--- 1767,1772 ----
