Hi,

Von: Brad King <[EMAIL PROTECTED]>

> Alexander Neundorf wrote:
> > -------- Original-Nachricht --------
> > Von: Brad King <[EMAIL PROTECTED]>
> > 
> >> Alexander Neundorf wrote:
> >>> Hi,
> >>>
> >>> it would be nice if it would be possible to have for each object file
> >> also a target which only preprocesses the file and one which
> >> preprocesses and compiles, but not assembles the file (so that you get
> >> the assembler code).
> >>> Is there a way to do this with macros ? 
> >>> I almost think this would have to be done in cmake itself. Probably
> >> somewhere where the object rules are created additionally for each
> object the
> >> same rule but with "-E" instead of "-c" would have to be created. It
> >> wouldn't be required to be executed on all, just on direct invocation:
> >>> make foo.o/pre
> >>> make foo.o/as
> >>>
> >>>
> >>> What do you think about this ?
> >>> Would you accept a patch ?
> >> Look in Modules/CMakeCInformation.cmake for the variable 
> >> CMAKE_C_COMPILE_OBJECT.  Other modules in the Platform directory set it
> >> also.  Just duplicate the variable with one called 
> >> CMAKE_C_PREPROCESS_OBJECT and then setup 
> >> cmLocalUnixMakefileGenerator3.cxx to create rules with ".E" extensions 
> >> instead of ".o".  You should be able to locate places that lookup 
> >> *_COMPILE_OBJECT vars.  See Modules/CMakeCXXInformation.cmake for the 
> >> C++ version.
> > 
> > Ok, yesterday I had a look at it and managed to get the rules for
> preprocessed files produced.
> > It ended up in cmMakefileTargetGenerator::WriteObjectBuildFile().
> > Problem: the rule was created in
> builddir/CMakeFiles/target.dir/build.make, but not in builddir/Makefile, so I 
> had to enter "make -f
> CMakeFiles/target.dir/build.make main.o.E".
> > What do I have to do to have this rule also appear in the Makefile in
> the build dir ?
> 
> There are "convenience" targets written to the builddir/Makefile for
> each object file in that directory with a rule to just invoke the
> appropriate build.make copy of the rule.  You'll have to locate the code
> that does this and add one for the .E files also.

Attached is a first try of a patch against 2.4 branch.
It introduces two new variables CMAKE_CREATE_PREPROCESS_RULES and 
CMAKE_CREATE_ASSEMBLE_RULES. I think especially the name 
CMAKE_CREATE_ASSEMBLE_RULES is not good (since actually everything except 
assembling is done).
The created files are named foo.o.E and foo.o.S (was easier than to replace the 
suffix.
I know only the compiler switches for gcc, so I added them only in gcc.cmake.

What do you think ?

Bye
Alex


-- 


"Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
Index: Modules/Platform/gcc.cmake
===================================================================
RCS file: /cvsroot/CMake/CMake/Modules/Platform/gcc.cmake,v
retrieving revision 1.10
diff -b -u -p -r1.10 gcc.cmake
--- Modules/Platform/gcc.cmake	1 Jun 2004 18:08:04 -0000	1.10
+++ Modules/Platform/gcc.cmake	15 Jul 2006 21:10:01 -0000
@@ -4,6 +4,9 @@ IF(CMAKE_COMPILER_IS_GNUCC)
   SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
   SET (CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
   SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
+  SET (CMAKE_C_PREPROCESS_FILE   "<CMAKE_C_COMPILER>  <FLAGS> -o <OBJECT> -E <SOURCE>")
+  SET (CMAKE_C_ASSEMBLE_FILE   "<CMAKE_C_COMPILER>  <FLAGS> -o <OBJECT> -S <SOURCE>")
+
 ENDIF(CMAKE_COMPILER_IS_GNUCC)
 
 IF(CMAKE_COMPILER_IS_GNUCXX)
@@ -12,5 +15,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
   SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
   SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
   SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
+  SET (CMAKE_CXX_PREPROCESS_FILE   "<CMAKE_CXX_COMPILER>  <FLAGS> -o <OBJECT> -E <SOURCE>")
+  SET (CMAKE_CXX_ASSEMBLE_FILE   "<CMAKE_CXX_COMPILER>  <FLAGS> -o <OBJECT> -S <SOURCE>")
 ENDIF(CMAKE_COMPILER_IS_GNUCXX)
 
Index: Source/cmLocalUnixMakefileGenerator3.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalUnixMakefileGenerator3.cxx,v
retrieving revision 1.128.2.6
diff -b -u -p -r1.128.2.6 cmLocalUnixMakefileGenerator3.cxx
--- Source/cmLocalUnixMakefileGenerator3.cxx	30 Jun 2006 17:48:43 -0000	1.128.2.6
+++ Source/cmLocalUnixMakefileGenerator3.cxx	15 Jul 2006 21:10:02 -0000
@@ -172,6 +172,33 @@ void cmLocalUnixMakefileGenerator3::Form
     }
 }
 
