[CONFIGURE]: Hack-support VS15 (VS 2017)
[reactos.git] / reactos / configure.cmd
1 @echo off
2
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
9
10 REM Does the user need help?
11 if /I "%1" == "help" goto help
12 if /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, RTC
17 echo Cmake-options: -DVARIABLE:TYPE=VALUE
18 endlocal
19 exit /b
20 )
21
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
25
26 REM This launches %VSINSTALLDIR%VS\vcvarsall.bat
27 call %2 x86
28
29 REM Configure host tools for x86.
30 cmake -G %3 -DARCH:STRING=i386 %~dp0
31 exit
32 )
33
34 REM Get the source root directory
35 set REACTOS_SOURCE_DIR=%~dp0
36
37 REM Set default generator
38 set CMAKE_GENERATOR="Ninja"
39 set CMAKE_GENERATOR_HOST=!CMAKE_GENERATOR!
40
41 REM Detect presence of cmake
42 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
43
44 REM Detect build environment (MinGW, VS, WDK, ...)
45 if defined ROS_ARCH (
46 echo Detected RosBE for %ROS_ARCH%
47 set BUILD_ENVIRONMENT=MinGW
48 set ARCH=%ROS_ARCH%
49 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
50
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=14
62 if not defined VS_VERSION (
63 echo Error: Visual Studio version too old or version detection failed.
64 endlocal
65 exit /b
66 )
67 set BUILD_ENVIRONMENT=VS
68 set VS_SOLUTION=0
69 set VS_RUNTIME_CHECKS=0
70 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
71 ) else (
72 echo Error: Unable to detect build environment. Configure script failure.
73 endlocal
74 exit /b
75 )
76
77 REM Checkpoint
78 if not defined ARCH (
79 echo Unknown build architecture
80 endlocal
81 exit /b
82 )
83
84 set NEW_STYLE_BUILD=1
85
86 REM Parse command line parameters
87 :repeat
88 if /I "%1%" == "-DNEW_STYLE_BUILD" (
89 set NEW_STYLE_BUILD=%2
90 ) else if "%BUILD_ENVIRONMENT%" == "MinGW" (
91 if /I "%1" == "Codeblocks" (
92 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
93 ) else if /I "%1" == "Eclipse" (
94 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
95 ) else if /I "%1" == "Makefiles" (
96 set CMAKE_GENERATOR="MinGW Makefiles"
97 ) else if /I "%1" == "clang" (
98 set MINGW_TOOCHAIN_FILE=toolchain-clang.cmake
99 ) else (
100 goto continue
101 )
102 ) else (
103 if /I "%1" == "CodeBlocks" (
104 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
105 ) else if /I "%1" == "Eclipse" (
106 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
107 ) else if /I "%1" == "Makefiles" (
108 set CMAKE_GENERATOR="NMake Makefiles"
109 ) else if /I "%1" == "VSSolution" (
110 set VS_SOLUTION=1
111 if "!VS_VERSION!" == "9" (
112 if "!ARCH!" == "amd64" (
113 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
114 ) else (
115 set CMAKE_GENERATOR="Visual Studio 9 2008"
116 )
117 ) else if "!VS_VERSION!" == "10" (
118 if "!ARCH!" == "amd64" (
119 set CMAKE_GENERATOR="Visual Studio 10 Win64"
120 ) else (
121 set CMAKE_GENERATOR="Visual Studio 10"
122 )
123 ) else if "!VS_VERSION!" == "11" (
124 if "!ARCH!" == "amd64" (
125 set CMAKE_GENERATOR="Visual Studio 11 Win64"
126 ) else if "!ARCH!" == "arm" (
127 set CMAKE_GENERATOR="Visual Studio 11 ARM"
128 set CMAKE_GENERATOR_HOST="Visual Studio 11"
129 ) else (
130 set CMAKE_GENERATOR="Visual Studio 11"
131 )
132 ) else if "!VS_VERSION!" == "12" (
133 if "!ARCH!" == "amd64" (
134 set CMAKE_GENERATOR="Visual Studio 12 Win64"
135 ) else if "!ARCH!" == "arm" (
136 set CMAKE_GENERATOR="Visual Studio 12 ARM"
137 set CMAKE_GENERATOR_HOST="Visual Studio 12"
138 ) else (
139 set CMAKE_GENERATOR="Visual Studio 12"
140 )
141 ) else if "!VS_VERSION!" == "14" (
142 if "!ARCH!" == "amd64" (
143 set CMAKE_GENERATOR="Visual Studio 14 Win64"
144 ) else if "!ARCH!" == "arm" (
145 set CMAKE_GENERATOR="Visual Studio 14 ARM"
146 set CMAKE_GENERATOR_HOST="Visual Studio 14"
147 ) else (
148 set CMAKE_GENERATOR="Visual Studio 14"
149 )
150 )
151 ) else if /I "%1" == "RTC" (
152 echo Runtime checks enabled
153 set VS_RUNTIME_CHECKS=1
154 ) else (
155 goto continue
156 )
157 )
158
159 REM Go to next parameter
160 SHIFT
161 goto repeat
162 :continue
163
164 REM Inform the user about the default build
165 if "!CMAKE_GENERATOR!" == "Ninja" (
166 echo This script defaults to Ninja. Type "configure help" for alternative options.
167 )
168
169 REM Create directories
170 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
171 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
172 echo Creating directories in %REACTOS_OUTPUT_PATH%
173
174 if not exist %REACTOS_OUTPUT_PATH% (
175 mkdir %REACTOS_OUTPUT_PATH%
176 )
177 cd %REACTOS_OUTPUT_PATH%
178 )
179
180 if "%NEW_STYLE_BUILD%"=="0" (
181
182 if not exist host-tools (
183 mkdir host-tools
184 )
185
186 if not exist reactos (
187 mkdir reactos
188 )
189
190 echo Preparing host tools...
191 cd host-tools
192 if EXIST CMakeCache.txt (
193 del CMakeCache.txt /q
194 )
195
196 set REACTOS_BUILD_TOOLS_DIR=!CD!
197
198 REM Use x86 for ARM host tools
199 if "%ARCH%" == "arm" (
200 REM Launch new script instance for x86 host tools configuration
201 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%
202 ) else (
203 cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
204 )
205
206 cd..
207
208 )
209
210 echo Preparing reactos...
211
212 if "%NEW_STYLE_BUILD%"=="0" (
213 cd reactos
214 )
215
216 if EXIST CMakeCache.txt (
217 del CMakeCache.txt /q
218 del host-tools\CMakeCache.txt /q
219 )
220
221 if "%NEW_STYLE_BUILD%"=="0" (
222 set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%"
223 )
224
225 if "%BUILD_ENVIRONMENT%" == "MinGW" (
226 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
227 ) else (
228 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%"
229 )
230
231 if "%NEW_STYLE_BUILD%"=="0" (
232 cd..
233 )
234
235 echo Configure script complete^^! Execute appropriate build commands (ex: ninja, make, nmake, etc...).
236 endlocal
237 exit /b
238
239 :cmake_notfound
240 echo Unable to find cmake, if it is installed, check your PATH variable.
241 endlocal
242 exit /b