-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-msvc.bat
executable file
·191 lines (163 loc) · 5.73 KB
/
build-msvc.bat
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
:: BSD 2-Clause License
::
:: Copyright (c) 2021-2022, Christoph Neuhauser, Felix Brendel
:: All rights reserved.
::
:: Redistribution and use in source and binary forms, with or without
:: modification, are permitted provided that the following conditions are met:
::
:: 1. Redistributions of source code must retain the above copyright notice, this
:: list of conditions and the following disclaimer.
::
:: 2. Redistributions in binary form must reproduce the above copyright notice,
:: this list of conditions and the following disclaimer in the documentation
:: and/or other materials provided with the distribution.
::
:: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
:: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
:: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
:: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
:: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
:: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
:: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
:: CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
:: OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
:: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@echo off
setlocal
pushd %~dp0
set VSLANG=1033
set run_program=true
set debug=false
set build_dir=".build"
set destination_dir="Shipping"
set vcpkg_triplet="x64-windows"
:: Leave empty to let cmake try to find the correct paths
set optix_install_dir=""
:loop
IF NOT "%1"=="" (
IF "%1"=="--do-not-run" (
SET run_program=false
)
IF "%1"=="--debug" (
SET debug=true
)
IF "%1"=="--vcpkg-triplet" (
SET vcpkg_triplet=%2
SHIFT
)
SHIFT
GOTO :loop
)
where cmake >NUL 2>&1 || echo cmake was not found but is required to build the program && exit /b 1
:: Creates a string with, e.g., -G "Visual Studio 17 2022".
:: Needs to be run from a Visual Studio developer PowerShell or command prompt.
if defined VCINSTALLDIR (
set VCINSTALLDIR_ESC=%VCINSTALLDIR:\=\\%
)
if defined VCINSTALLDIR (
set "x=%VCINSTALLDIR_ESC:Microsoft Visual Studio\\=" & set "VsPathEnd=%"
)
if defined VCINSTALLDIR (
set cmake_generator=-G "Visual Studio %VisualStudioVersion:~0,2% %VsPathEnd:~0,4%"
)
if not defined VCINSTALLDIR (
set cmake_generator=
)
IF "%VULKAN_SDK%"=="" (
for /D %%F in (C:\VulkanSDK\*) do (
set VULKAN_SDK=%%F
goto vulkan_finished
)
)
:vulkan_finished
set third_party_dir=%~dp0/third_party
set cmake_args=-DCMAKE_TOOLCHAIN_FILE="third_party/vcpkg/scripts/buildsystems/vcpkg.cmake" ^
-DVCPKG_TARGET_TRIPLET=%vcpkg_triplet% ^
-DCMAKE_CXX_FLAGS="/MP" ^
-Dsgl_DIR="third_party/sgl/install/lib/cmake/sgl/"
set cmake_args_general=-DCMAKE_TOOLCHAIN_FILE="%third_party_dir%/vcpkg/scripts/buildsystems/vcpkg.cmake" ^
-DVCPKG_TARGET_TRIPLET=%vcpkg_triplet%
if not exist .\third_party\ mkdir .\third_party\
pushd third_party
if not exist .\vcpkg (
echo ------------------------
echo fetching vcpkg
echo ------------------------
git clone --depth 1 https://github.com/Microsoft/vcpkg.git || exit /b 1
call vcpkg\bootstrap-vcpkg.bat -disableMetrics || exit /b 1
vcpkg\vcpkg install --triplet=%vcpkg_triplet% || exit /b 1
)
if not exist .\sgl (
echo ------------------------
echo fetching sgl
echo ------------------------
git clone --depth 1 https://github.com/chrismile/sgl.git || exit /b 1
)
if not exist .\sgl\install (
echo ------------------------
echo building sgl
echo ------------------------
mkdir sgl\.build 2> NUL
pushd sgl\.build
cmake .. %cmake_generator% %cmake_args_general% ^
-DCMAKE_INSTALL_PREFIX="%third_party_dir%/sgl/install" -DCMAKE_CXX_FLAGS="/MP" || exit /b 1
if x%vcpkg_triplet:release=%==x%vcpkg_triplet% (
cmake --build . --config Debug -- /m || exit /b 1
cmake --build . --config Debug --target install || exit /b 1
)
if x%vcpkg_triplet:debug=%==x%vcpkg_triplet% (
cmake --build . --config Release -- /m || exit /b 1
cmake --build . --config Release --target install || exit /b 1
)
popd
)
popd
if %debug% == true (
echo ------------------------
echo building in debug
echo ------------------------
set cmake_config="Debug"
) else (
echo ------------------------
echo building in release
echo ------------------------
set cmake_config="Release"
)
echo ------------------------
echo generating
echo ------------------------
if not %optix_install_dir% == "" (
echo Using custom OptiX path
set cmake_args=%cmake_args% -DOptiX_INSTALL_DIR=%optix_install_dir%
)
cmake %cmake_generator% %cmake_args% -S . -B %build_dir%
echo ------------------------
echo compiling
echo ------------------------
cmake --build %build_dir% --config %cmake_config% -- /m || exit /b 1
echo ------------------------
echo copying new files
echo ------------------------
if %debug% == true (
if not exist %destination_dir%\*.pdb (
del %destination_dir%\*.dll
)
robocopy %build_dir%\Debug\ %destination_dir% >NUL
robocopy third_party\sgl\.build\Debug %destination_dir% *.dll *.pdb >NUL
) else (
if exist %destination_dir%\*.pdb (
del %destination_dir%\*.dll
del %destination_dir%\*.pdb
)
robocopy %build_dir%\Release\ %destination_dir% >NUL
robocopy third_party\sgl\.build\Release %destination_dir% *.dll >NUL
)
echo.
echo All done!
pushd %destination_dir%
if %run_program% == true (
CloudRendering.exe
) else (
echo Build finished.
)