Reactos
1@echo off
2
3REM This is needed so as to avoid static expansion of environment variables
4REM inside if (...) conditionals.
5REM See http://stackoverflow.com/questions/305605/weird-scope-issue-in-bat-file
6REM for more explanation.
7REM Precisely needed for configuring Visual Studio Environment.
8setlocal enabledelayedexpansion
9
10REM Does the user need help?
11if /I "%1" == "help" goto help
12if /I "%1" == "/?" (
13:help
14 echo Help for configure script
15 echo Syntax: path\to\source\configure.cmd [script-options] [Cmake-options]
16 echo Available script-options: Codeblocks, Eclipse, Makefiles, clang, VSSolution
17 echo Cmake-options: -DVARIABLE:TYPE=VALUE
18 goto quit
19)
20
21REM Get the source root directory
22set REACTOS_SOURCE_DIR=%~dp0
23
24REM Ensure there's no spaces in the source path
25echo %REACTOS_SOURCE_DIR%| find " " > NUL
26if %ERRORLEVEL% == 0 (
27 echo. & echo Your source path contains at least one space.
28 echo This will cause problems with building.
29 echo Please rename your folders so there are no spaces in the source path,
30 echo or move your source to a different folder.
31 goto quit
32)
33
34REM Set default generator
35set CMAKE_GENERATOR="Ninja"
36set CMAKE_ARCH=
37
38REM Detect presence of cmake
39cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
40
41REM Detect build environment (MinGW, VS, WDK, ...)
42if defined ROS_ARCH (
43 echo Detected RosBE for %ROS_ARCH%
44 set BUILD_ENVIRONMENT=MinGW
45 set ARCH=%ROS_ARCH%
46 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
47
48) else if defined VCINSTALLDIR (
49 REM VS command prompt does not put this in environment vars
50 cl 2>&1 | find "x86" > NUL && set ARCH=i386
51 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
52 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
53 cl 2>&1 | find "ARM64" > NUL && set ARCH=arm64
54 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
55 cl 2>&1 | findstr /R /c:"19\.1.\." > NUL && set VS_VERSION=15
56 cl 2>&1 | findstr /R /c:"19\.2.\." > NUL && set VS_VERSION=16
57 cl 2>&1 | findstr /R /c:"19\.3.\." > NUL && set VS_VERSION=17
58 cl 2>&1 | findstr /R /c:"19\.4.\." > NUL && set VS_VERSION=17
59 cl 2>&1 | findstr /R /c:"19\.5.\." > NUL && set VS_VERSION=18
60 if not defined VS_VERSION (
61 echo Error: Visual Studio version too old ^(before 14 ^(2015^)^) or version detection failed.
62 goto quit
63 )
64 set BUILD_ENVIRONMENT=VS
65 set VS_SOLUTION=0
66 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
67) else (
68 echo Error: Unable to detect build environment. Configure script failure.
69 goto quit
70)
71
72REM Checkpoint
73if not defined ARCH (
74 echo Unknown build architecture.
75 goto quit
76)
77
78set USE_CLANG_CL=0
79
80REM Parse command line parameters
81set CMAKE_PARAMS=
82set REMAINING=%*
83:repeat
84
85 REM Extract a parameter without removing '='
86 for /f "tokens=1*" %%a in ("%REMAINING%") do (
87 set "PARAM=%%a"
88 set REMAINING=%%b
89 )
90
91 if "%BUILD_ENVIRONMENT%" == "MinGW" (
92 if /I "!PARAM!" == "Codeblocks" (
93 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
94 ) else if /I "!PARAM!" == "Eclipse" (
95 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
96 ) else if /I "!PARAM!" == "Makefiles" (
97 set CMAKE_GENERATOR="MinGW Makefiles"
98 ) else if /I "!PARAM!" == "Ninja" (
99 set CMAKE_GENERATOR="Ninja"
100 ) else if /I "!PARAM!" == "VSSolution" (
101 echo. & echo Error: Creation of VS Solution files is not supported in a MinGW environment.
102 echo Please run this command in a [Developer] Command Prompt for Visual Studio.
103 goto quit
104 ) else if /I "!PARAM:~0,2!" == "-D" (
105 REM User is passing a switch to CMake
106 set "CMAKE_PARAMS=%CMAKE_PARAMS% !PARAM!"
107 ) else (
108 echo. & echo Warning: Unrecognized switch "!PARAM!" & echo.
109 )
110 ) else (
111 if /I "!PARAM!" == "CodeBlocks" (
112 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
113 ) else if /I "!PARAM!" == "Eclipse" (
114 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
115 ) else if /I "!PARAM!" == "Makefiles" (
116 set CMAKE_GENERATOR="NMake Makefiles"
117 ) else if /I "!PARAM!" == "Ninja" (
118 set CMAKE_GENERATOR="Ninja"
119 ) else if /I "!PARAM!" == "clang" (
120 set USE_CLANG_CL=1
121 ) else if /I "!PARAM!" == "VSSolution" (
122 set VS_SOLUTION=1
123 REM explicitly set VS version for project generator
124 for /f "tokens=1*" %%a in ("%REMAINING%") do (
125 set PARAM=%%a
126 set REMAINING2=%%b
127 )
128 if /I "!PARAM!" == "-VS_VER" (
129 for /f "tokens=1*" %%a in ("!REMAINING2!") do (
130 set VS_VERSION=%%a
131 set REMAINING=%%b
132 )
133 echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
134 )
135 set CMAKE_GENERATOR="Visual Studio !VS_VERSION!"
136 if "!ARCH!" == "i386" (
137 set CMAKE_ARCH=-A Win32
138 ) else if "!ARCH!" == "amd64" (
139 set CMAKE_ARCH=-A x64
140 ) else if "!ARCH!" == "arm" (
141 set CMAKE_ARCH=-A ARM
142 ) else if "!ARCH!" == "arm64" (
143 set CMAKE_ARCH=-A ARM64
144 )
145 ) else if /I "!PARAM:~0,2!" == "-D" (
146 REM User is passing a switch to CMake
147 set "CMAKE_PARAMS=%CMAKE_PARAMS% !PARAM!"
148 ) else (
149 echo. & echo Warning: Unrecognized switch "!PARAM!" & echo.
150 )
151 )
152
153 REM Go to next parameter
154 if defined REMAINING goto repeat
155
156REM Inform the user about the default build
157if "!CMAKE_GENERATOR!" == "Ninja" (
158 echo This script defaults to Ninja. Type "configure help" for alternative options.
159)
160
161REM Display information
162echo Configuring a new ReactOS build on:
163(for /f "delims=" %%x in ('ver') do @echo %%x) & echo.
164
165REM Create directories
166set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
167
168if "%VS_SOLUTION%" == "1" (
169 set REACTOS_OUTPUT_PATH=%REACTOS_OUTPUT_PATH%-sln
170)
171
172if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
173 set CD_SAME_AS_SOURCE=1
174 echo Creating directories in %REACTOS_OUTPUT_PATH%
175
176 if not exist %REACTOS_OUTPUT_PATH% (
177 mkdir %REACTOS_OUTPUT_PATH%
178 )
179 cd %REACTOS_OUTPUT_PATH%
180)
181
182if "%VS_SOLUTION%" == "1" (
183 if exist build.ninja (
184 echo. & echo Error: This directory has already been configured for ninja.
185 echo An output folder configured for ninja can't be reconfigured for VSSolution.
186 echo Use an empty folder or delete the contents of this folder, then try again.
187 goto quit
188 )
189) else if exist REACTOS.sln (
190 echo. & echo Error: This directory has already been configured for Visual Studio.
191 echo An output folder configured for VSSolution can't be reconfigured for ninja.
192 echo Use an empty folder or delete the contents of this folder, then try again. & echo.
193 goto quit
194)
195
196
197if EXIST CMakeCache.txt (
198 del /q CMakeCache.txt
199)
200
201if "%BUILD_ENVIRONMENT%" == "MinGW" (
202 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %CMAKE_PARAMS% "%REACTOS_SOURCE_DIR%"
203) else if %USE_CLANG_CL% == 1 (
204 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 %CMAKE_PARAMS% "%REACTOS_SOURCE_DIR%"
205) else (
206 cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %CMAKE_PARAMS% "%REACTOS_SOURCE_DIR%"
207)
208
209if %ERRORLEVEL% NEQ 0 (
210 goto quit
211)
212
213if "%CD_SAME_AS_SOURCE%" == "1" (
214 set ENDV= from %REACTOS_OUTPUT_PATH%
215)
216
217if "%VS_SOLUTION%" == "1" (
218 set ENDV= You can now use msbuild or open REACTOS.sln%ENDV%
219) else (
220 set ENDV= Execute appropriate build commands ^(e.g. ninja, make, nmake, etc.^)%ENDV%
221)
222
223echo. & echo Configure script complete^^!%ENDV%
224
225goto quit
226
227:cmake_notfound
228echo Unable to find cmake. If it is installed, check your PATH variable.
229
230:quit
231endlocal
232exit /b