-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.ps1
210 lines (175 loc) · 6.35 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
param (
# comma separated
[string[]][Parameter(Mandatory)]
$projects,
# The drive that is not a system drive, so no difficulties with permissions and such
# to simply build the project. a temporary directory will be created in the provided
# drive for building the dependencies as the working dir.
[string][Parameter(Mandatory)]
$drive = "D"
)
$WORK_DIR = $null
# Versions
$VER_JPEGLIB = "3.0.3"
$VER_ZLIB = "v1.3.1"
$VER_SPDLOG = "v1.14.1"
$VER_IMGUI = "v1.90.7"
$VER_SIMPLEINI = "v4.23"
function build_jpeglib {
Write-Host "Building jpeglib..."
git clone --branch=$VER_JPEGLIB --depth=1 https://github.com/ko4life-net/libjpeg-turbo
cd libjpeg-turbo
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A Win32 `
-DENABLE_SHARED=OFF `
-DWITH_TURBOJPEG=OFF `
-DJPEG_STATIC_OUTPUT_NAME=jpeg `
-DCMAKE_INSTALL_PREFIX=pkg `
-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" `
-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT="$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>" `
-DCMAKE_POLICY_DEFAULT_CMP0141=NEW
cmake --build . --config Debug --target jpeg-static install
cmake --build . --config Release --target jpeg-static install
Remove-Item $PSScriptRoot\jpeglib\include, $PSScriptRoot\jpeglib\lib -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item .\pkg\include $PSScriptRoot\jpeglib\ -Recurse
Copy-Item .\pkg\lib $PSScriptRoot\jpeglib\ -Recurse
cd $WORK_DIR
}
function build_zlib {
Write-Host "Building zlib..."
git clone --branch=$VER_ZLIB --depth=1 https://github.com/ko4life-net/zlib
cd zlib
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A Win32 `
-DZLIB_SHARED_PROJECT_NAME="zlib-shared" `
-DZLIB_STATIC_PROJECT_NAME="zlib" `
-DZLIB_BUILD_EXAMPLES=OFF `
-DCMAKE_INSTALL_PREFIX=pkg `
-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" `
-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT="$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>" `
-DCMAKE_POLICY_DEFAULT_CMP0141=NEW
cmake --build . --config Debug --target zlib install
cmake --build . --config Release --target zlib install
Remove-Item $PSScriptRoot\zlib\include, $PSScriptRoot\zlib\lib -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item .\pkg\lib\zlib-*.lib -Force -ErrorAction SilentlyContinue # remove shared libs. TODO: I should probably update their cmake file.
Copy-Item .\pkg\include $PSScriptRoot\zlib\ -Recurse
Copy-Item .\pkg\lib $PSScriptRoot\zlib\ -Recurse
cd $WORK_DIR
}
function build_spdlog {
Write-Host "Building spdlog..."
git clone --branch=$VER_SPDLOG --depth=1 https://github.com/ko4life-net/spdlog.git
cd spdlog
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A Win32 `
-DCMAKE_INSTALL_PREFIX=pkg `
-DSPDLOG_USE_STD_FORMAT=ON `
-DSPDLOG_BUILD_EXAMPLE=OFF `
-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" `
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW
cmake --build . --config Debug --target install
cmake --build . --config Release --target install
Remove-Item $PSScriptRoot\spdlog\include, $PSScriptRoot\spdlog\lib -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item .\pkg\include $PSScriptRoot\spdlog\ -Recurse
Copy-Item .\pkg\lib $PSScriptRoot\spdlog\ -Recurse
cd $WORK_DIR
}
function build_imgui {
Write-Host "Building imgui..."
git clone --branch=$VER_IMGUI --depth=1 --recursive --shallow-submodules https://github.com/ko4life-net/imgui-cmake.git
cd imgui-cmake
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A Win32 `
-DIMGUI_WITH_BACKEND=ON `
-DIMGUI_BACKEND_PLATFORM=WIN32 `
-DIMGUI_BACKEND_DX9=ON `
-DCMAKE_INSTALL_PREFIX=pkg `
-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" `
-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT="$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>" `
-DCMAKE_POLICY_DEFAULT_CMP0141=NEW
cmake --build . --config Debug --target install
cmake --build . --config Release --target install
Remove-Item $PSScriptRoot\imgui\include, $PSScriptRoot\imgui\lib, $PSScriptRoot\imgui\misc -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item .\pkg\include $PSScriptRoot\imgui\ -Recurse
Copy-Item .\pkg\lib $PSScriptRoot\imgui\ -Recurse
Copy-Item .\pkg\misc $PSScriptRoot\imgui\ -Recurse
cd $WORK_DIR
}
function build_simpleini {
Write-Host "Building simpleini..."
git clone --branch=$VER_SIMPLEINI --depth=1 https://github.com/ko4life-net/simpleini
cd simpleini
mkdir build
cd build
# There is no actual lib here, since it is a header only library
cmake .. -G "Visual Studio 17 2022" -A Win32 -DCMAKE_INSTALL_PREFIX=pkg
cmake --build . --config Release --target install
Remove-Item $PSScriptRoot\simpleini\include, $PSScriptRoot\simpleini\lib -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item .\pkg\include $PSScriptRoot\simpleini\include\simpleini\ -Recurse
Copy-Item .\pkg\lib $PSScriptRoot\simpleini\ -Recurse
cd $WORK_DIR
}
function build_projects {
if ($projects -contains "all") {
build_jpeglib
build_zlib
build_spdlog
build_imgui
build_simpleini
} else {
foreach ($project in $projects) {
switch ($project.ToLower()) {
"jpeglib" { build_jpeglib }
"zlib" { build_zlib }
"spdlog" { build_spdlog }
"imgui" { build_imgui }
"simpleini" { build_simpleini }
default { Write-Host "Unknown project: [$project]" }
}
}
}
Write-Host "Succesfully built and installed [$($projects -join ", ")] projects!"
}
function create_work_dir {
if (-not (Get-PSDrive $drive -ErrorAction SilentlyContinue)) {
Write-Host "Invalid drive [$drive]. Use one of the available below:"
Get-PSDrive
exit 1
}
$wd = $null
foreach ($i in 0..10) {
$_wd = $drive + ":\_ko" + ((New-Guid) -split '-')[0]
if (-not (Test-Path $_wd)) {
$wd = (mkdir $_wd).FullName
break
}
}
if (-not $wd) {
Write-Host "Failed to create working directory..."
exit 1
}
return $wd
}
function Main {
$drive = $drive.ToUpper()
$WORK_DIR = create_work_dir
Write-Host "Building projects working directory: [$WORK_DIR]"
pushd $WORK_DIR
$start_time = Get-Date
try {
build_projects
} catch {
MessageError "An error occurred: $_"
exit 1
} finally {
$end_time = Get-Date
$elapsed_time = $end_time - $start_time
Write-Host "Time taken: $($elapsed_time.ToString('hh\:mm\:ss\.ffff'))"
popd
}
}
Main