[CMAKE][CONFIGURE] Enable runtime checks on MSVC by default.
[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
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 | findstr /R /c:"19\.1.\." > NUL && set VS_VERSION=15
58 cl 2>&1 | findstr /R /c:"19\.2.\." > NUL && set VS_VERSION=16
59 if not defined VS_VERSION (
60 echo Error: Visual Studio version too old ^(before 10 ^(2010^)^) or version detection failed.
61 goto quit
62 )
63 set BUILD_ENVIRONMENT=VS
64 set VS_SOLUTION=0
65 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
66 ) else (
67 echo Error: Unable to detect build environment. Configure script failure.
68 goto quit
69 )
70
71 REM Checkpoint
72 if not defined ARCH (
73 echo Unknown build architecture
74 goto quit
75 )
76
77 set USE_CLANG_CL=0
78
79 REM Parse command line parameters
80 :repeat
81 if "%BUILD_ENVIRONMENT%" == "MinGW" (
82 if /I "%1" == "Codeblocks" (
83 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
84 ) else if /I "%1" == "Eclipse" (
85 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
86 ) else if /I "%1" == "Makefiles" (
87 set CMAKE_GENERATOR="MinGW Makefiles"
88 ) else if /I "%1" == "VSSolution" (
89 echo. && echo Error: Creation of VS Solution files is not supported in a MinGW environment.
90 echo Please run this command in a [Developer] Command Prompt for Visual Studio.
91 goto quit
92 ) else if /I "%1" NEQ "" (
93 echo %1| find /I "-D" > NUL
94 if %ERRORLEVEL% == 0 (
95 REM User is passing a switch to CMake
96 REM Ignore it, and ignore the next parameter that follows
97 Shift
98 ) else (
99 echo. && echo Warning: Unrecognized switch "%1" && echo.
100 )
101 ) else (
102 goto continue
103 )
104 ) else (
105 if /I "%1" == "CodeBlocks" (
106 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
107 ) else if /I "%1" == "Eclipse" (
108 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
109 ) else if /I "%1" == "Makefiles" (
110 set CMAKE_GENERATOR="NMake Makefiles"
111 ) else if /I "%1" == "clang" (
112 set USE_CLANG_CL=1
113 ) else if /I "%1" == "VSSolution" (
114 set VS_SOLUTION=1
115 REM explicitly set VS version for project generator
116 if /I "%2" == "-VS_VER" (
117 set VS_VERSION=%3
118 echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
119 )
120 set CMAKE_GENERATOR="Visual Studio !VS_VERSION!"
121 if "!ARCH!" == "i386" (
122 set CMAKE_ARCH=-A Win32
123 ) else if "!ARCH!" == "amd64" (
124 set CMAKE_ARCH=-A x64
125 ) else if "!ARCH!" == "arm" (
126 set CMAKE_ARCH=-A ARM
127 )
128 ) else if /I "%1" NEQ "" (
129 echo %1| find /I "-D" > NUL
130 if %ERRORLEVEL% == 0 (
131 REM User is passing a switch to CMake
132 REM Ignore it, and ignore the next parameter that follows
133 Shift
134 ) else (
135 echo. && echo Warning: Unrecognized switch "%1" && echo.
136 )
137 ) else (
138 goto continue
139 )
140 )
141
142 REM Go to next parameter
143 SHIFT
144 goto repeat
145 :continue
146
147 REM Inform the user about the default build
148 if "!CMAKE_GENERATOR!" == "Ninja" (
149 echo This script defaults to Ninja. Type "configure help" for alternative options.
150 )
151
152 REM Create directories
153 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
154
155 if "%VS_SOLUTION%" == "1" (
156 set REACTOS_OUTPUT_PATH=%REACTOS_OUTPUT_PATH%-sln
157 )
158
159 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
160 set CD_SAME_AS_SOURCE=1
161 echo Creating directories in %REACTOS_OUTPUT_PATH%
162
163 if not exist %REACTOS_OUTPUT_PATH% (
164 mkdir %REACTOS_OUTPUT_PATH%
165 )
166 cd %REACTOS_OUTPUT_PATH%
167 )
168
169 if "%VS_SOLUTION%" == "1" (
170
171 if exist build.ninja (
172 echo. && echo Error: This directory has already been configured for ninja.
173 echo An output folder configured for ninja can't be reconfigured for VSSolution.
174 echo Use an empty folder or delete the contents of this folder, then try again.
175 goto quit
176 )
177 ) else if exist REACTOS.sln (
178 echo. && echo Error: This directory has already been configured for Visual Studio.
179 echo An output folder configured for VSSolution can't be reconfigured for ninja.
180 echo Use an empty folder or delete the contents of this folder, then try again. && echo.
181 goto quit
182 )
183
184 echo Preparing reactos...
185
186 if EXIST CMakeCache.txt (
187 del CMakeCache.txt /q
188 )
189
190
191 if "%BUILD_ENVIRONMENT%" == "MinGW" (
192 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
193 ) else if %USE_CLANG_CL% == 1 (
194 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 %* "%REACTOS_SOURCE_DIR%"
195 ) else (
196 cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
197 )
198
199 if %ERRORLEVEL% NEQ 0 (
200 goto quit
201 )
202
203 if "%CD_SAME_AS_SOURCE%" == "1" (
204 set ENDV= from %REACTOS_OUTPUT_PATH%
205 )
206
207 if "%VS_SOLUTION%" == "1" (
208 set ENDV= You can now use msbuild or open REACTOS.sln%ENDV%.
209 ) else (
210 set ENDV= Execute appropriate build commands ^(ex: ninja, make, nmake, etc...^)%ENDV%
211 )
212
213 echo. && echo Configure script complete^^!%ENDV%
214
215 goto quit
216
217 :cmake_notfound
218 echo Unable to find cmake, if it is installed, check your PATH variable.
219
220 :quit
221 endlocal
222 exit /b