+void cmLocalUnixMakefileGenerator3::WriteObjectRule(cmGeneratedFileStream& ruleFileStream, std::string currentObjectName, std::vector<cmTarget *>& targets, const char* comment)
+{
+  std::vector<std::string> depends;
+  std::vector<std::string> commands;
+
+  // for each target using the object file
+  for (std::vector<cmTarget *>::iterator to = 
+       targets.begin(); to != targets.end(); ++to)
+  {
+    std::string tgtMakefileName = this->GetRelativeTargetDirectory(**to);
+    std::string targetName = tgtMakefileName;
+
+    tgtMakefileName += "/build.make";
+    targetName += "/";
+    targetName += currentObjectName.c_str();
+    commands.push_back(this->GetRecursiveMakeCall
+                       (tgtMakefileName.c_str(),targetName.c_str()));  
+    this->CreateCDCommand(commands,
+                          this->Makefile->GetHomeOutputDirectory(),
+                          this->Makefile->GetStartOutputDirectory());
+  }
+  this->WriteMakeRule(ruleFileStream, 
+                      comment, 
+                       currentObjectName.c_str(), depends, commands, false);
+}
+
+
 //----------------------------------------------------------------------------
 void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
 {
@@ -211,34 +238,19 @@ void cmLocalUnixMakefileGenerator3::Writ
     gg->WriteConvenienceRules(ruleFileStream,emittedTargets);
     }
   
-  std::vector<std::string> depends;
-  std::vector<std::string> commands;
-
   // now write out the object rules
   // for each object file name
   for (std::map<cmStdString,std::vector<cmTarget *> >::iterator lo = 
          this->LocalObjectFiles.begin();
        lo != this->LocalObjectFiles.end(); ++lo)
     {
-    commands.clear();
-    // for each target using the object file
-    for (std::vector<cmTarget *>::iterator to = 
-           lo->second.begin(); to != lo->second.end(); ++to)
-      {
-      std::string tgtMakefileName = this->GetRelativeTargetDirectory(**to);
-      std::string targetName = tgtMakefileName;
-      tgtMakefileName += "/build.make";
-      targetName += "/";
-      targetName += lo->first.c_str();
-      commands.push_back(this->GetRecursiveMakeCall
-                         (tgtMakefileName.c_str(),targetName.c_str()));  
-      this->CreateCDCommand(commands,
-                                    this->Makefile->GetHomeOutputDirectory(),
-                                    this->Makefile->GetStartOutputDirectory());
-      }
-    this->WriteMakeRule(ruleFileStream, 
-                        "target for object file", 
-                        lo->first.c_str(), depends, commands, false);
+
+      this->WriteObjectRule(ruleFileStream, lo->first, lo->second, "target for object file");
+      if(this->Makefile->IsOn("CMAKE_CREATE_PREPROCESS_RULES")) 
+        this->WriteObjectRule(ruleFileStream, lo->first+".E", lo->second, "target for preprocessed files");
+      if(this->Makefile->IsOn("CMAKE_CREATE_ASSEMBLE_RULES")) 
+        this->WriteObjectRule(ruleFileStream, lo->first+".S", lo->second, "target for assembled files");
+
     }
 
   // add a help target as long as there isn;t a real target named help
