Hello,

As I told yesterday, here comes a patch for the Eclipse CDT4 generator available in the current CVS version of CMake.

Although I have not extensively tested it, the works fine. In addition to the in-tree build which has always worked, this patch allows you to have 'myapp' and 'myapp/build' or 'myapp' and 'myapp-build' at the same level:

mydir/myapp
mydir/myapp/build

or

mydir/myapp
mydir/myapp-build

The patch breaks the CMake way of doing thing, as it writes the Eclipse project files (.project and .cproject) in the source directory even in an out-of-tree build.

Tomorrow I'll try to implement a new property, or look at the value of a variable, to make it possible to use the pure-CMake style (.project and .cproject in the generated-files directory) or the Eclipse-required style (.project and .cproject in the source directory).

Please try it and send your comments to the list or to me.

--
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
--- CMake.orig/Source/cmExtraEclipseCDT4Generator.cxx	2007-10-17 17:17:45.000000000 +0200
+++ CMake/Source/cmExtraEclipseCDT4Generator.cxx	2007-10-19 00:36:12.000000000 +0200
@@ -9,6 +9,7 @@
   Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
   Copyright (c) 2004 Alexander Neundorf [EMAIL PROTECTED], All rights reserved.
   Copyright (c) 2007 Miguel A. Figueroa-Villanueva. All rights reserved.
+  Copyright (c) 2007 Pau Garcia i Quiles, [EMAIL PROTECTED] All rights reserved.
   See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
 
      This software is distributed WITHOUT ANY WARRANTY; without even
@@ -86,7 +87,7 @@
 
   const std::string homeDirectory(mf->GetHomeDirectory());
   const std::string homeOutputDirectory(mf->GetHomeOutputDirectory());
-  const std::string filename = homeOutputDirectory + "/.project";
+  const std::string filename = homeDirectory + "/.project";
 
   cmGeneratedFileStream fout(filename.c_str());
   if (!fout)
@@ -94,10 +95,10 @@
     return;
     }
 
-  fout << 
+  fout <<
     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
     "<projectDescription>\n"
-    "\t<name>" << this->GetPathBasename(homeOutputDirectory) << "</name>\n"
+    "\t<name>" << this->GetPathBasename(homeDirectory) << "</name>\n"
     "\t<comment></comment>\n"
     "\t<projects>\n"
     "\t</projects>\n"
@@ -109,7 +110,7 @@
     ;
 
   // use clean target
-  fout << 
+  fout <<
     "\t\t\t\t<dictionary>\n"
     "\t\t\t\t\t<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>\n"
     "\t\t\t\t\t<value>clean</value>\n"
@@ -130,7 +131,7 @@
 
   // set the make command
   std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
-  fout << 
+  fout <<
     "\t\t\t\t<dictionary>\n"
     "\t\t\t\t\t<key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key>\n"
     "\t\t\t\t\t<value>true</value>\n"
