PCH support
authorRoyce Mitchell III <royce3@ev1.net>
Thu, 10 Mar 2005 14:05:41 +0000 (14:05 +0000)
committerRoyce Mitchell III <royce3@ev1.net>
Thu, 10 Mar 2005 14:05:41 +0000 (14:05 +0000)
svn path=/branches/xmlbuildsystem/; revision=13908

reactos/tools/rbuild/backend/mingw/mingw.cpp
reactos/tools/rbuild/backend/mingw/modulehandler.cpp
reactos/tools/rbuild/backend/mingw/modulehandler.h
reactos/tools/rbuild/module.cpp
reactos/tools/rbuild/rbuild.h

index a5511c4..d5b5b1a 100644 (file)
@@ -50,6 +50,7 @@ MingwBackend::CreateMakefile ()
        if ( !fMakefile )\r
                throw AccessDeniedException ( ProjectNode.makefile );\r
        MingwModuleHandler::SetMakefile ( fMakefile );\r
+       MingwModuleHandler::SetUsePch ( use_pch );\r
 }\r
 \r
 void\r
index 1af28f8..25e2de9 100644 (file)
@@ -23,6 +23,8 @@ MingwModuleHandler::ref = 0;
 \r
 FILE*\r
 MingwModuleHandler::fMakefile = NULL;\r
+bool\r
+MingwModuleHandler::use_pch = false;\r
 \r
 string\r
 ReplaceExtension ( const string& filename,\r
@@ -67,6 +69,12 @@ MingwModuleHandler::SetMakefile ( FILE* f )
        fMakefile = f;\r
 }\r
 \r
+void\r
+MingwModuleHandler::SetUsePch ( bool b )\r
+{\r
+       use_pch = b;\r
+}\r
+\r
 MingwModuleHandler*\r
 MingwModuleHandler::LookupHandler ( const string& location,\r
                                     ModuleType moduletype )\r