Index: Source/cmLocalUnixMakefileGenerator3.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalUnixMakefileGenerator3.h,v
retrieving revision 1.45.2.1
diff -b -u -p -r1.45.2.1 cmLocalUnixMakefileGenerator3.h
--- Source/cmLocalUnixMakefileGenerator3.h	30 Jun 2006 17:48:45 -0000	1.45.2.1
+++ Source/cmLocalUnixMakefileGenerator3.h	15 Jul 2006 21:10:02 -0000
@@ -26,6 +26,7 @@ class cmMakeDepend;
 class cmMakefileTargetGenerator;
 class cmTarget;
 class cmSourceFile;
+class cmGeneratedFileStream;
 
 /** \class cmLocalUnixMakefileGenerator3
  * \brief Write a LocalUnix makefiles.
@@ -215,6 +216,7 @@ protected:
   void FormatOutputPath(std::string& path, const char* name);
 
   void WriteLocalMakefile();
+  void WriteObjectRule(cmGeneratedFileStream& ruleFileStream, std::string currentObjectName, std::vector<cmTarget *>& targets, const char* comment);
   
   // write the target rules for the local Makefile into the stream
   void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
Index: Source/cmMakefileTargetGenerator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefileTargetGenerator.cxx,v
retrieving revision 1.16.2.5
diff -b -u -p -r1.16.2.5 cmMakefileTargetGenerator.cxx
--- Source/cmMakefileTargetGenerator.cxx	30 Jun 2006 17:48:46 -0000	1.16.2.5
+++ Source/cmMakefileTargetGenerator.cxx	15 Jul 2006 21:10:05 -0000
@@ -475,6 +475,69 @@ cmMakefileTargetGenerator
                                       relativeObj.c_str(),
                                       depends, commands, false);
 
+//////////  
+  if(this->Makefile->IsOn("CMAKE_CREATE_PREPROCESS_RULES")) 
+  {
+      std::vector<std::string> noDepends;
+      std::string relativePreprocessedFiles = relativeObj;
+      relativePreprocessedFiles+=".E";
+
+      std::vector<std::string> prepCommands;
+
+      std::string prepRuleVar = "CMAKE_";
+      prepRuleVar += lang;
+      prepRuleVar += "_PREPROCESS_FILE";
+      if (this->Makefile->GetDefinition(prepRuleVar.c_str()))
+      {
+         std::string prepRule = this->Makefile->GetDefinition(prepRuleVar.c_str());
+         cmSystemTools::ExpandListArgument(prepRule, prepCommands);
+
+         vars.Object = relativePreprocessedFiles.c_str();
+  
+         // Expand placeholders in the commands.
+         for(std::vector<std::string>::iterator i = prepCommands.begin();
+             i != prepCommands.end(); ++i)
+         {
+            this->LocalGenerator->ExpandRuleVariables(*i, vars);
+         }
+
+          this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+                                              relativePreprocessedFiles.c_str(),
+                                              noDepends, prepCommands, false);
+      }
+  }
+
+  if(this->Makefile->IsOn("CMAKE_CREATE_ASSEMBLE_RULES")) 
+  {
+      std::vector<std::string> noDepends;
+      std::string relativeAssembledFiles = relativeObj;
+      relativeAssembledFiles+=".S";
+
+      std::vector<std::string> prepCommands;
+
+      std::string prepRuleVar = "CMAKE_";
+      prepRuleVar += lang;
+      prepRuleVar += "_ASSEMBLE_FILE";
+      if (this->Makefile->GetDefinition(prepRuleVar.c_str()))
+      {
+         std::string prepRule = this->Makefile->GetDefinition(prepRuleVar.c_str());
+         cmSystemTools::ExpandListArgument(prepRule, prepCommands);
+
+         vars.Object = relativeAssembledFiles.c_str();
+  
+         // Expand placeholders in the commands.
+         for(std::vector<std::string>::iterator i = prepCommands.begin();
+             i != prepCommands.end(); ++i)
+         {
+            this->LocalGenerator->ExpandRuleVariables(*i, vars);
+         }
+
+          this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
+                                              relativeAssembledFiles.c_str(),
+                                              noDepends, prepCommands, false);
+      }
+  }
+
   // If the language needs provides-requires mode, create the
   // corresponding targets.
   std::string objectRequires = relativeObj;
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to