-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_app.bat
177 lines (140 loc) · 4.56 KB
/
build_app.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
@echo off
REM Copyright 2022-present Contributors to the jobman project.
REM SPDX-License-Identifier: BSD-3-Clause
REM https://github.com/mikaelsundell/jobman
set "app_dir=%~dp0"
set "app_name=Jobman"
set "pkg_name=jobman"
set "build_type="
set "deploy=0"
set "cmake_generator=Visual Studio 16 2019"
REM Parse arguments
:parse_args
if "%~1"=="" goto done_parse_args
set "arg=%~1"
if "%arg:~0,17%"=="--cmake_generator=" (
set "cmake_generator=%arg:~17%"
) else if "%arg%"=="--deploy" (
set "deploy=1"
) else (
set "build_type=%arg%"
)
shift
goto parse_args
:done_parse_args
if "%build_type%"=="" (
echo Invalid build type: Please specify 'Debug', 'Release', or 'all'
exit /b 1
)
setlocal enabledelayedexpansion
set "ERRORLEVEL=0"
cls
REM validate build type
if not "%build_type%"=="Debug" (
if not "%build_type%"=="Release" (
if not "%build_type%"=="All" (
echo Invalid build type: %build_type% (use 'Debug', 'Release', or 'All')
goto :error
)
)
)
REM check if CMake is in the PATH
where cmake >nul 2>&1
if errorlevel 1 (
echo CMake not found in the PATH, please make sure it's installed
goto :error
)
REM check if CMake version is compatible
for /f "tokens=*" %%V in ('cmake --version') do (
for /f "tokens=*" %%V in ("%%V") do (
set "cmake_version=%%V"
set "cmake_version=!cmake_version:cmake version =!"
for /f "delims=. tokens=1-3" %%a in ("!cmake_version!") do (
set "major=%%a"
set "minor=%%b"
set "patch=%%c"
)
)
)
REM build jobman
:build_jobman
echo Building Jobman for %build_type% using %cmake_generator%
echo -------------------------------------------------------
set "build_dir=%app_dir%build.%build_type%"
echo Building in %build_dir%
mkdir "%build_dir%"
cd "%build_dir%"
REM prefix directory
if not defined THIRDPARTY_DIR (
echo Could not find 3rdparty project environment variable THIRDPARTY_DIR
goto :error
)
REM cmake friendly paths
set "cmake_dir=%app_dir:\=/%"
set "cmake_thirdparty_dir=%THIRDPARTY_DIR:\=/%"
REM generate build with cmake
cmake .. -G "%cmake_generator%" -DCMAKE_MODULE_PATH="%cmake_dir%modules" -DCMAKE_PREFIX_PATH="%cmake_thirdparty_dir%"
if errorlevel 1 goto :error
REM build the configuration
cmake --build . --config %build_type% --parallel --verbose
if errorlevel 1 goto :error
REM deploy the configuration if requested
if "%deploy%"=="1" (
call :deploy_jobman
)
goto :end
:deploy_jobman
REM deploy using windeployqt
set "deploy_dir=%app_dir%deploy.%build_type%"
set "windeployqt=%THIRDPARTY_DIR%\bin\windeployqt6.exe"
set "exe_path=%build_dir%\%build_type%\%app_name%.exe"
set "presets_path=%build_dir%\%build_type%\Presets"
set "resources_path=%build_dir%\%build_type%\Resources"
echo Deploying Jobman for %build_type% to %deploy_dir%
echo -------------------------------------------------
REM check if windeployqt exists
if not exist "%windeployqt%" (
echo windeployqt not found in %THIRDPARTY_DIR%/bin
goto :error
)
REM clean deploy directory
if exist "%deploy_dir%" rmdir /s /q "%deploy_dir%"
mkdir "%deploy_dir%"
REM copy executable
copy "%exe_path%" "%deploy_dir%"
REM copy resources
xcopy "%presets_path%" "%deploy_dir%\Presets" /E /I /Y
xcopy "%resources_path%" "%deploy_dir%\Resources" /E /I /Y
REM copy dependencies
copy "%THIRDPARTY_DIR%\bin\lcms2.dll" "%deploy_dir%"
REM run windeployqt
"%windeployqt%" "%deploy_dir%\%app_name%.exe" --dir "%deploy_dir%"
if errorlevel 1 goto :error
echo deployment successful
REM create a zip file of the deployment folder
REM extract version from CMakeLists.txt
set "version_file=%app_dir%CMakeLists.txt"
set "version="
for /f "usebackq tokens=3 delims=() " %%A in (`findstr /c:"set (app_long_version" "%version_file%"`) do (
set "version=%%A"
set "version=!version:~1,-1!"
)
if "%version%"=="" (
echo failed to extract version from CMakeLists.txt
goto :error
)
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /value ^| find "LocalDateTime"') do set datetime=%%I
set "current_date=%datetime:~2,6%"
set "zipfile=%deploy_dir%\%app_name%_%version%_%current_date%_%build_type%.zip"
echo creating zip file: %zipfile%
powershell -command "Compress-Archive -Path '%deploy_dir%\*' -DestinationPath '%zipfile%' -Force"
if errorlevel 1 (
echo failed to create ZIP file
goto :error
)
echo zip file created successfully: %zipfile%
goto :end
:error
exit /b 1
:end
exit /b 0