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