Skip to content

Commit 752e90b

Browse files
Merge pull request DK22Pac#240 from cleolibrary/precompiled_headers
Introduced precompiled header
2 parents 024bb32 + f8d0a73 commit 752e90b

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,4 +495,6 @@ user.settings
495495
*.workspace
496496
*.mk
497497

498-
tools/plugin-sdk-funcs-gen/funcs_conv.h
498+
tools/plugin-sdk-funcs-gen/funcs_conv.h
499+
/shared/stdafx.cpp
500+
/shared/stdafx.h

tools/premake/premake5.lua

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)")
544569
end
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+
546638
function pluginSdkExampleProject(projectDir, projectName, projectType, game2, game3, gameVc, gameSa, game4, d3dSupport, laSupport, additionalIncludeDirs, additionalLibraryDirs, additionalLibraries, additionalDefinitions)
547639
local supportedGames = {}
548640
local gameCounter = 1
@@ -820,8 +912,10 @@ else
820912
os.remove(sdkdir .. "\\plugin.workspace")
821913
os.remove(sdkdir .. "\\plugin.workspace.layout")
822914
deleteAllFoldersWithName(sdkdir, ".vs")
915+
generatePrecompiledHeader(sdkdir .. "\\shared", false)
823916

824917
if _ACTION ~= "clean" then
918+
generatePrecompiledHeader(sdkdir .. "\\shared", true)
825919

826920
workspace "plugin"
827921
location (sdkdir)

tools/premake/stdafx_template.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
3+
#ifdef USE_PCH
4+
#include <algorithm>
5+
#include <array>
6+
#include <assert.h>
7+
#include <cassert>
8+
#include <crtdbg.h>
9+
#include <cstddef>
10+
#include <cstdint>
11+
#include <cstdio>
12+
#include <expected>
13+
#include <functional>
14+
#include <limits>
15+
#include <list>
16+
#include <map>
17+
#include <math.h>
18+
#include <memory>
19+
#include <rwcore.h>
20+
#include <stdio.h>
21+
#include <stdlib.h>
22+
#include <string.h> // c-string utils
23+
#include <string> // std::string
24+
#include <string_view>
25+
#include <tchar.h>
26+
#include <tuple>
27+
#include <type_traits>
28+
#include <unordered_map>
29+
#include <utility>
30+
#include <vector>
31+
#include <windows.h>
32+
33+
GENERATED_LIST
34+
35+
#ifdef GTAIII
36+
#include "game_iii\CVector.h"
37+
#include "game_iii\CVector2D.h"
38+
#endif
39+
#ifdef GTAVC
40+
#include "game_vc\CVector.h"
41+
#include "game_vc\CVector2D.h"
42+
#endif
43+
#ifdef GTASA
44+
#include "game_sa\CVector.h"
45+
#include "game_sa\CVector2D.h"
46+
#endif
47+
#endif

0 commit comments

Comments
 (0)