[CMake] Patch: Unix out-of-source build extension

Andrey aka50 at yandex.ru
Fri Sep 24 08:32:08 EDT 2004


First, thank for greate tool. Really usefull thing for multiplatfom
development. 

I work in XEmacs (FreeBSD) and out-of-source build is usefull, but
still cryptic for edit-and-compile, because Makefiles lives in some
"build" directory. 

This patch realize idea to create some "stub" Makefiles, which will
contain all targets and only "cd" to real build directory and run real
make with specified target. This feature combine out-of-source build
flexibility and still simpe as in-source build. One problem - remove
this file can be acomplished only with commands like "find ./ -exec".
But maybe later I'll fix this.


========================= START CUT THERE ===========================
diff -ru cmake-2.0.3.orig/ChangeLog.txt cmake-2.0.3/ChangeLog.txt
--- cmake-2.0.3.orig/ChangeLog.txt      Wed May  5 18:23:05 2004
+++ cmake-2.0.3/ChangeLog.txt   Fri Sep 24 15:05:30 2004
@@ -1,3 +1,9 @@
+2004-09-24 15:01  aka50
+
+       * Source/cmLocalUnixMakefileGenerator.cxx: ENH: variable 
+        CMAKE_USE_STUB_MAKEFILES:BOOL=ON allows to make stub Makefiles in 
+        source directory when out-of-source build used
+
 2004-05-05 10:19  hoffman
 
        * CMakeLists.txt, Source/cmCPluginAPI.h: ENH: move version to 2.1
diff -ru cmake-2.0.3.orig/Source/cmLocalUnixMakefileGenerator.cxx cmake-2.0.3/Source/cmLocalUnixMakefileGenerator.cxx
--- cmake-2.0.3.orig/Source/cmLocalUnixMakefileGenerator.cxx    Thu Jul 22 19:20:28 2004
+++ cmake-2.0.3/Source/cmLocalUnixMakefileGenerator.cxx Fri Sep 24 15:01:10 2004
@@ -94,6 +94,57 @@
   std::string dest = m_Makefile->GetStartOutputDirectory();
   dest += "/Makefile";
   this->OutputMakefile(dest.c_str(), !fromTheTop); 
+
+  if ( m_Makefile->IsOn("CMAKE_USE_STUB_MAKEFILES") && 
+       strcmp(m_Makefile->GetStartDirectory(), m_Makefile->GetStartOutputDirectory()) && 
+       cmSystemTools::FileIsDirectory(m_Makefile->GetStartDirectory()))
+  {
+
+         // output the makefile fragment
+         std::string destcopy = m_Makefile->GetStartDirectory();
+         destcopy += "/Makefile";
+         cmGeneratedFileStream tempFile(destcopy.c_str());
+         tempFile.SetAlwaysCopy(true);
+         std::ostream&  fout = tempFile.GetStream();
+         if(!fout)
+         {
+                 cmSystemTools::Error("Error can not open for write: ", destcopy.c_str());
+                 return;
+         }
+
+  
+         fout << "# CMAKE generated Makefile, DO NOT EDIT!\n"
+              << "# Generated by \"" << m_GlobalGenerator->GetName() << "\""
+              << " Generator, CMake Version " 
+              << cmMakefile::GetMajorVersion() << "." 
+              << cmMakefile::GetMinorVersion() << "\n"
+              << "# Generated for build path: "
+              << m_Makefile->GetStartOutputDirectory() << "\n\n";
+
+         // generate default targets
+         fout << "# Default targets\n"
+              << "all:\n"
+              << "\tcd " << m_Makefile->GetStartOutputDirectory() << ";$(MAKE) $(MAKESILENT) all\n\n"
+              << "clean:\n"
+              << "\tcd " << m_Makefile->GetStartOutputDirectory() << ";$(MAKE) $(MAKESILENT) clean\n\n"
+              << "depend:\n"
+              << "\tcd " << m_Makefile->GetStartOutputDirectory() << ";$(MAKE) $(MAKESILENT) depend\n\n"
+              << "install:\n"
+              << "\tcd " << m_Makefile->GetStartOutputDirectory() << ";$(MAKE) $(MAKESILENT) install\n\n"
+              << "requild_cache:\n"
+              << "\tcd " << m_Makefile->GetStartOutputDirectory() << ";$(MAKE) $(MAKESILENT) rebuild_cache\n"
+              << "\n";
+
+         // for each target
+         const cmTargets &tgts = m_Makefile->GetTargets();
+         for(cmTargets::const_iterator l = tgts.begin(); 
+             l != tgts.end(); l++)
+         {
+                 fout << l->first.c_str() << ":\n";
+                 fout << "\tcd " << m_Makefile->GetStartOutputDirectory() << ";$(MAKE) $(MAKESILENT) " 
+                      << l->first.c_str() << "\n\n";
+         }
+  }
 }
 
 void 
========================== END CUT THERE ============================



More information about the CMake mailing list