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
22 REM Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
23 if /I "%1" == "arm_hosttools" (
24 echo Configuring x86 host tools for ARM cross build
26 REM This launches %VSINSTALLDIR%VS\vcvarsall.bat
29 REM Configure host tools for x86.
30 cmake -G %3 -DARCH:STRING=i386 %~dp0
34 REM Get the source root directory
35 set REACTOS_SOURCE_DIR=%~dp0
37 REM Set default generator
38 set CMAKE_GENERATOR="Ninja"
39 set CMAKE_GENERATOR_HOST=!CMAKE_GENERATOR!
41 REM Detect presence of cmake
42 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
44 REM Detect build environment (MinGW, VS, WDK, ...)
46 echo Detected RosBE for %ROS_ARCH%
47 set BUILD_ENVIRONMENT=MinGW
49 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
51 ) else if defined VCINSTALLDIR (
52 REM VS command prompt does not put this in environment vars
53 cl 2>&1 | find "x86" > NUL && set ARCH=i386
54 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
55 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
56 cl 2>&1 | find "15.00." > NUL && set VS_VERSION=9
57 cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10
58 cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
59 cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
60 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
61 cl 2>&1 | find "19.10." > NUL && set VS_VERSION=15
62 cl 2>&1 | find "19.11." > NUL && set VS_VERSION=15
63 cl 2>&1 | find "19.12." > NUL && set VS_VERSION=15
64 if not defined VS_VERSION (
65 echo Error: Visual Studio version too old or version detection failed.
69 set BUILD_ENVIRONMENT=VS
71 set VS_RUNTIME_CHECKS=0
72 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
74 echo Error: Unable to detect build environment. Configure script failure.
81 echo Unknown build architecture
89 REM Parse command line parameters
91 if /I "%1%" == "-DNEW_STYLE_BUILD" (
92 set NEW_STYLE_BUILD=%2
93 ) else if "%BUILD_ENVIRONMENT%" == "MinGW" (
94 if /I "%1" == "Codeblocks" (
95 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
96 ) else if /I "%1" == "Eclipse" (
97 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
98 ) else if /I "%1" == "Makefiles" (
99 set CMAKE_GENERATOR="MinGW Makefiles"
104 if /I "%1" == "CodeBlocks" (
105 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
106 ) else if /I "%1" == "Eclipse" (
107 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
108 ) else if /I "%1" == "Makefiles" (
109 set CMAKE_GENERATOR="NMake Makefiles"
110 ) else if /I "%1" == "clang" (
112 ) else if /I "%1" == "VSSolution" (
114 REM explicitly set VS version for project generator
115 if /I "%2" == "-VS_VER" (
117 echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
119 if "!VS_VERSION!" == "9" (
120 if "!ARCH!" == "amd64" (
121 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
123 set CMAKE_GENERATOR="Visual Studio 9 2008"
125 ) else if "!VS_VERSION!" == "10" (
126 if "!ARCH!" == "amd64" (
127 set CMAKE_GENERATOR="Visual Studio 10 Win64"
129 set CMAKE_GENERATOR="Visual Studio 10"
131 ) else if "!VS_VERSION!" == "11" (
132 if "!ARCH!" == "amd64" (
133 set CMAKE_GENERATOR="Visual Studio 11 Win64"
134 ) else if "!ARCH!" == "arm" (
135 set CMAKE_GENERATOR="Visual Studio 11 ARM"
136 set CMAKE_GENERATOR_HOST="Visual Studio 11"
138 set CMAKE_GENERATOR="Visual Studio 11"
140 ) else if "!VS_VERSION!" == "12" (
141 if "!ARCH!" == "amd64" (
142 set CMAKE_GENERATOR="Visual Studio 12 Win64"
143 ) else if "!ARCH!" == "arm" (
144 set CMAKE_GENERATOR="Visual Studio 12 ARM"
145 set CMAKE_GENERATOR_HOST="Visual Studio 12"
147 set CMAKE_GENERATOR="Visual Studio 12"
149 ) else if "!VS_VERSION!" == "14" (
150 if "!ARCH!" == "amd64" (
151 set CMAKE_GENERATOR="Visual Studio 14 Win64"
152 ) else if "!ARCH!" == "arm" (
153 set CMAKE_GENERATOR="Visual Studio 14 ARM"
154 set CMAKE_GENERATOR_HOST="Visual Studio 14"
156 set CMAKE_GENERATOR="Visual Studio 14"
158 ) else if "!VS_VERSION!" == "15" (
159 if "!ARCH!" == "amd64" (
160 set CMAKE_GENERATOR="Visual Studio 15 Win64"
161 ) else if "!ARCH!" == "arm" (
162 set CMAKE_GENERATOR="Visual Studio 15 ARM"
163 set CMAKE_GENERATOR_HOST="Visual Studio 15"
165 set CMAKE_GENERATOR="Visual Studio 15"
168 ) else if /I "%1" == "RTC" (
169 echo Runtime checks enabled
170 set VS_RUNTIME_CHECKS=1
176 REM Go to next parameter
181 REM Inform the user about the default build
182 if "!CMAKE_GENERATOR!" == "Ninja" (
183 echo This script defaults to Ninja. Type "configure help" for alternative options.
186 REM Create directories
187 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
188 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
189 echo Creating directories in %REACTOS_OUTPUT_PATH%
191 if not exist %REACTOS_OUTPUT_PATH% (
192 mkdir %REACTOS_OUTPUT_PATH%
194 cd %REACTOS_OUTPUT_PATH%
197 if "%NEW_STYLE_BUILD%"=="0" (
199 if not exist host-tools (
203 if not exist reactos (
207 echo Preparing host tools...
209 if EXIST CMakeCache.txt (
210 del CMakeCache.txt /q
213 set REACTOS_BUILD_TOOLS_DIR=!CD!
215 REM Use x86 for ARM host tools
216 if "%ARCH%" == "arm" (
217 REM Launch new script instance for x86 host tools configuration
218 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%
220 cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
227 echo Preparing reactos...
229 if "%NEW_STYLE_BUILD%"=="0" (
233 if EXIST CMakeCache.txt (
234 del CMakeCache.txt /q
235 del host-tools\CMakeCache.txt /q
238 if "%NEW_STYLE_BUILD%"=="0" (
239 set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%"
242 if "%BUILD_ENVIRONMENT%" == "MinGW" (
243 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
244 ) else if %USE_CLANG_CL% == 1 (
245 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%"
247 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%"
250 if "%NEW_STYLE_BUILD%"=="0" (
254 echo Configure script complete^^! Execute appropriate build commands (ex: ninja, make, nmake, etc...).
259 echo Unable to find cmake, if it is installed, check your PATH variable.