@@ -275,25 +276,22 @@
   // create linked resources
   if (homeDirectory != homeOutputDirectory)
     {
+
+    std::map<cmStdString, std::vector<cmLocalGenerator*> > projectMap = this->GlobalGenerator->GetProjectMap();
+
     fout << "\t<linkedResources>\n";
     // for each sub project create a linked resource to the source dir
     // - only if it is an out-of-source build
-    for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
-          it = this->GlobalGenerator->GetProjectMap().begin();
-         it != this->GlobalGenerator->GetProjectMap().end();
-         ++it)
-      {
       fout <<
         "\t\t<link>\n"
-        "\t\t\t<name>" << it->first << "</name>\n"
+        "\t\t\t<name>" << this->GetPathBasename(homeOutputDirectory)<< "</name>\n"
         "\t\t\t<type>2</type>\n"
         "\t\t\t<location>"
-        << this->GetEclipsePath(
-             it->second[0]->GetMakefile()->GetStartDirectory())
+        <<
+        this->GetEclipsePath(projectMap[this->GetPathBasename(homeDirectory)][0]->GetMakefile()->GetStartOutputDirectory())
         << "</location>\n"
         "\t\t</link>\n"
         ;
-      }
     // for EXECUTABLE_OUTPUT_PATH when not in binary dir
     std::string output_path = mf->GetDefinition("EXECUTABLE_OUTPUT_PATH");
     if (!cmSystemTools::IsSubDirectory(output_path.c_str(),
@@ -349,12 +347,13 @@
 void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
 {
   std::set<std::string> emmited;
-  
+
   const cmMakefile* mf
     = this->GlobalGenerator->GetLocalGenerators()[0]->GetMakefile();
 
   const std::string homeOutputDirectory(mf->GetHomeOutputDirectory());
-  const std::string filename = homeOutputDirectory + "/.cproject";
+  const std::string homeDirectory(mf->GetHomeDirectory());
+  const std::string filename = homeDirectory + "/.cproject";
 
   cmGeneratedFileStream fout(filename.c_str());
   if (!fout)
@@ -363,7 +362,7 @@
     }
 
   // add header
-  fout << 
+  fout <<
     "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
     "<?fileVersion 4.0.0?>\n\n"
     "<cproject>\n"
@@ -373,7 +372,7 @@
   fout << "<cconfiguration id=\"org.eclipse.cdt.core.default.config.1\">\n";
 
   // Configuration settings...
-  fout << 
+  fout <<
     "<storageModule"
     " buildSystemId=\"org.eclipse.cdt.core.defaultConfigDataProvider\""
     " id=\"org.eclipse.cdt.core.default.config.1\""
@@ -437,9 +436,9 @@
   fout << "</extensions>\n"
           "</storageModule>\n"
           ;
-  
+
   // ???
-  fout << 
+  fout <<
     "<storageModule moduleId=\"org.eclipse.cdt.core.language.mapping\">\n"
     "<project-mappings/>\n"
     "</storageModule>\n"
@@ -456,10 +455,9 @@
   // - make it type 'src'
   // - and exclude it from type 'out'
   std::string exclude_from_out;
-  for (std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator
-        it = this->GlobalGenerator->GetProjectMap().begin();
-       it != this->GlobalGenerator->GetProjectMap().end();
-       ++it)
+  std::map<cmStdString, std::vector<cmLocalGenerator*> >::const_iterator it = this->GlobalGenerator->GetProjectMap().begin();
+  it++; // Skip first element
+  while ( it != this->GlobalGenerator->GetProjectMap().end() )
     {
     fout << "<pathentry kind=\"src\" path=\"" << it->first << "\"/>\n";
 
@@ -470,6 +468,7 @@
       {
       exclude_from_out += it->first + "/|";
       }
+    ++it;
     }
   exclude_from_out += "**/CMakeFiles/";
   fout << "<pathentry excluding=\"" << exclude_from_out
@@ -532,7 +531,7 @@
   fout << "</storageModule>\n";
 
   // add build targets
-  fout << 
+  fout <<
     "<storageModule moduleId=\"org.eclipse.cdt.make.core.buildtargets\">\n"
     "<buildTargets>\n"
     ;
@@ -665,7 +664,7 @@
 void cmExtraEclipseCDT4Generator
 ::AppendStorageScanners(cmGeneratedFileStream& fout)
 {
-  fout << 
+  fout <<
     "<storageModule moduleId=\"scannerConfiguration\">\n"
     "<autodiscovery enabled=\"true\" problemReportingEnabled=\"true\""
     " selectedProfileId="
@@ -689,7 +688,7 @@
                                                const std::string&     target,
                                                const std::string&     make)
 {
-  fout << 
+  fout <<
     "<target name=\"" << target << "\""
     " path=\"\""
     " targetID=\"org.eclipse.cdt.make.MakeTargetBuilder\">\n"
@@ -716,7 +715,7 @@
                        bool                   runActionUseDefault,
                        bool                   sipParserEnabled)
 {
-  fout << 
+  fout <<
     "<profile id=\"" << profileID << "\">\n"
     "<buildOutputProvider>\n"
     "<openAction enabled=\"" << (openActionEnabled ? "true" : "false")
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to