@@ -710,11 +718,14 @@ MingwModuleHandler::GenerateGccCommand ( const Module& module,
                                          const string& cc,\r
                                          const string& cflagsMacro ) const\r
 {\r
+       string deps = sourceFilename;\r
+       if ( module.pch && use_pch )\r
+               deps += " " + module.pch->header + ".gch";\r
        string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );\r
        fprintf ( fMakefile,\r
                  "%s: %s\n",\r
                  objectFilename.c_str (),\r
-                 sourceFilename.c_str () );\r
+                 deps.c_str () );\r
        fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [CC]      $<\n" );\r
        fprintf ( fMakefile,\r
                 "\t%s -c %s -o %s %s\n",\r
@@ -1045,6 +1056,26 @@ MingwModuleHandler::GenerateObjectFileTargets (
        const string& windresflagsMacro,\r
        string_list& clean_files ) const\r
 {\r
+       if ( module.pch && use_pch )\r
+       {\r
+               const string& pch_file = module.pch->header;\r
+               string gch_file = pch_file + ".gch";\r
+               CLEAN_FILE(gch_file);\r
+               fprintf (\r
+                       fMakefile,\r
+                       "%s: %s\n",\r
+                       gch_file.c_str(),\r
+                       pch_file.c_str() );\r
+               fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [PCH]     $@\n" );\r
+               fprintf (\r
+                       fMakefile,\r
+                       "\t%s -c %s -o %s %s\n\n",\r
+                       cc.c_str(),\r
+                       pch_file.c_str(),\r
+                       gch_file.c_str(),\r
+                       cflagsMacro.c_str() );\r
+       }\r
+\r
        GenerateObjectFileTargets ( module,\r
                                    module.non_if_data,\r
                                    cc,\r
@@ -1425,6 +1456,8 @@ MingwModuleHandler::GetDefinitionDependencies ( const Module& module ) const
        return dependencies;\r
 }\r
 \r
+// TODO FIXME - check for C++ extensions when parsing XML, and set a\r
+// bool in the Module class\r
 bool\r
 MingwModuleHandler::IsCPlusPlusModule ( const Module& module ) const\r
 {\r
index 3ce812c..7995c58 100644 (file)
@@ -5,7 +5,7 @@
 \r
 extern std::string\r
 ReplaceExtension ( const std::string& filename,\r
-                      const std::string& newExtension );\r
+                   const std::string& newExtension );\r
 \r
 \r
 class MingwModuleHandler\r
@@ -20,6 +20,7 @@ public:
        virtual ~MingwModuleHandler();\r
 \r
        static void SetMakefile ( FILE* f );\r
+       static void SetUsePch ( bool use_pch );\r
        static MingwModuleHandler* LookupHandler ( const std::string& location,\r
                                                   ModuleType moduletype_ );\r
        virtual void Process ( const Module& module, string_list& clean_files ) = 0;\r
@@ -73,6 +74,7 @@ protected:
        std::string GetLinkingDependencies ( const Module& module ) const;\r
        bool IsCPlusPlusModule ( const Module& module ) const;\r
        static FILE* fMakefile;\r
+       static bool use_pch;\r
        static std::set<std::string> directory_set;\r
 private:\r
        std::string ConcatenatePaths ( const std::string& path1,\r
index 7033181..2425f1d 100644 (file)
@@ -90,7 +90,8 @@ Module::Module ( const Project& project,
        : project (project),\r
          node (moduleNode),\r
          importLibrary (NULL),\r
-         bootstrap (NULL)\r
+         bootstrap (NULL),\r
+         pch (NULL)\r
 {\r
        if ( node.name != "module" )\r
                throw Exception ( "internal tool error: Module created with non-<module> node" );\r
@@ -141,6 +142,8 @@ Module::~Module ()
                delete compilerFlags[i];\r
        for ( i = 0; i < linkerFlags.size(); i++ )\r
                delete linkerFlags[i];\r
+       if ( pch )\r
+               delete pch;\r
 }\r
 \r
 void\r
@@ -158,6 +161,8 @@ Module::ProcessXML()
        for ( i = 0; i < linkerFlags.size(); i++ )\r
                linkerFlags[i]->ProcessXML();\r
        non_if_data.ProcessXML();\r
+       if ( pch )\r
+               pch->ProcessXML();\r
 }\r
 \r
 void\r
@@ -282,6 +287,20 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
                bootstrap = new Bootstrap ( project, this, e );\r
                subs_invalid = true;\r
        }\r
+       else if ( e.name == "pch" )\r
+       {\r
+               if ( pIf )\r
+                       throw InvalidBuildFileException (\r
+                               e.location,\r
+                               "<pch> is not a valid sub-element of <if>" );\r
+               if ( pch )\r
+                       throw InvalidBuildFileException (\r
+                               e.location,\r
+                               "Only one <pch> is valid per module" );\r
+               pch = new PchFile (\r
+                       e, *this, FixSeparator ( path + CSEP + e.value ) );\r
+               subs_invalid = true;\r
+       }\r
        if ( subs_invalid && e.subElements.size() > 0 )\r
                throw InvalidBuildFileException (\r
                        e.location,\r
@@ -806,3 +825,17 @@ void
 Property::ProcessXML()\r
 {\r
 }\r
+\r
+\r
+PchFile::PchFile (\r
+       const XMLElement& node_,\r
+       const Module& module_,\r
+       const string& header_ )\r
+       : node(node_), module(module_), header(header_)\r
+{\r
+}\r
+\r
+void\r
+PchFile::ProcessXML()\r
+{\r
+}\r
index 3750535..08112e8 100644 (file)
@@ -54,6 +54,7 @@ class Property;
 class AutomaticDependency;\r
 class Bootstrap;\r
 class CDFile;\r
+class PchFile;\r
 \r
 class SourceFileTest;\r
 \r
@@ -150,6 +151,7 @@ public:
        std::vector<Dependency*> dependencies;\r
        std::vector<CompilerFlag*> compilerFlags;\r
        std::vector<LinkerFlag*> linkerFlags;\r
+       PchFile* pch;\r
 \r
        Module ( const Project& project,\r
                 const XMLElement& moduleNode,\r
@@ -499,6 +501,21 @@ public:
 };\r
 \r
 \r
+class PchFile\r
+{\r
+public:\r
+       const XMLElement& node;\r
+       const Module& module;\r
+       std::string header;\r
+\r
+       PchFile (\r
+               const XMLElement& node,\r
+               const Module& module,\r
+               const std::string& header );\r
+       void ProcessXML();\r
+};\r
+\r
+\r
 extern std::string\r
 FixSeparator ( const std::string& s );\r
 \r