xref: /reactos/configure.cmd (revision 5100859e)
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, RTC
17    echo Cmake-options: -DVARIABLE:TYPE=VALUE
18    goto quit
19)
20
21REM Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
22if /I "%1" == "arm_hosttools" (
23    echo Configuring x86 host tools for ARM cross build
24
25    REM This launches %VSINSTALLDIR%VS\vcvarsall.bat
26    call %2 x86
27
28    REM Configure host tools for x86.
29    cmake -G %3 -DARCH:STRING=i386 %~dp0
30    exit
31)
32
33REM Get the source root directory
34set REACTOS_SOURCE_DIR=%~dp0
35
36REM Ensure there's no spaces in the source path
37echo %REACTOS_SOURCE_DIR%| find " " > NUL
38if %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.
43    goto quit
44)
45
46REM Set default generator
47set CMAKE_GENERATOR="Ninja"
48set CMAKE_GENERATOR_HOST=!CMAKE_GENERATOR!
49
50REM Detect presence of cmake
51cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
52
53REM Detect build environment (MinGW, VS, WDK, ...)
54if defined ROS_ARCH (
55    echo Detected RosBE for %ROS_ARCH%
56    set BUILD_ENVIRONMENT=MinGW
57    set ARCH=%ROS_ARCH%
58    set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
59
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 "15.00." > NUL && set VS_VERSION=9
66    cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10
67    cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
68    cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
69    cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
70    cl 2>&1 | find "19.10." > NUL && set VS_VERSION=15
71    cl 2>&1 | find "19.11." > NUL && set VS_VERSION=15
72    cl 2>&1 | find "19.12." > NUL && set VS_VERSION=15
73    cl 2>&1 | find "19.13." > NUL && set VS_VERSION=15
74    if not defined VS_VERSION (
75        echo Error: Visual Studio version too old or version detection failed.
76        goto quit
77    )
78    set BUILD_ENVIRONMENT=VS
79    set VS_SOLUTION=0
80    set VS_RUNTIME_CHECKS=0
81    echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
82) else (
83    echo Error: Unable to detect build environment. Configure script failure.
84    goto quit
85)
86
87REM Checkpoint
88if not defined ARCH (
89    echo Unknown build architecture
90    goto quit
91)
92
93set NEW_STYLE_BUILD=1
94set USE_CLANG_CL=0
95
96REM Parse command line parameters
97:repeat
98    if /I "%1" == "-DNEW_STYLE_BUILD" (
99        set NEW_STYLE_BUILD=%2
100    ) else if "%BUILD_ENVIRONMENT%" == "MinGW" (
101        if /I "%1" == "Codeblocks" (
102            set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
103        ) else if /I "%1" == "Eclipse" (
104            set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
105        ) else if /I "%1" == "Makefiles" (
106            set CMAKE_GENERATOR="MinGW Makefiles"
107        ) else if /I "%1" == "VSSolution" (
108            echo. && echo Error: Creation of VS Solution files is not supported in a MinGW environment.
109            echo Please run this command in a [Developer] Command Prompt for Visual Studio.
110            goto quit
111        ) else if /I "%1" == "RTC" (
112            echo. && echo 	Warning: RTC switch is ignored outside of a Visual Studio environment. && echo.
113        ) else if /I "%1" NEQ "" (
114            echo %1| find /I "-D" > NUL
115            if %ERRORLEVEL% == 0 (
116                REM User is passing a switch to CMake
117                REM Ignore it, and ignore the next parameter that follows
118                Shift
119            ) else (
120                echo. && echo   Warning: Unrecognized switch "%1" && echo.
121            )
122        ) else (
123            goto continue
124        )
125    ) else (
126        if /I "%1" == "CodeBlocks" (
127            set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
128        ) else if /I "%1" == "Eclipse" (
129            set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
130        ) else if /I "%1" == "Makefiles" (
131            set CMAKE_GENERATOR="NMake Makefiles"
132        ) else if /I "%1" == "clang" (
133            set USE_CLANG_CL=1
134        ) else if /I "%1" == "VSSolution" (
135            set VS_SOLUTION=1
136            REM explicitly set VS version for project generator
137            if /I "%2" == "-VS_VER" (
138                set VS_VERSION=%3
139                echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
140            )
141            if "!VS_VERSION!" == "9" (
142                if "!ARCH!" == "amd64" (
143                    set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
144                ) else (
145                    set CMAKE_GENERATOR="Visual Studio 9 2008"
146                )
147            ) else if "!VS_VERSION!" == "10" (
148                if "!ARCH!" == "amd64" (
149                    set CMAKE_GENERATOR="Visual Studio 10 Win64"
150                ) else (
151                    set CMAKE_GENERATOR="Visual Studio 10"
152                )
153            ) else if "!VS_VERSION!" == "11" (
154                if "!ARCH!" == "amd64" (
155                    set CMAKE_GENERATOR="Visual Studio 11 Win64"
156                ) else if "!ARCH!" == "arm" (
157                    set CMAKE_GENERATOR="Visual Studio 11 ARM"
158                    set CMAKE_GENERATOR_HOST="Visual Studio 11"
159                ) else (
160                    set CMAKE_GENERATOR="Visual Studio 11"
161                )
162            ) else if "!VS_VERSION!" == "12" (
163                if "!ARCH!" == "amd64" (
164                    set CMAKE_GENERATOR="Visual Studio 12 Win64"
165                ) else if "!ARCH!" == "arm" (
166                    set CMAKE_GENERATOR="Visual Studio 12 ARM"
167                    set CMAKE_GENERATOR_HOST="Visual Studio 12"
168                ) else (
169                    set CMAKE_GENERATOR="Visual Studio 12"
170                )
171            ) else if "!VS_VERSION!" == "14" (
172                if "!ARCH!" == "amd64" (
173                    set CMAKE_GENERATOR="Visual Studio 14 Win64"
174                ) else if "!ARCH!" == "arm" (
175                    set CMAKE_GENERATOR="Visual Studio 14 ARM"
176                    set CMAKE_GENERATOR_HOST="Visual Studio 14"
177                ) else (
178                    set CMAKE_GENERATOR="Visual Studio 14"
179                )
180            ) else if "!VS_VERSION!" == "15" (
181                if "!ARCH!" == "amd64" (
182                    set CMAKE_GENERATOR="Visual Studio 15 Win64"
183                ) else if "!ARCH!" == "arm" (
184                    set CMAKE_GENERATOR="Visual Studio 15 ARM"
185                    set CMAKE_GENERATOR_HOST="Visual Studio 15"
186                ) else (
187                    set CMAKE_GENERATOR="Visual Studio 15"
188                )
189            )
190        ) else if /I "%1" == "RTC" (
191            echo Runtime checks enabled
192            set VS_RUNTIME_CHECKS=1
193        ) else if /I "%1" NEQ "" (
194            echo %1| find /I "-D" > NUL
195            if %ERRORLEVEL% == 0 (
196                REM User is passing a switch to CMake
197                REM Ignore it, and ignore the next parameter that follows
198                Shift
199            ) else (
200                echo. && echo   Warning: Unrecognized switch "%1" && echo.
201            )
202        ) else (
203            goto continue
204        )
205    )
206
207    REM Go to next parameter
208    SHIFT
209    goto repeat
210:continue
211
212REM Inform the user about the default build
213if "!CMAKE_GENERATOR!" == "Ninja" (
214    echo This script defaults to Ninja. Type "configure help" for alternative options.
215)
216
217REM Create directories
218set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
219
220if "%VS_SOLUTION%" == "1" (
221    set REACTOS_OUTPUT_PATH=%REACTOS_OUTPUT_PATH%-sln
222)
223
224if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
225    set CD_SAME_AS_SOURCE=1
226    echo Creating directories in %REACTOS_OUTPUT_PATH%
227
228    if not exist %REACTOS_OUTPUT_PATH% (
229        mkdir %REACTOS_OUTPUT_PATH%
230    )
231    cd %REACTOS_OUTPUT_PATH%
232)
233
234if "%VS_SOLUTION%" == "1" (
235
236    if exist build.ninja (
237        echo. && echo Error: This directory has already been configured for ninja.
238        echo An output folder configured for ninja can't be reconfigured for VSSolution.
239        echo Use an empty folder or delete the contents of this folder, then try again.
240        goto quit
241    )
242) else if exist REACTOS.sln (
243    echo. && echo Error: This directory has already been configured for Visual Studio.
244    echo An output folder configured for VSSolution can't be reconfigured for ninja.
245    echo Use an empty folder or delete the contents of this folder, then try again. && echo.
246    goto quit
247)
248
249if "%NEW_STYLE_BUILD%"=="0" (
250
251    if not exist host-tools (
252        mkdir host-tools
253    )
254
255    if not exist reactos (
256        mkdir reactos
257    )
258
259    echo Preparing host tools...
260    cd host-tools
261    if EXIST CMakeCache.txt (
262        del CMakeCache.txt /q
263    )
264
265    set REACTOS_BUILD_TOOLS_DIR=!CD!
266
267    REM Use x86 for ARM host tools
268    if "%ARCH%" == "arm" (
269        REM Launch new script instance for x86 host tools configuration
270        start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%
271    ) else (
272        cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
273    )
274
275    cd..
276
277)
278
279echo Preparing reactos...
280
281if "%NEW_STYLE_BUILD%"=="0" (
282    cd reactos
283)
284
285if EXIST CMakeCache.txt (
286    del CMakeCache.txt /q
287    del host-tools\CMakeCache.txt /q
288)
289
290if "%NEW_STYLE_BUILD%"=="0" (
291    set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%"
292)
293
294if "%BUILD_ENVIRONMENT%" == "MinGW" (
295    cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
296) else if %USE_CLANG_CL% == 1 (
297        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%"
298) else (
299    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%"
300)
301
302if "%NEW_STYLE_BUILD%"=="0" (
303    cd..
304)
305
306if %ERRORLEVEL% NEQ 0 (
307    goto quit
308)
309
310if "%CD_SAME_AS_SOURCE%" == "1" (
311    set ENDV= from %REACTOS_OUTPUT_PATH%
312)
313
314if "%VS_SOLUTION%" == "1" (
315    set ENDV= You can now use msbuild or open REACTOS.sln%ENDV%.
316) else (
317    set ENDV= Execute appropriate build commands ^(ex: ninja, make, nmake, etc...^)%ENDV%
318)
319
320echo. && echo Configure script complete^^!%ENDV%
321
322goto quit
323
324:cmake_notfound
325echo Unable to find cmake, if it is installed, check your PATH variable.
326
327:quit
328endlocal
329exit /b
330