diff --git a/reactos/tools/rbuild/backend/mingw/mingw.cpp b/reactos/tools/rbuild/backend/mingw/mingw.cpp index 0a17635d189..d4fb41e793c 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.cpp +++ b/reactos/tools/rbuild/backend/mingw/mingw.cpp @@ -89,6 +89,42 @@ MingwBackend::AddDirectoryTarget ( const string& directory, return directoryTree->name; } +bool +MingwBackend::CanEnablePreCompiledHeaderSupportForModule ( const Module& module ) +{ + if ( !configuration.CompilationUnitsEnabled ) + return true; + + const vector& compilationUnits = module.non_if_data.compilationUnits; + size_t i; + for ( i = 0; i < compilationUnits.size (); i++ ) + { + CompilationUnit& compilationUnit = *compilationUnits[i]; + if ( compilationUnit.files.size () != 1 ) + return false; + } + // intentionally make a copy so that we can append more work in + // the middle of processing without having to go recursive + vector v = module.non_if_data.ifs; + for ( i = 0; i < v.size (); i++ ) + { + size_t j; + If& rIf = *v[i]; + // check for sub-ifs to add to list + const vector& ifs = rIf.data.ifs; + for ( j = 0; j < ifs.size (); j++ ) + v.push_back ( ifs[j] ); + const vector& compilationUnits = rIf.data.compilationUnits; + for ( j = 0; j < compilationUnits.size (); j++ ) + { + CompilationUnit& compilationUnit = *compilationUnits[j]; + if ( compilationUnit.files.size () != 1 ) + return false; + } + } + return true; +} + void MingwBackend::ProcessModules () { @@ -104,6 +140,8 @@ MingwBackend::ProcessModules () MingwModuleHandler* h = MingwModuleHandler::InstanciateHandler ( module, this ); + if ( use_pch && CanEnablePreCompiledHeaderSupportForModule ( module ) ) + h->EnablePreCompiledHeaderSupport (); if ( module.host == HostDefault ) { module.host = h->DefaultHost(); @@ -207,7 +245,6 @@ MingwBackend::CreateMakefile () throw AccessDeniedException ( ProjectNode.makefile ); MingwModuleHandler::SetBackend ( this ); MingwModuleHandler::SetMakefile ( fMakefile ); - MingwModuleHandler::SetUsePch ( use_pch ); } void diff --git a/reactos/tools/rbuild/backend/mingw/mingw.h b/reactos/tools/rbuild/backend/mingw/mingw.h index a4237044013..45db183d5f9 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.h +++ b/reactos/tools/rbuild/backend/mingw/mingw.h @@ -92,6 +92,7 @@ private: void DetectNetwideAssembler (); void DetectPipeSupport (); void DetectPCHSupport (); + bool CanEnablePreCompiledHeaderSupportForModule ( const Module& module ); void ProcessModules (); void CheckAutomaticDependenciesForModuleOnly (); void ProcessNormal (); diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index a4b3e6fc900..1ae557ed391 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -32,8 +32,6 @@ MingwBackend* MingwModuleHandler::backend = NULL; FILE* MingwModuleHandler::fMakefile = NULL; -bool -MingwModuleHandler::use_pch = false; string PrefixFilename ( @@ -73,6 +71,7 @@ MingwModuleHandler::MingwModuleHandler ( : module(module_) { + use_pch = false; } MingwModuleHandler::~MingwModuleHandler() @@ -91,10 +90,10 @@ MingwModuleHandler::SetMakefile ( FILE* f ) fMakefile = f; } -/*static*/ void -MingwModuleHandler::SetUsePch ( bool b ) +void +MingwModuleHandler::EnablePreCompiledHeaderSupport () { - use_pch = b; + use_pch = true; } /* static*/ string diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.h b/reactos/tools/rbuild/backend/mingw/modulehandler.h index 9bc19e5306f..e911799f906 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.h +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.h @@ -39,7 +39,7 @@ public: static void SetBackend ( MingwBackend* backend_ ); static void SetMakefile ( FILE* f ); - static void SetUsePch ( bool use_pch ); + void EnablePreCompiledHeaderSupport (); static std::string PassThruCacheDirectory ( const std::string &f, @@ -125,7 +125,7 @@ protected: std::string GetLinkingDependencies () const; static MingwBackend* backend; static FILE* fMakefile; - static bool use_pch; + bool use_pch; private: std::string ConcatenatePaths ( const std::string& path1, const std::string& path2 ) const; diff --git a/reactos/tools/rbuild/compilationunitsupportcode.cpp b/reactos/tools/rbuild/compilationunitsupportcode.cpp index 7bb8cd805c1..1c208f06031 100644 --- a/reactos/tools/rbuild/compilationunitsupportcode.cpp +++ b/reactos/tools/rbuild/compilationunitsupportcode.cpp @@ -82,8 +82,6 @@ CompilationUnitSupportCode::WriteCompilationUnitFile ( Module& module, s = buf; s = s + sprintf ( s, "/* This file is automatically generated. */\n" ); s = s + sprintf ( s, "#define ONE_COMPILATION_UNIT\n" ); - if ( module.pch ) - s = s + sprintf ( s, "#include <%s>\n", ChangeSeparator ( module.pch->file.name, '\\', '/' ).c_str () ); for ( size_t i = 0; i < compilationUnit.files.size () ; i++ ) {