[HDAUDBUS] Build a device instance ID from Codec & node number. CORE-13702
[reactos.git] / 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 goto quit
19 )
20
21 REM Get the source root directory
22 set REACTOS_SOURCE_DIR=%~dp0
23
24 REM Ensure there's no spaces in the source path
25 echo %REACTOS_SOURCE_DIR%| find " " > NUL
26 if %ERRORLEVEL% == 0 (
27 echo. && echo Your source path contains at least one space.
28 echo This will cause problems with building.
29 echo Please rename your folders so there are no spaces in the source path,
30 echo or move your source to a different folder.
31 goto quit
32 )
33
34 REM Set default generator
35 set CMAKE_GENERATOR="Ninja"
36 set CMAKE_ARCH=
37
38 REM Detect presence of cmake
39 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
40
41 REM Detect build environment (MinGW, VS, WDK, ...)
42 if defined ROS_ARCH (
43 echo Detected RosBE for %ROS_ARCH%
44 set BUILD_ENVIRONMENT=MinGW
45 set ARCH=%ROS_ARCH%
46 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
47
48 ) else if defined VCINSTALLDIR (
49 REM VS command prompt does not put this in environment vars
50 cl 2>&1 | find "x86" > NUL && set ARCH=i386
51 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
52 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
53 cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10
54 cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
55 cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
56 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
57 cl 2>&1 | find "19.10." > NUL && set VS_VERSION=15
58 cl 2>&1 | find "19.11." > NUL && set VS_VERSION=15
59 cl 2>&1 | find "19.12." > NUL && set VS_VERSION=15
60 cl 2>&1 | find "19.13." > NUL && set VS_VERSION=15
61 cl 2>&1 | find "19.14." > NUL && set VS_VERSION=15
62 cl 2>&1 | find "19.15." > NUL && set VS_VERSION=15
63 cl 2>&1 | find "19.16." > NUL && set VS_VERSION=15
64 cl 2>&1 | find "19.20." > NUL && set VS_VERSION=16
65 cl 2>&1 | find "19.21." > NUL && set VS_VERSION=16
66 cl 2>&1 | find "19.22." > NUL && set VS_VERSION=16
67 cl 2>&1 | find "19.23." > NUL && set VS_VERSION=16
68 if not defined VS_VERSION (
69 echo Error: Visual Studio version too old ^(before 10 ^(2010^)^) or version detection failed.
70 goto quit
71 )
72 set BUILD_ENVIRONMENT=VS
73 set VS_SOLUTION=0
74 set VS_RUNTIME_CHECKS=0
75 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
76 ) else (
77 echo Error: Unable to detect build environment. Configure script failure.
78 goto quit
79 )
80
81 REM Checkpoint
82 if not defined ARCH (
83 echo Unknown build architecture
84 goto quit
85 )
86
87 set USE_CLANG_CL=0
88
89 REM Parse command line parameters
90 :repeat
91 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" == "VSSolution" (
99 echo. && echo Error: Creation of VS Solution files is not supported in a MinGW environment.
100 echo Please run this command in a [Developer] Command Prompt for Visual Studio.
101 goto quit
102 ) else if /I "%1" == "RTC" (
103 echo. && echo Warning: RTC switch is ignored outside of a Visual Studio environment. && echo.
104 ) else if /I "%1" NEQ "" (
105 echo %1| find /I "-D" > NUL
106 if %ERRORLEVEL% == 0 (
107 REM User is passing a switch to CMake
108 REM Ignore it, and ignore the next parameter that follows
109 Shift
110 ) else (
111 echo. && echo Warning: Unrecognized switch "%1" && echo.
112 )
113 ) else (
114 goto continue
115 )
116 ) else (
117 if /I "%1" == "CodeBlocks" (
118 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
119 ) else if /I "%1" == "Eclipse" (
120 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
121 ) else if /I "%1" == "Makefiles" (
122 set CMAKE_GENERATOR="NMake Makefiles"
123 ) else if /I "%1" == "clang" (
124 set USE_CLANG_CL=1
125 ) else if /I "%1" == "VSSolution" (
126 set VS_SOLUTION=1
127 REM explicitly set VS version for project generator
128 if /I "%2" == "-VS_VER" (
129 set VS_VERSION=%3
130 echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
131 )
132 set CMAKE_GENERATOR="Visual Studio !VS_VERSION!"
133 if "!ARCH!" == "i386" (
134 set CMAKE_ARCH=-A Win32
135 ) else if "!ARCH!" == "amd64" (
136 set CMAKE_ARCH=-A x64
137 ) else if "!ARCH!" == "arm" (
138 set CMAKE_ARCH=-A ARM
139 )
140 ) else if /I "%1" == "RTC" (
141 echo Runtime checks enabled
142 set VS_RUNTIME_CHECKS=1
143 ) else if /I "%1" NEQ "" (
144 echo %1| find /I "-D" > NUL
145 if %ERRORLEVEL% == 0 (
146 REM User is passing a switch to CMake
147 REM Ignore it, and ignore the next parameter that follows
148 Shift
149 ) else (
150 echo. && echo Warning: Unrecognized switch "%1" && echo.
151 )
152 ) else (
153 goto continue
154 )
155 )
156
157 REM Go to next parameter
158 SHIFT
159 goto repeat
160 :continue
161
162 REM Inform the user about the default build
163 if "!CMAKE_GENERATOR!" == "Ninja" (
164 echo This script defaults to Ninja. Type "configure help" for alternative options.
165 )
166
167 REM Create directories
168 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
169
170 if "%VS_SOLUTION%" == "1" (
171 set REACTOS_OUTPUT_PATH=%REACTOS_OUTPUT_PATH%-sln
172 )
173
174 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
175 set CD_SAME_AS_SOURCE=1
176 echo Creating directories in %REACTOS_OUTPUT_PATH%
177
178 if not exist %REACTOS_OUTPUT_PATH% (
179 mkdir %REACTOS_OUTPUT_PATH%
180 )
181 cd %REACTOS_OUTPUT_PATH%
182 )
183
184 if "%VS_SOLUTION%" == "1" (
185
186 if exist build.ninja (
187 echo. && echo Error: This directory has already been configured for ninja.
188 echo An output folder configured for ninja can't be reconfigured for VSSolution.
189 echo Use an empty folder or delete the contents of this folder, then try again.
190 goto quit
191 )
192 ) else if exist REACTOS.sln (
193 echo. && echo Error: This directory has already been configured for Visual Studio.
194 echo An output folder configured for VSSolution can't be reconfigured for ninja.
195 echo Use an empty folder or delete the contents of this folder, then try again. && echo.
196 goto quit
197 )
198
199 echo Preparing reactos...
200
201 if EXIST CMakeCache.txt (
202 del CMakeCache.txt /q
203 )
204
205
206 if "%BUILD_ENVIRONMENT%" == "MinGW" (
207 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
208 ) else if %USE_CLANG_CL% == 1 (
209 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%"
210 ) else (
211 cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
212 )
213
214 if %ERRORLEVEL% NEQ 0 (
215 goto quit
216 )
217
218 if "%CD_SAME_AS_SOURCE%" == "1" (
219 set ENDV= from %REACTOS_OUTPUT_PATH%
220 )
221
222 if "%VS_SOLUTION%" == "1" (
223 set ENDV= You can now use msbuild or open REACTOS.sln%ENDV%.
224 ) else (
225 set ENDV= Execute appropriate build commands ^(ex: ninja, make, nmake, etc...^)%ENDV%
226 )
227
228 echo. && echo Configure script complete^^!%ENDV%
229
230 goto quit
231
232 :cmake_notfound
233 echo Unable to find cmake, if it is installed, check your PATH variable.
234
235 :quit
236 endlocal
237 exit /b