-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathgen-buildsys.cmd
More file actions
147 lines (127 loc) · 5.54 KB
/
gen-buildsys.cmd
File metadata and controls
147 lines (127 loc) · 5.54 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
@if not defined _echo @echo off
rem
rem This file invokes cmake and generates the build system for windows.
set __argCount=0
for %%x in (%*) do set /A __argCount+=1
if %__argCount% lss 4 goto :USAGE
if %1=="/?" goto :USAGE
set __Os=%5
set "__repoRoot=%~dp0..\.."
:: normalize
for %%i in ("%__repoRoot%") do set "__repoRoot=%%~fi"
:: Set up the EMSDK environment before setlocal so that it propagates to the caller.
if /i "%__Os%" == "browser" (
if "%EMSDK_PATH%" == "" (
if not exist "%__repoRoot%\src\mono\browser\emsdk" (
echo Error: Should set EMSDK_PATH environment variable pointing to emsdk root.
exit /B 1
)
set EMSDK_QUIET=1 && call "%__repoRoot%\src\mono\browser\emsdk\emsdk_env"
) else (
set EMSDK_QUIET=1 && call "%EMSDK_PATH%\emsdk_env"
)
)
setlocal enabledelayedexpansion
set __SourceDir=%1
set __IntermediatesDir=%2
set __VSVersion=%3
set __Arch=%4
set __CmakeGenerator=Visual Studio
set __ExtraCmakeParams=
if /i "%__Ninja%" == "1" (
set __CmakeGenerator=Ninja
) else (
if /i NOT "%__Arch%" == "wasm" (
if /i "%__VSVersion%" == "18.0" (set __CmakeGenerator=%__CmakeGenerator% 18 2026)
if /i "%__VSVersion%" == "17.0" (set __CmakeGenerator=%__CmakeGenerator% 17 2022)
if /i "%__Arch%" == "x64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A x64)
if /i "%__Arch%" == "arm" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM)
if /i "%__Arch%" == "arm64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM64)
if /i "%__Arch%" == "x86" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A Win32)
) else (
set __CmakeGenerator=NMake Makefiles
)
)
if /i "%__Arch%" == "wasm" (
if "%__Os%" == "" (
echo Error: Please add target OS parameter
exit /B 1
)
if /i "%__Os%" == "browser" (
set CMakeToolPrefix=emcmake
)
if /i "%__Os%" == "wasi" (
if "%WASI_SDK_PATH%" == "" (
if not exist "%__repoRoot%\artifacts\wasi-sdk" (
echo Error: Should set WASI_SDK_PATH environment variable pointing to WASI SDK root.
exit /B 1
)
set "WASI_SDK_PATH=%__repoRoot%\artifacts\wasi-sdk"
)
set __CmakeGenerator=Ninja
set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1"
)
) else (
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0"
)
if /i "%__Os%" == "android" (
:: Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot
set __ANDROID_API_LEVEL=24
if "%ANDROID_NDK_ROOT%" == "" (
echo Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root.
exit /B 1
)
set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_BUILD=1" "-DANDROID_CPP_FEATURES='no-rtti exceptions'"
set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_PLATFORM=android-!__ANDROID_API_LEVEL!" "-DANDROID_NATIVE_API_LEVEL=!__ANDROID_API_LEVEL!"
if "%__Arch%" == "x64" (
set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=x86_64"
)
if "%__Arch%" == "x86" (
set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=x86"
)
if "%__Arch%" == "arm64" (
set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=arm64-v8a"
)
if "%__Arch%" == "arm" (
set __ExtraCmakeParams=!__ExtraCmakeParams! "-DANDROID_ABI=armeabi-v7a"
)
set __ExtraCmakeParams=!__ExtraCmakeParams! "-DCMAKE_TOOLCHAIN_FILE='%ANDROID_NDK_ROOT:\=/%/build/cmake/android.toolchain.cmake'" "-C %__repoRoot%/eng/native/tryrun.cmake"
)
:loop
if [%6] == [] goto end_loop
set __ExtraCmakeParams=%__ExtraCmakeParams% %6
shift
goto loop
:end_loop
set __ExtraCmakeParams="-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" %__ExtraCmakeParams%
set __CmdLineOptionsUpToDateFile=%__IntermediatesDir%\cmake_cmd_line.txt
set __CMakeCmdLineCache=
if not "%__ConfigureOnly%" == "1" (
REM MSBuild can't reload from a CMake reconfigure during build correctly, so only do this
REM command-line up to date check for non-VS generators.
if "%__CmakeGenerator:Visual Studio=%" == "%__CmakeGenerator%" (
if exist "%__CmdLineOptionsUpToDateFile%" (
set /p __CMakeCmdLineCache=<"%__CmdLineOptionsUpToDateFile%"
REM Strip the extra space from the end of the cached command line
if "!__ExtraCmakeParams!" == "!__CMakeCmdLineCache:~0,-1!" (
echo The CMake command line is the same as the last run. Skipping running CMake.
exit /B 0
) else (
echo The CMake command line differs from the last run. Running CMake again.
)
)
)
)
echo %CMakeToolPrefix% "%CMakePath% %__ExtraCmakeParams% --no-warn-unused-cli -G %__CmakeGenerator% -B %__IntermediatesDir% -S %__SourceDir%"
%CMakeToolPrefix% "%CMakePath%" %__ExtraCmakeParams% --no-warn-unused-cli -G "%__CmakeGenerator%" -B %__IntermediatesDir% -S %__SourceDir%
if "%errorlevel%" == "0" (
echo %__ExtraCmakeParams% > %__CmdLineOptionsUpToDateFile%
)
endlocal
exit /B %errorlevel%
:USAGE
echo "Usage..."
echo "gen-buildsys.cmd <path to top level CMakeLists.txt> <path to location for intermediate files> <VSVersion> <arch> <os>"
echo "Specify the path to the top level CMake file"
echo "Specify the VSVersion to be used, e. g. 17.0 for VS2022"
EXIT /B 1