-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild-msvc.bat
executable file
·393 lines (356 loc) · 13.1 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
:: 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 devel=false
set clean=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=""
:: Optionally, the program can be built with Direct3D 12 support for some renderers.
set use_d3d=false
:loop
IF NOT "%1"=="" (
IF "%1"=="--do-not-run" (
SET run_program=false
)
IF "%1"=="--debug" (
SET debug=true
)
IF "%1"=="--devel" (
SET devel=true
)
IF "%1"=="--clean" (
SET clean=true
)
IF "%1"=="--vcpkg-triplet" (
SET vcpkg_triplet=%2
SHIFT
)
IF "%1"=="--d3d" (
SET use_d3d=true
)
SHIFT
GOTO :loop
)
:: Clean the build artifacts if requested by the user.
if %clean% == true (
echo ------------------------
echo cleaning up old files
echo ------------------------
rd /s /q "third_party\vcpkg"
for /d %%G in (".build*") do rd /s /q "%%~G"
rd /s /q "Shipping"
git submodule update --init --recursive
:: https://stackoverflow.com/questions/5626879/how-to-find-if-a-file-contains-a-given-string-using-windows-command-line
find /c "sgl" .gitmodules >NUL
if %errorlevel% equ 1 goto sglnotfound
rd /s /q "third_party\sgl\install"
for /d %%G in ("third_party\sgl\.build*") do rd /s /q "%%~G"
)
goto cleandone
:sglnotfound
rd /s /q "third_party\sgl"
goto cleandone
:cleandone
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 VisualStudioVersion (
set "VsVersionNumber=%VisualStudioVersion:~0,2%"
) else (
set VsVersionNumber=0
)
if defined VisualStudioVersion (
if not defined VsPathEnd (
if %VsVersionNumber% == 14 (
set VsPathEnd=2015
) else if %VsVersionNumber% == 15 (
set VsPathEnd=2017
) else if %VsVersionNumber% == 16 (
set VsPathEnd=2019
) else if %VsVersionNumber% == 17 (
set VsPathEnd=2022
)
)
)
if defined VsPathEnd (
set cmake_generator=-G "Visual Studio %VisualStudioVersion:~0,2% %VsPathEnd:~0,4%"
) else (
set cmake_generator=
)
if %debug% == true (
set cmake_config="Debug"
set cmake_config_opposite="Release"
) else (
set cmake_config="Release"
set cmake_config_opposite="Debug"
)
if not exist .\submodules\IsosurfaceCpp\src (
echo ------------------------
echo initializing submodules
echo ------------------------
git submodule init || exit /b 1
git submodule update || exit /b 1
)
if not exist .\third_party\ mkdir .\third_party\
set proj_dir=%~dp0
set third_party_dir=%proj_dir%third_party
pushd third_party
IF "%VULKAN_SDK%"=="" (
for /D %%F in (C:\VulkanSDK\*) do (
set VULKAN_SDK=%%F
set "PATH=%%F\Bin;%PATH%"
goto vulkan_finished
)
)
:vulkan_finished
if %use_d3d% == true (
set cmake_args_sgl=%cmake_args_sgl% -DSUPPORT_D3D12=ON -DVCPKG_MANIFEST_FEATURES=d3d12
)
IF "%toolchain_file%"=="" (
SET use_vcpkg=true
) ELSE (
SET use_vcpkg=false
)
IF "%toolchain_file%"=="" SET toolchain_file="vcpkg/scripts/buildsystems/vcpkg.cmake"
set cmake_args=%cmake_args% -DCMAKE_TOOLCHAIN_FILE="third_party/%toolchain_file%" ^
-DPYTHONHOME="./python3" ^
-Dsgl_DIR="third_party/sgl/install/lib/cmake/sgl/"
set cmake_args_general=%cmake_args_general% -DCMAKE_TOOLCHAIN_FILE="%third_party_dir%/%toolchain_file%"
if %use_vcpkg% == true (
set cmake_args=%cmake_args% -DVCPKG_TARGET_TRIPLET=%vcpkg_triplet% -DCMAKE_CXX_FLAGS="/MP"
set cmake_args_sgl=-DCMAKE_CXX_FLAGS="/MP"
set cmake_args_general=%cmake_args_general% -DVCPKG_TARGET_TRIPLET=%vcpkg_triplet%
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
)
)
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_dir% 2> NUL
pushd sgl\%build_dir%
cmake .. %cmake_generator% %cmake_args_sgl% %cmake_args_general% ^
-DCMAKE_INSTALL_PREFIX="%third_party_dir%/sgl/install" || exit /b 1
if %use_vcpkg% == true (
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
)
) else (
cmake --build . --config %cmake_config% || exit /b 1
cmake --build . --config %cmake_config% --target install || exit /b 1
)
popd
)
set embree_version=3.13.3
if not exist ".\embree-%embree_version%.x64.vc14.windows" (
echo ------------------------
echo downloading Embree
echo ------------------------
curl.exe -L "https://github.com/embree/embree/releases/download/v%embree_version%/embree-%embree_version%.x64.vc14.windows.zip" --output embree-%embree_version%.x64.vc14.windows.zip
tar -xvzf "embree-%embree_version%.x64.vc14.windows.zip"
)
set cmake_args=%cmake_args% -Dembree_DIR="third_party/embree-%embree_version%.x64.vc14.windows/lib/cmake/embree-%embree_version%"
set ospray_version=2.9.0
if not exist ".\ospray-%ospray_version%.x86_64.windows" (
echo ------------------------
echo downloading OSPRay
echo ------------------------
curl.exe -L "https://github.com/ospray/OSPRay/releases/download/v%ospray_version%/ospray-%ospray_version%.x86_64.windows.zip" --output ospray-%ospray_version%.x86_64.windows.zip
tar -xvzf "ospray-%ospray_version%.x86_64.windows.zip"
)
set cmake_args=%cmake_args% -Dospray_DIR="third_party/ospray-%ospray_version%.x86_64.windows/lib/cmake/ospray-%ospray_version%"
set eccodes_version=2.26.0
if not exist ".\eccodes-%eccodes_version%-Source" (
echo ------------------------
echo downloading ecCodes
echo ------------------------
curl.exe -L "https://confluence.ecmwf.int/download/attachments/45757960/eccodes-%eccodes_version%-Source.tar.gz?api=v2" --output eccodes-%eccodes_version%-Source.tar.gz
tar -xvzf "eccodes-%eccodes_version%-Source.tar.gz"
)
:: ecCodes needs bash.exe, but it is just a dummy pointing the caller to WSL if not installed.
:: ecCodes is disabled for now due to build errors on Windows.
set use_eccodes=false
:: set bash_output=empty
:: for /f %%i in ('where bash') do set bash_location=%%i
:: IF "%bash_location%"=="" (
:: set bash_location=C:\Windows\System32\bash.exe
:: )
:: IF EXIST "%bash_location%" (
:: goto bash_exists
:: ) ELSE (
:: goto system_bash_not_exists
:: )
::
:: :: goto circumvents problems when not using EnableDelayedExpansion.
:: :bash_exists
:: set bash_output=empty
:: for /f %%i in ('"%bash_location%" --version') do set bash_output=%%i
:: IF "%bash_output%"=="" (
:: set bash_output=empty
:: )
:: :: Output is usually https://aka.ms/wslstore when WSL is not installed.
:: if not x%bash_output:wsl=%==x%bash_output% (
:: set use_eccodes=false
:: ) ELSE (
:: set use_eccodes=true
:: )
:: goto finished
::
:: :system_bash_not_exists
:: set bash_location="C:/Program Files/Git/bin/bash.exe"
:: IF EXIST "%bash_location%" (
:: set "PATH=C:\Program Files\Git\bin;%PATH%"
:: goto bash_exists
:: ) ELSE (
:: goto finished
:: )
::
:: :finished
:: echo bash_location: %bash_location%
:: echo use_eccodes: %use_eccodes%
if %use_eccodes% == true if not exist ".\eccodes-%eccodes_version%" (
echo ------------------------
echo building ecCodes
echo ------------------------
pushd eccodes-%eccodes_version%-Source
if not exist .\build\ mkdir .\build\
pushd build
cmake .. %cmake_generator% -DCMAKE_INSTALL_PREFIX=../../eccodes-%eccodes_version% -DCMAKE_CXX_FLAGS="/MP" || exit /b 1
cmake --build . --config Debug -- /m || exit /b 1
cmake --build . --config Debug --target install || exit /b 1
cmake --build . --config Release -- /m || exit /b 1
cmake --build . --config Release --target install || exit /b 1
popd
popd
)
set cmake_args=%cmake_args% -Deccodes_DIR="third_party/eccodes-%eccodes_version%/lib/cmake/eccodes-%eccodes_version%"
set oidn_version=2.3.1
if not exist ".\oidn-%oidn_version%.x64.windows" (
echo ------------------------
echo downloading OpenImageDenoise
echo ------------------------
curl.exe -L "https://github.com/OpenImageDenoise/oidn/releases/download/v%oidn_version%/oidn-%oidn_version%.x64.windows.zip" --output oidn-%oidn_version%.x64.windows.zip
tar -xvzf "oidn-%oidn_version%.x64.windows.zip"
del "oidn-%oidn_version%.x64.windows.zip"
)
set cmake_args=%cmake_args% -DOpenImageDenoise_DIR="third_party/oidn-%oidn_version%.x64.windows/lib/cmake/OpenImageDenoise-%oidn_version%"
popd
if %debug% == true (
echo ------------------------
echo building in debug
echo ------------------------
) else (
echo ------------------------
echo building in release
echo ------------------------
)
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 ------------------------
if %use_vcpkg% == true (
cmake --build %build_dir% --config %cmake_config% -- /m || exit /b 1
) else (
cmake --build %build_dir% --config %cmake_config% || exit /b 1
)
echo ------------------------
echo copying new files
echo ------------------------
robocopy .build\vcpkg_installed\x64-windows\tools\python3 ^
%destination_dir%\python3 /e >NUL
robocopy third_party\ospray-%ospray_version%.x86_64.windows\bin %destination_dir% *.dll >NUL
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_dir%\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_dir%\Release %destination_dir% *.dll >NUL
)
:: Build other configuration and copy sgl DLLs to the build directory.
if %devel% == true (
echo ------------------------
echo setting up dev files
echo ------------------------
if %use_vcpkg% == true (
cmake --build %build_dir% --config %cmake_config_opposite% -- /m || exit /b 1
) else (
cmake --build %build_dir% --config %cmake_config_opposite% || exit /b 1
)
robocopy third_party\sgl\%build_dir%\Debug %build_dir%\Debug\ *.dll *.pdb >NUL
robocopy third_party\sgl\%build_dir%\Release %build_dir%\Release\ *.dll >NUL
)
echo.
echo All done!
pushd %destination_dir%
if %run_program% == true (
LineVis.exe
) else (
echo Build finished.
)