@@ -363,6 +363,31 @@ function pluginSdkStaticLibProject(projectName, sdkdir, outName, isPluginProject
363363 [" " ] = (projectFile (projectPath , " plugin*.h" ))
364364 }
365365 end
366+
367+ -- precompiled header
368+ if msbuild and (projectName == " plugin_iii" or projectName == " plugin_vc" or projectName == " plugin_sa" ) then
369+ pchheader " stdafx.h"
370+ forceincludes " stdafx.h"
371+ pchsource (path .getrelative (path .getabsolute (" ." ), sdkdir .. " /shared/stdafx.cpp" ))
372+
373+ filter " files:**stdafx.cpp"
374+ defines " USE_PCH"
375+
376+ local projDir = path .getrelative (path .getabsolute (" ." ), sdkdir .. " /" .. projectName )
377+ local gameFiles = projDir .. " /" .. gameName .. " /**"
378+ local attractorFiles = projDir .. " /game_vc/CPed*Attractor*" -- files using _HAS_ITERATOR_DEBUGGING macro
379+
380+ filter { " files:" .. gameFiles , " files:not " .. attractorFiles }
381+ defines " USE_PCH"
382+
383+ filter (" files:not " .. gameFiles )
384+ flags " NoPCH"
385+
386+ filter (" files:" .. attractorFiles )
387+ flags " NoPCH"
388+
389+ filter {}
390+ end
366391 else
367392 location (projectPath )
368393 files {
@@ -543,6 +568,73 @@ xcopy /Y \"$(TargetPath)\" \"$(GTA_" .. gameAbbr .. "_DIR)\" \r\n\
543568 debugdir (" $(GTA_" .. gameAbbr .. " _DIR)" )
544569end
545570
571+ function generatePrecompiledHeader (directory , create )
572+ local headerFilename = path .join (directory , " stdafx.h" )
573+ local sourceFilename = path .join (directory , " stdafx.cpp" )
574+
575+ -- remove old files
576+ os.remove (headerFilename )
577+ os.remove (sourceFilename )
578+
579+ if create == false then
580+ return
581+ end
582+
583+ print (" Generating precompiled header files..." )
584+
585+ -- generate stdafx.h
586+ local header = " // This file was generated by Premake\n " ;
587+
588+ local templateFile = io.open (" stdafx_template.h" , " r" )
589+ header = header .. templateFile :read (" *all" )
590+ templateFile :close ()
591+
592+ -- gather include files
593+ local fileList = {}
594+ function collect (dir , excludes )
595+ local f = os .matchfiles (sdkdir .. " \\ " .. dir .. " \\ **.h*" )
596+ for i = 1 , # f do
597+ local p = path .getrelative (directory , f [i ]):gsub (" /" , " \\ " )
598+
599+ local excluded = false
600+ for j = 1 , # excludes do
601+ if string.find (p , excludes [j ]) then
602+ excluded = true
603+ break
604+ end
605+ end
606+
607+ if excluded == false then
608+ fileList [# fileList + 1 ] = p
609+ end
610+ end
611+ end
612+ collect (" hooking" , {})
613+ collect (" injector" , {" \\ gvm\\ " })
614+ collect (" modutils" , {})
615+ collect (" safetyhook" , {})
616+ collect (" shared" , {" dxsdk\\ " ," rwd3d9.h" })
617+ collect (" stb" , {})
618+ table.sort (fileList )
619+
620+ local includesList = " "
621+ for i = 1 , # fileList do
622+ if i > 1 then includesList = includesList .. ' \n ' end
623+ includesList = includesList .. ' #include "' .. fileList [i ] .. ' "'
624+ end
625+ header = header :gsub (" GENERATED_LIST" , includesList );
626+
627+ -- stdafx.h file
628+ local file = io.open (headerFilename , ' w' )
629+ file :write (header )
630+ file :close ()
631+
632+ -- stdafx.cpp file
633+ file = io.open (sourceFilename , ' w' )
634+ file :write (' #include "stdafx.h"\n ' )
635+ file :close ()
636+ end
637+
546638function pluginSdkExampleProject (projectDir , projectName , projectType , game2 , game3 , gameVc , gameSa , game4 , d3dSupport , laSupport , additionalIncludeDirs , additionalLibraryDirs , additionalLibraries , additionalDefinitions )
547639 local supportedGames = {}
548640 local gameCounter = 1
0 commit comments