-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_cpp.bat
106 lines (99 loc) · 3.1 KB
/
build_cpp.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
:: Simple CMake wrapper script to build the CMake targets in the project.
:: Any arguments before --build-args are passed directly to cmake --build.
::
:: Note: any -D<var>=<value> arguments must be double-quoted!
@echo off
setlocal EnableDelayedExpansion
:: arguments passed to cmake command directly
set CMAKE_ARGS=
:: arguments passed to cmake --build command directly
set CMAKE_BUILD_ARGS=
:: program name, as any label `call`ed uses label name as %0
set PROGNAME=%0
:: indicate current argument parsing mode
set PARSE_MODE=cmake_args
call :Main %*
exit /b !ERRORLEVEL!
::::
:: Collect incoming arguments, separating them for cmake, cmake --build.
::
:: Sets the CMAKE_ARGS and CMAKE_BUILD_ARGS global variables.
::
:: Arguments:
:: Array of command-line arguments
:: Any arguments after --build-args are passed to cmake --build while the
:: rest preceding will be passed to the cmake configure command.
::
:CollectArgs
:: note that using "::" as comment can cause cmd to misinterpret tokens as
:: drive names when you have "::" inside the if statements. use rem instead.
:: however, rem tends to be much slower.
::
:: see https://stackoverflow.com/a/12407934/14227825 and other answers.
::
:: we break early if the help flag is encountered and set PARSE_MODE.
::
for %%A in (%*) do (
if %%A==--help (
set PARSE_MODE=print_help
exit /b 0
) else (
if %%A==--build-args (
set PARSE_MODE=cmake_build_args
) else (
if !PARSE_MODE!==cmake_build_args (
if not defined CMAKE_BUILD_ARGS (
set CMAKE_BUILD_ARGS=%%A
) else (
set CMAKE_BUILD_ARGS=!CMAKE_BUILD_ARGS! %%A
)
) else (
if not defined CMAKE_ARGS (
set CMAKE_ARGS=%%A
) else (
set CMAKE_ARGS=!CMAKE_ARGS! %%A
)
)
)
)
)
exit /b 0
::::
:: Main function for the build script.
::
:: Arguments:
:: Array of command-line arguments
::
:Main
:: print help blurb if necessary
:: separate incoming args into those for cmake, cmake --build. note that the
:: only way to preserve literal "=" is to just accept all the args.
call :CollectArgs %*
:: print help and exit if PARSE_MODE is print_help
if !PARSE_MODE!==print_help (
call :PrintHelp
exit /b 0
)
cmake -G Ninja -S . -B build_windows !CMAKE_ARGS!
cmake --build build_windows !CMAKE_BUILD_ARGS!
exit /b !ERRORLEVEL!
::::
:: Print help output.
::
:: Note: ^ is used to escape some characters with special meaning, and can be
:: also used for line continuation. ! must be double-escaped, however.
::
:PrintHelp
echo Usage: %PROGNAME% [ARG ...] [--build-args BUILD_ARG [BUILD_ARG ...]]
echo.
echo Build the C++ library and examples by using CMake.
echo.
echo Note that any -D^<var^>=^<value^> arguments must be double-quoted^^!
echo.
echo Arguments:
echo ARG ... args passed to cmake command
echo --build-args ARG [ARG ...] args passed to cmake --build command
echo --help show this help message and exit
exit /b 0
endlocal
echo on