3 REM This is needed so as to avoid static expansion of environment variables
4 REM inside if (...) conditionals.
5 REM See http://stackoverflow.com/questions/305605/weird-scope-issue-in-bat-file
6 REM for more explanation.
7 REM Precisely needed for configuring Visual Studio Environment.
8 setlocal enabledelayedexpansion
10 REM Does the user need help?
11 if /I "%1" == "help" goto 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, RTC
17 echo Cmake-options: -DVARIABLE:TYPE=VALUE
21 REM Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
22 if /I "%1" == "arm_hosttools" (
23 echo Configuring x86 host tools for ARM cross build
25 REM This launches %VSINSTALLDIR%VS\vcvarsall.bat
28 REM Configure host tools for x86.
29 cmake -G %3 -DARCH:STRING=i386 %~dp0
33 REM Get the source root directory
34 set REACTOS_SOURCE_DIR=%~dp0
36 REM Ensure there's no spaces in the source path
37 echo %REACTOS_SOURCE_DIR%| find " " > NUL
38 if %ERRORLEVEL% == 0 (
39 echo. && echo Your source path contains at least one space.
40 echo This will cause problems with building.
41 echo Please rename your folders so there are no spaces in the source path,
42 echo or move your source to a different folder.
46 REM Set default generator
47 set CMAKE_GENERATOR="Ninja"
48 set CMAKE_GENERATOR_HOST=!CMAKE_GENERATOR!
50 REM Detect presence of cmake
51 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
53 REM Detect build environment (MinGW, VS, WDK, ...)
55 echo Detected RosBE for %ROS_ARCH%
56 set BUILD_ENVIRONMENT=MinGW
58 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
60 ) else if defined VCINSTALLDIR (
61 REM VS command prompt does not put this in environment vars
62 cl 2>&1 | find "x86" > NUL && set ARCH=i386
63 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
64 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
65 cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10
66 cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
67 cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
68 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
69 cl 2>&1 | find "19.10." > NUL && set VS_VERSION=15
70 cl 2>&1 | find "19.11." > NUL && set VS_VERSION=15
71 cl 2>&1 | find "19.12." > NUL && set VS_VERSION=15
72 cl 2>&1 | find "19.13." > NUL && set VS_VERSION=15
73 cl 2>&1 | find "19.14." > NUL && set VS_VERSION=15
74 cl 2>&1 | find "19.15." > NUL && set VS_VERSION=15
75 if not defined VS_VERSION (
76 echo Error: Visual Studio version too old ^(before 10 ^(2010^)^) or version detection failed.
79 set BUILD_ENVIRONMENT=VS
81 set VS_RUNTIME_CHECKS=0
82 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
84 echo Error: Unable to detect build environment. Configure script failure.
90 echo Unknown build architecture
97 REM Parse command line parameters
99 if /I "%1" == "-DNEW_STYLE_BUILD" (
100 set NEW_STYLE_BUILD=%2
101 ) else if "%BUILD_ENVIRONMENT%" == "MinGW" (
102 if /I "%1" == "Codeblocks" (
103 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
104 ) else if /I "%1" == "Eclipse" (
105 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
106 ) else if /I "%1" == "Makefiles" (
107 set CMAKE_GENERATOR="MinGW Makefiles"
108 ) else if /I "%1" == "VSSolution" (
109 echo. && echo Error: Creation of VS Solution files is not supported in a MinGW environment.
110 echo Please run this command in a [Developer] Command Prompt for Visual Studio.
112 ) else if /I "%1" == "RTC" (
113 echo. && echo Warning: RTC switch is ignored outside of a Visual Studio environment. && echo.
114 ) else if /I "%1" NEQ "" (
115 echo %1| find /I "-D" > NUL
116 if %ERRORLEVEL% == 0 (
117 REM User is passing a switch to CMake
118 REM Ignore it, and ignore the next parameter that follows
121 echo. && echo Warning: Unrecognized switch "%1" && echo.
127 if /I "%1" == "CodeBlocks" (
128 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
129 ) else if /I "%1" == "Eclipse" (
130 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
131 ) else if /I "%1" == "Makefiles" (
132 set CMAKE_GENERATOR="NMake Makefiles"
133 ) else if /I "%1" == "clang" (
135 ) else if /I "%1" == "VSSolution" (
137 REM explicitly set VS version for project generator
138 if /I "%2" == "-VS_VER" (
140 echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
142 if "!VS_VERSION!" == "10" (
143 if "!ARCH!" == "amd64" (
144 set CMAKE_GENERATOR="Visual Studio 10 Win64"
146 set CMAKE_GENERATOR="Visual Studio 10"
148 ) else if "!VS_VERSION!" == "11" (
149 if "!ARCH!" == "amd64" (
150 set CMAKE_GENERATOR="Visual Studio 11 Win64"
151 ) else if "!ARCH!" == "arm" (
152 set CMAKE_GENERATOR="Visual Studio 11 ARM"
153 set CMAKE_GENERATOR_HOST="Visual Studio 11"
155 set CMAKE_GENERATOR="Visual Studio 11"
157 ) else if "!VS_VERSION!" == "12" (
158 if "!ARCH!" == "amd64" (
159 set CMAKE_GENERATOR="Visual Studio 12 Win64"
160 ) else if "!ARCH!" == "arm" (
161 set CMAKE_GENERATOR="Visual Studio 12 ARM"
162 set CMAKE_GENERATOR_HOST="Visual Studio 12"
164 set CMAKE_GENERATOR="Visual Studio 12"
166 ) else if "!VS_VERSION!" == "14" (
167 if "!ARCH!" == "amd64" (
168 set CMAKE_GENERATOR="Visual Studio 14 Win64"
169 ) else if "!ARCH!" == "arm" (
170 set CMAKE_GENERATOR="Visual Studio 14 ARM"
171 set CMAKE_GENERATOR_HOST="Visual Studio 14"
173 set CMAKE_GENERATOR="Visual Studio 14"
175 ) else if "!VS_VERSION!" == "15" (
176 if "!ARCH!" == "amd64" (
177 set CMAKE_GENERATOR="Visual Studio 15 Win64"
178 ) else if "!ARCH!" == "arm" (
179 set CMAKE_GENERATOR="Visual Studio 15 ARM"
180 set CMAKE_GENERATOR_HOST="Visual Studio 15"
182 set CMAKE_GENERATOR="Visual Studio 15"
185 ) else if /I "%1" == "RTC" (
186 echo Runtime checks enabled
187 set VS_RUNTIME_CHECKS=1
188 ) else if /I "%1" NEQ "" (
189 echo %1| find /I "-D" > NUL
190 if %ERRORLEVEL% == 0 (
191 REM User is passing a switch to CMake
192 REM Ignore it, and ignore the next parameter that follows
195 echo. && echo Warning: Unrecognized switch "%1" && echo.
202 REM Go to next parameter
207 REM Inform the user about the default build
208 if "!CMAKE_GENERATOR!" == "Ninja" (
209 echo This script defaults to Ninja. Type "configure help" for alternative options.
212 REM Create directories
213 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
215 if "%VS_SOLUTION%" == "1" (
216 set REACTOS_OUTPUT_PATH=%REACTOS_OUTPUT_PATH%-sln
219 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
220 set CD_SAME_AS_SOURCE=1
221 echo Creating directories in %REACTOS_OUTPUT_PATH%
223 if not exist %REACTOS_OUTPUT_PATH% (
224 mkdir %REACTOS_OUTPUT_PATH%
226 cd %REACTOS_OUTPUT_PATH%
229 if "%VS_SOLUTION%" == "1" (
231 if exist build.ninja (
232 echo. && echo Error: This directory has already been configured for ninja.
233 echo An output folder configured for ninja can't be reconfigured for VSSolution.
234 echo Use an empty folder or delete the contents of this folder, then try again.
237 ) else if exist REACTOS.sln (
238 echo. && echo Error: This directory has already been configured for Visual Studio.
239 echo An output folder configured for VSSolution can't be reconfigured for ninja.
240 echo Use an empty folder or delete the contents of this folder, then try again. && echo.
244 if "%NEW_STYLE_BUILD%"=="0" (
246 if not exist host-tools (
250 if not exist reactos (
254 echo Preparing host tools...
256 if EXIST CMakeCache.txt (
257 del CMakeCache.txt /q
260 set REACTOS_BUILD_TOOLS_DIR=!CD!
262 REM Use x86 for ARM host tools
263 if "%ARCH%" == "arm" (
264 REM Launch new script instance for x86 host tools configuration
265 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%
267 cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
274 echo Preparing reactos...
276 if "%NEW_STYLE_BUILD%"=="0" (
280 if EXIST CMakeCache.txt (
281 del CMakeCache.txt /q
282 del host-tools\CMakeCache.txt /q
285 if "%NEW_STYLE_BUILD%"=="0" (
286 set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%"
289 if "%BUILD_ENVIRONMENT%" == "MinGW" (
290 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
291 ) else if %USE_CLANG_CL% == 1 (
292 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
294 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
297 if "%NEW_STYLE_BUILD%"=="0" (
301 if %ERRORLEVEL% NEQ 0 (
305 if "%CD_SAME_AS_SOURCE%" == "1" (
306 set ENDV= from %REACTOS_OUTPUT_PATH%
309 if "%VS_SOLUTION%" == "1" (
310 set ENDV= You can now use msbuild or open REACTOS.sln%ENDV%.
312 set ENDV= Execute appropriate build commands ^(ex: ninja, make, nmake, etc...^)%ENDV%
315 echo. && echo Configure script complete^^!%ENDV%
320 echo Unable to find cmake, if it is installed, check your PATH variable.