fixed vcproj files for modules which do not use pch
[reactos.git] / reactos / tools / rbuild / backend / msvc / vcprojmaker.cpp
index b84d0a0..534f600 100644 (file)
@@ -213,7 +213,10 @@ MSVCBackend::_generate_vcproj ( const Module& module )
        {\r
                std::string& cfg = cfgs[icfg];\r
 \r
-               bool debug = !strstr ( cfg.c_str(), "Release" );\r
+               bool debug = strstr ( cfg.c_str(), "Debug" );\r
+               bool speed = strstr ( cfg.c_str(), "Speed" );\r
+               bool release = (!debug && !speed );\r
+\r
                //bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );\r
 \r
                fprintf ( OUT, "\t\t<Configuration\r\n" );\r
@@ -225,7 +228,7 @@ MSVCBackend::_generate_vcproj ( const Module& module )
 \r
                fprintf ( OUT, "\t\t\t<Tool\r\n" );\r
                fprintf ( OUT, "\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tOptimization=\"%d\"\r\n", debug ? 0 : 2 );\r
+               fprintf ( OUT, "\t\t\t\tOptimization=\"%d\"\r\n", release ? 2 : 0 );\r
 \r
                fprintf ( OUT, "\t\t\t\tAdditionalIncludeDirectories=\"" );\r
                bool multiple_includes = false;\r
@@ -248,28 +251,20 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                if ( debug )\r
                {\r
                        defines.push_back ( "_DEBUG" );\r
-                       if ( lib || exe )\r
-                       {\r
-                               defines.push_back ( "_LIB" );\r
-                       }\r
-                       else\r
-                       {\r
-                               defines.push_back ( "_WINDOWS" );\r
-                               defines.push_back ( "_USRDLL" );\r
-                       }\r
                }\r
                else\r
                {\r
                        defines.push_back ( "NDEBUG" );\r
-                       if ( lib || exe )\r
-                       {\r
-                               defines.push_back ( "_LIB" );\r
-                       }\r
-                       else\r
-                       {\r
-                               defines.push_back ( "_WINDOWS" );\r
-                               defines.push_back ( "_USRDLL" );\r
-                       }\r
+               }\r
+\r
+               if ( lib || exe )\r
+               {\r
+                       defines.push_back ( "_LIB" );\r
+               }\r
+               else\r
+               {\r
+                       defines.push_back ( "_WINDOWS" );\r
+                       defines.push_back ( "_USRDLL" );\r
                }\r
 \r
                fprintf ( OUT, "\t\t\t\tPreprocessorDefinitions=\"" );\r
@@ -283,15 +278,37 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                }\r
                fprintf ( OUT, "\"\r\n" );\r
 \r
-               fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"TRUE\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"3\"\r\n" );\r
+               fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );\r
+               fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"%s\"\r\n", debug ? "3" : "0" );\r
                fprintf ( OUT, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );\r
                fprintf ( OUT, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );\r
                fprintf ( OUT, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );\r
-               fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tWarningLevel=\"1\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"TRUE\"\r\n" );\r
-               fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"4\"/>\r\n" );\r
+               \r
+               if ( module.pch != NULL )\r
+               {\r
+                       fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"2\"\r\n" );\r
+                       string pch_path = Path::RelativeFromDirectory (\r
+                               module.pch->file.name,\r
+                               module.GetBasePath() );\r
+                       fprintf ( OUT, "\t\t\t\tPrecompiledHeaderThrough=\"%s\"\r\n", pch_path.c_str() );\r
+               }\r
+               else\r
+               {\r
+                       fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );\r
+               }\r
+\r
+               fprintf ( OUT, "\t\t\t\tWholeProgramOptimization=\"%s\"\r\n", release ? "TRUE" : "FALSE");\r
+               if ( release )\r
+               {\r
+                       fprintf ( OUT, "\t\t\t\tFavorSizeOrSpeed=\"1\"\r\n" );\r
+                       fprintf ( OUT, "\t\t\t\tStringPooling=\"true\"\r\n" );\r
+               }\r
+\r
+               fprintf ( OUT, "\t\t\t\tEnablePREfast=\"%s\"\r\n", debug ? "TRUE" : "FALSE");\r
+               fprintf ( OUT, "\t\t\t\tDisableSpecificWarnings=\"4201;4127\"\r\n" );\r
+               fprintf ( OUT, "\t\t\t\tWarningLevel=\"%s\"\r\n", release ? "0" : "4" );\r
+               fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"%s\"\r\n", release ? "FALSE" : "TRUE");\r
+               fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"%s\"/>\r\n", speed ? "0" : "4");\r
 \r
                fprintf ( OUT, "\t\t\t<Tool\r\n" );\r
                fprintf ( OUT, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );\r
