Sync to trunk r65566.
[reactos.git] / configure.cmd
1 @echo off
2
3 :: This is needed so as to avoid static expansion of environment variables
4 :: inside if (...) conditionals.
5 :: See http://stackoverflow.com/questions/305605/weird-scope-issue-in-bat-file
6 :: for more explanation.
7 :: Precisely needed for configuring Visual Studio Environment.
8 setlocal enabledelayedexpansion
9
10 :: 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 exit /b
19 )
20
21 :: Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
22 if /I "%1" == "arm_hosttools" (
23 echo Configuring x86 host tools for ARM cross build
24
25 :: This launches %VSINSTALLDIR%VS\vcvarsall.bat
26 call %2 x86
27
28 :: Configure host tools for x86
29 cmake -G %3 -DARCH:STRING=i386 %~dp0
30 exit
31 )
32
33 :: Get the source root directory
34 set REACTOS_SOURCE_DIR=%~dp0
35
36 :: Set default generator
37 set CMAKE_GENERATOR="Ninja"
38 set CMAKE_GENERATOR_HOST=!CMAKE_GENERATOR!
39
40 :: Detect presence of cmake
41 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
42
43 :: Detect build environment (MinGW, VS, WDK, ...)
44 if defined ROS_ARCH (
45 echo Detected RosBE for %ROS_ARCH%
46 set BUILD_ENVIRONMENT=MinGW
47 set ARCH=%ROS_ARCH%
48 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake
49
50 ) else if defined VCINSTALLDIR (
51 :: VS command prompt does not put this in environment vars
52 cl 2>&1 | find "x86" > NUL && set ARCH=i386
53 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
54 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
55 cl 2>&1 | find "15.00." > NUL && set VS_VERSION=9
56 cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10
57 cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
58 cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
59 if not defined VS_VERSION (
60 echo Error: Visual Studio version too old or version detection failed.
61 exit /b
62 )
63 set BUILD_ENVIRONMENT=VS
64 set VS_SOLUTION=0
65 set VS_RUNTIME_CHECKS=0
66 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
67 ) else (
68 echo Error: Unable to detect build environment. Configure script failure.
69 exit /b
70 )
71
72 :: Checkpoint
73 if not defined ARCH (
74 echo Unknown build architecture
75 exit /b
76 )
77
78 :: Parse command line parameters
79 :repeat
80 if "%BUILD_ENVIRONMENT%" == "MinGW" (
81 if /I "%1" == "Codeblocks" (
82 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
83 ) else if /I "%1" == "Eclipse" (
84 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
85 ) else if /I "%1" == "Makefiles" (
86 set CMAKE_GENERATOR="MinGW Makefiles"
87 ) else if /I "%1" == "clang" (
88 set MINGW_TOOCHAIN_FILE=toolchain-clang.cmake
89 ) else (
90 goto continue
91 )
92 ) else (
93 if /I "%1" == "CodeBlocks" (
94 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
95 ) else if /I "%1" == "Eclipse" (
96 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
97 ) else if /I "%1" == "Makefiles" (
98 set CMAKE_GENERATOR="NMake Makefiles"
99 ) else if /I "%1" == "VSSolution" (
100 set VS_SOLUTION=1
101 if "!VS_VERSION!" == "9" (
102 if "!ARCH!" == "amd64" (
103 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
104 ) else (
105 set CMAKE_GENERATOR="Visual Studio 9 2008"
106 )
107 ) else if "!VS_VERSION!" == "10" (
108 if "!ARCH!" == "amd64" (
109 set CMAKE_GENERATOR="Visual Studio 10 Win64"
110 ) else (
111 set CMAKE_GENERATOR="Visual Studio 10"
112 )
113 ) else if "!VS_VERSION!" == "11" (
114 if "!ARCH!" == "amd64" (
115 set CMAKE_GENERATOR="Visual Studio 11 Win64"
116 ) else if "!ARCH!" == "arm" (
117 set CMAKE_GENERATOR="Visual Studio 11 ARM"
118 set CMAKE_GENERATOR_HOST="Visual Studio 11"
119 ) else (
120 set CMAKE_GENERATOR="Visual Studio 11"
121 )
122 ) else if "!VS_VERSION!" == "12" (
123 if "!ARCH!" == "amd64" (
124 set CMAKE_GENERATOR="Visual Studio 12 Win64"
125 ) else if "!ARCH!" == "arm" (
126 set CMAKE_GENERATOR="Visual Studio 12 ARM"
127 set CMAKE_GENERATOR_HOST="Visual Studio 12"
128 ) else (
129 set CMAKE_GENERATOR="Visual Studio 12"
130 )
131 )
132 ) else if /I "%1" == "RTC" (
133 echo Runtime checks enabled
134 set VS_RUNTIME_CHECKS=1
135 ) else (
136 goto continue
137 )
138 )
139
140 :: Go to next parameter
141 SHIFT
142 goto repeat
143 :continue
144
145 :: Inform the user about the default build
146 if "!CMAKE_GENERATOR!" == "Ninja" (
147 echo This script defaults to Ninja. Type "configure help" for alternative options.
148 )
149
150 :: Create directories
151 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
152 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
153 echo Creating directories in %REACTOS_OUTPUT_PATH%
154
155 if not exist %REACTOS_OUTPUT_PATH% (
156 mkdir %REACTOS_OUTPUT_PATH%
157 )
158 cd %REACTOS_OUTPUT_PATH%
159 )
160
161 if not exist host-tools (
162 mkdir host-tools
163 )
164 if not exist reactos (
165 mkdir reactos
166 )
167
168 echo Preparing host tools...
169 cd host-tools
170 if EXIST CMakeCache.txt (
171 del CMakeCache.txt /q
172 )
173 set REACTOS_BUILD_TOOLS_DIR=%CD%
174
175 :: Use x86 for ARM host tools
176 if "%ARCH%" == "arm" (
177 :: Launch new script instance for x86 host tools configuration
178 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%
179 ) else (
180 cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
181 )
182
183 cd..
184
185 echo Preparing reactos...
186 cd reactos
187 if EXIST CMakeCache.txt (
188 del CMakeCache.txt /q
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% -DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%" %* "%REACTOS_SOURCE_DIR%"
193 ) else (
194 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%" -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
195 )
196
197 cd..
198
199 echo Configure script complete^^! Enter directories and execute appropriate build commands (ex: ninja, make, nmake, etc...).
200 exit /b
201
202 :cmake_notfound
203 echo Unable to find cmake, if it is installed, check your PATH variable.
204 exit /b