-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetupProject.bat
More file actions
176 lines (152 loc) · 5.31 KB
/
SetupProject.bat
File metadata and controls
176 lines (152 loc) · 5.31 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
172
173
174
175
176
@echo off
REM Enable ANSI escape sequences
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "ESC=%%b"
)
set log_file=%~dp0CMake_Gen.log
echo %ESC%[92m-----------------------------------%ESC%[0m
echo %ESC%[92mRunning CMake Project Generation%ESC%[0m
echo %ESC%[92m-----------------------------------%ESC%[0m
echo -----------------------------------
echo Setting up project
echo -----------------------------------
choice /m "Do you want to update git submodules?"
if errorlevel 2 (
echo Skipping git submodule update.
echo -----------------------------------
goto build_directory
) else (
echo Updating git submodules.
echo -----------------------------------
where /q git
if errorlevel 1 (
echo Cannot find git on PATH! Please make sure git repository is initialized.
echo -----------------------------------
echo Please initialize submodules manually and rerun.
exit /b 1
) ELSE (
git submodule sync --recursive
git submodule update --init --recursive
)
)
:build_directory
echo Checking if Build directory exists.
echo -----------------------------------
if exist "build" (
choice /m "Do you want to generate a fresh build by deleting the existing build folder?"
if errorlevel 2 (
echo Keeping existing build directory.
echo -----------------------------------
) else (
echo Generating a fresh build.
echo -----------------------------------
echo Deleting existing Build directory.
rmdir /s /q "build"
echo -----------------------------------
mkdir build
)
) else (
echo Creating Build directory.
echo -----------------------------------
mkdir build
)
:cmake_generation
echo Checking if CMake is installed.
echo -----------------------------------
where /q cmake
if errorlevel 1 (
echo CMake not found on PATH! Please install CMake and add it to your PATH.
echo -----------------------------------
exit /b 1
) else (
echo CMake found on PATH.
echo -----------------------------------
)
echo %ESC%[92mStarting CMake Project Generation%ESC%[0m
echo %ESC%[92m-----------------------------------%ESC%[0m
cd build
(
echo %ESC%[92mCMake-----------------------------------%ESC%[0m
echo %ESC%[92mRunning CMake Project Generation%ESC%[0m
echo %ESC%[92m%date% %time%%ESC%[0m
echo %ESC%[92m-----------------------------------%ESC%[0m
) > "%~dp0CMake_Gen.log"
REM --- Run CMake asynchronously and show a pseudo progress bar while it works ---
set "_cmakeFlag=%temp%\cmake_setup_done.flag"
if exist "%_cmakeFlag%" del /f /q "%_cmakeFlag%" >nul 2>&1
REM Launch CMake (background) and create flag file on completion (removed needless backslash escapes)
start "CMakeGenerate" /b cmd /c "( cmake .. >> "%~dp0CMake_Gen.log" 2>&1 & echo done>"%_cmakeFlag%" )"
set /a _p=0
set /a _pmax=100
set "_progressScript=%~dp0scripts\Progress.bat"
if not exist "%_progressScript%" (
echo (Progress script not found, waiting for CMake...)
goto :wait_for_cmake_setup
)
echo Tracking CMake progress (log milestones)...
call "%_progressScript%" 50 0 100
set stepsTotal=11
set currentStep=0
set lastStep=0
set fallbackPercent=0
set maxFallback=90
set idleLoops=0
set maxIdleLoops=6
REM Progress milestone keywords (ordered)
set k1=The C compiler identification
set k2=The CXX compiler identification
set k3=Detecting C compiler ABI info
set k4=Detecting CXX compiler ABI info
set k5=Check for working C compiler
set k6=Check for working CXX compiler
set k7=Detecting C compile features
set k8=Detecting CXX compile features
set k9=Configuring done
set k10=Generating done
set k11=Build files have been written
:progress_loop_setup
if exist "%_cmakeFlag%" goto :finish_progress_setup
REM Update milestone based on log contents
for /L %%S in (1,1,11) do (
if !currentStep! lss %%S (
for /f "delims=" %%L in ('findstr /C:"!k%%S!" "%~dp0CMake_Gen.log" 2^>nul') do set currentStep=%%S
)
)
REM Compute percent from milestones
set /a percent=(currentStep*100)/stepsTotal
REM Fallback incremental if idle
if !currentStep! EQU !lastStep! (
set /a idleLoops+=1
if !idleLoops! GEQ !maxIdleLoops! if !fallbackPercent! LSS !maxFallback! (
set /a fallbackPercent+=1
set idleLoops=0
)
) else (
set idleLoops=0
)
if !fallbackPercent! GTR !percent! set percent=!fallbackPercent!
if !percent! GTR 99 set percent=99
call "%_progressScript%" 50 !percent! 100
set lastStep=!currentStep!
>nul ping 127.0.0.1 -n 2
goto :progress_loop_setup
:finish_progress_setup
call "%_progressScript%" 50 100 100
:wait_for_cmake_setup
if not exist "%_cmakeFlag%" goto :wait_for_cmake_setup
del /f /q "%_cmakeFlag%" >nul 2>&1
cd ..
findstr /C:"CMake Error" "%log_file%" > nul
if %errorlevel% equ 0 (
echo %ESC%[91m-----------------------------------%ESC%[0m
echo %ESC%[91mCMake Error Detected!%ESC%[0m
echo %ESC%[91mPlease check "CMake_Gen.log" for more information about the errors.%ESC%[0m
echo %ESC%[91m-----------------------------------%ESC%[0m
) else (
echo %ESC%[92mCMake Project Generation Complete%ESC%[0m
echo %ESC%[92m-----------------------------------%ESC%[0m
echo %ESC%[92mA log file has been created called CMake_Gen.log%ESC%[0m
echo %ESC%[92m-----------------------------------%ESC%[0m
)
echo %ESC%[92mPress any key to exit...%ESC%[0m
pause >nul