-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
171 lines (152 loc) · 5.83 KB
/
setup.bat
File metadata and controls
171 lines (152 loc) · 5.83 KB
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
@REM project_starter_kit
@REM https://github.com/simongeilfus/project_starter_kit
@rem MIT License
@rem Copyright (c) 2022 Simon Geilfus
@rem Permission is hereby granted, free of charge, to any person obtaining a copy
@rem of this software and associated documentation files (the "Software"), to deal
@rem in the Software without restriction, including without limitation the rights
@rem to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@rem copies of the Software, and to permit persons to whom the Software is
@rem furnished to do so, subject to the following conditions:
@rem The above copyright notice and this permission notice shall be included in all
@rem copies or substantial portions of the Software.
@rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@rem IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@rem FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@rem AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
@rem LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
@rem OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
@rem SOFTWARE.
@rem ---------------------------------------------------------------------------
@rem GENERATES GIT COMMANDS TO SETUP PROJECT WITH REPOSITORIES AND/OR SUBMODULES
@rem ---------------------------------------------------------------------------
@echo off
setlocal EnableDelayedExpansion
echo project_starter_kit/setup.bat
@rem parse arguments
@rem -----------------------------------
set argc=0
for %%x in (%*) do (
set /A argc+=1
set "argv[!argc!]=%%~x"
)
@rem prompt to rename the project if options.cmake still has the default name
@rem -----------------------------------
findstr /C:"set(PROJECT project_starter_kit)" "%~dp0options.cmake" >nul 2>&1
if errorlevel 1 goto skip_project_rename
echo:
echo The project name in options.cmake is still "project_starter_kit".
set "new_project_name="
set /p "new_project_name= Enter a new project name (leave blank to keep default): "
if not defined new_project_name goto skip_project_rename
powershell -NoProfile -Command "(Get-Content -Raw -LiteralPath '%~dp0options.cmake') -replace 'set\(PROJECT project_starter_kit\)', 'set(PROJECT %new_project_name%)' | Set-Content -NoNewline -Encoding ASCII -LiteralPath '%~dp0options.cmake'"
if errorlevel 1 (
echo Warning: failed to update options.cmake.
) else (
echo options.cmake updated: PROJECT = %new_project_name%
)
echo:
:skip_project_rename
@rem no argument message
@rem -----------------------------------
if %argc% lss 1 goto print_help
@rem build commands
@rem -----------------------------------
set needs_submodule_init=0
set commandc=0
set git_mode=submodule add
for /L %%e in (1,1,%argc%) do (
if !argv[%%e]! == clone (
@rem change mode to clone
set "git_mode=clone"
) else (
if !argv[%%e]! == submodule (
@rem change mode to submodule
set "git_mode=submodule add"
) else (
@rem check if this match the name of a git repository to setup
for /F "tokens=1,2,3,4" %%i in (%~dp0/tools/third_party.txt) do (
@rem if there's a match add the command to the list
if !argv[%%e]! == %%i (
set /A commandc+=1
set "commandv[!commandc!]=git !git_mode! %%k %%l %%j third_party/%%i"
set needs_submodule_init=1
)
)
@rem install cmake
if !argv[%%e]! == cmake (
set /A commandc+=1
set "commandv[!commandc!]=call tools\setup_cmake.bat"
)
@rem install python
if !argv[%%e]! == python (
set /A commandc+=1
set "commandv[!commandc!]=call tools\setup_python.bat"
)
@rem install vulkan
if !argv[%%e]! == vulkan (
set /A commandc+=1
set "commandv[!commandc!]=call tools\setup_vulkan.bat"
)
)
)
)
@rem no commands build warning message
@rem -----------------------------------
if %commandc% lss 1 (
echo:
echo Error: No commands were build
goto print_help
) else (
if %needs_submodule_init% == 1 (
@rem otherwise add default ending commands
set /A commandc+=1
set "commandv[!commandc!]=git submodule update --init --recursive"
)
)
@rem check the working dir is a git repo (only matters if we're about to run git commands)
@rem -----------------------------------
if %needs_submodule_init% neq 1 goto skip_git_check
git rev-parse --is-inside-work-tree >nul 2>&1
if not errorlevel 1 goto skip_git_check
echo:
echo This directory is not a git repository, but the requested setup needs one
echo to add submodules.
echo:
choice /C YN /M "Initialize a new git repository here with 'git init'? "
if errorlevel 2 goto end
echo:
git init
echo:
:skip_git_check
@rem print commands
@rem -----------------------------------
echo This script will generate the following commands:
echo:
for /L %%i in (1,1,%commandc%) do echo !commandv[%%i]!
@rem confirm message
@rem -----------------------------------
echo:
choice /C YN /M "Do you want to execute those commands? "
echo:
goto option-%errorlevel%
:option-1
@rem execute commands
@rem -----------------------------------
for /L %%i in (1,1,%commandc%) do !commandv[%%i]!
goto end
:print_help
echo:
echo usage: setup [mode] lib0 lib1 [mode] lib2 lib3
echo mode defaults to "submodule" but can be set to "clone" or "submodule" in any order
echo available third party libraries:
for /F "tokens=1,2,3" %%i in (%~dp0/tools/third_party.txt) do echo %%i
@rem cleanup
@rem -----------------------------------
:option-2
:end
set argc=
set argv=
set commandc=
set commandv=
set needs_submodule_init=