@@ -318,33 +335,40 @@ MSVCBackend::_generate_vcproj ( const Module& module )
 \r
                        fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s%s\"\r\n", module.name.c_str(), module_type.c_str() );\r
                        fprintf ( OUT, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug ? 2 : 1 );\r
-                       fprintf ( OUT, "\t\t\t\tGenerateDebugInformation=\"TRUE\"\r\n" );\r
+                       fprintf ( OUT, "\t\t\t\tGenerateDebugInformation=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );\r
 \r
                        if ( debug )\r
                                fprintf ( OUT, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module.name.c_str() );\r
 \r
                        if ( sys )\r
                        {\r
-                               fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /DRIVER /ALIGN:0x20 /subsystem:NATIVE /SECTION:INIT,D /FORCE:MULTIPLE /IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096\"\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /DRIVER /ALIGN:0x20 /SUBSYSTEM:NATIVE /SECTION:INIT,D /NODEFAULTLIB /IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096\"\r\n" );\r
                                fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );\r
                                fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint == "" ? "DriverEntry" : module.entrypoint.c_str ());\r
                                fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress == "" ? "0x10000" : module.baseaddress.c_str ());   \r
                        }\r
                        else if ( exe )\r
                        {\r
-                               if ( module.type == Kernel || module.type == NativeCUI)\r
+                               if ( module.type == Kernel )\r
                                {\r
-                                       fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /SECTION:INIT,D /ALIGN:4096 /FORCE:MULTIPLE\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /NODEFAULTLIB /SECTION:INIT,D /ALIGN:0x80\"\r\n" );\r
                                        fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );\r
-                                       fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint.c_str ());\r
+                                       fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"KiSystemStartup\"\r\n" );\r
                                        fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress.c_str ());  \r
                                }\r
+                               else if ( module.type == NativeCUI )\r
+                               {\r
+                                       fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /NODEFAULTLIB /ALIGN:0x20\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"NtProcessStartup\"\r\n" );\r
+                                       fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress.c_str ());  \r
+                               }\r
                                else if ( module.type == Win32CUI || module.type == Win32GUI )\r
                                {\r
                                        fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", console ? 1 : 2 );\r
                                }\r
                        }\r
-                       else if ( dll)\r
+                       else if ( dll )\r
                        {\r
                                fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint == "" ? "DllMain" : module.entrypoint.c_str ());\r
                                fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress == "" ? "0x40000" : module.baseaddress.c_str ());\r
@@ -400,11 +424,24 @@ MSVCBackend::_generate_vcproj ( const Module& module )
                fprintf ( OUT, "\t\t\t<File\r\n" );\r
                fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file.c_str() );\r
 \r
-               if (configuration.VSProjectVersion < "8.00") {\r
-                       for ( size_t iconfig = 0; iconfig < cfgs.size(); iconfig++ )\r
+               for ( size_t iconfig = 0; iconfig < cfgs.size(); iconfig++ )\r
+               {\r
+                       std::string& config = cfgs[iconfig];\r
+\r
+                       if (( isrcfile == 0 ) && ( module.pch != NULL ))\r
                        {\r
-                               std::string& config = cfgs[iconfig];\r
+                               /* little hack to speed up PCH */\r
+                               fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t\tName=\"" );\r
+                               fprintf ( OUT, config.c_str() );\r
+                               fprintf ( OUT, "|Win32\">\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\r\n" );\r
+                               fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );\r
+                       }\r
 \r
+                       if (configuration.VSProjectVersion < "8.00") {\r
                                if ((source_file.find(".idl") != string::npos) || ((source_file.find(".asm") != string::npos || tolower(source_file.at(source_file.size() - 1)) == 's')))\r
                                {\r
                                        fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );\r