[LOCALSPL_APITEST]
[reactos.git] / reactos / 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 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
60 if not defined VS_VERSION (
61 echo Error: Visual Studio version too old or version detection failed.
62 exit /b
63 )
64 set BUILD_ENVIRONMENT=VS
65 set VS_SOLUTION=0
66 set VS_RUNTIME_CHECKS=0
67 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
68 ) else (
69 echo Error: Unable to detect build environment. Configure script failure.
70 exit /b
71 )
72
73 :: Checkpoint
74 if not defined ARCH (
75 echo Unknown build architecture
76 exit /b
77 )
78
79 :: 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" == "clang" (
89 set MINGW_TOOCHAIN_FILE=toolchain-clang.cmake
90 ) else (
91 goto continue
92 )
93 ) else (
94 if /I "%1" == "CodeBlocks" (
95 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
96 ) else if /I "%1" == "Eclipse" (
97 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
98 ) else if /I "%1" == "Makefiles" (
99 set CMAKE_GENERATOR="NMake Makefiles"
100 ) else if /I "%1" == "VSSolution" (
101 set VS_SOLUTION=1
102 if "!VS_VERSION!" == "9" (
103 if "!ARCH!" == "amd64" (
104 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
105 ) else (
106 set CMAKE_GENERATOR="Visual Studio 9 2008"
107 )
108 ) else if "!VS_VERSION!" == "10" (
109 if "!ARCH!" == "amd64" (
110 set CMAKE_GENERATOR="Visual Studio 10 Win64"
111 ) else (
112 set CMAKE_GENERATOR="Visual Studio 10"
113 )
114 ) else if "!VS_VERSION!" == "11" (
115 if "!ARCH!" == "amd64" (
116 set CMAKE_GENERATOR="Visual Studio 11 Win64"
117 ) else if "!ARCH!" == "arm" (
118 set CMAKE_GENERATOR="Visual Studio 11 ARM"
119 set CMAKE_GENERATOR_HOST="Visual Studio 11"
120 ) else (
121 set CMAKE_GENERATOR="Visual Studio 11"
122 )
123 ) else if "!VS_VERSION!" == "12" (
124 if "!ARCH!" == "amd64" (
125 set CMAKE_GENERATOR="Visual Studio 12 Win64"
126 ) else if "!ARCH!" == "arm" (
127 set CMAKE_GENERATOR="Visual Studio 12 ARM"
128 set CMAKE_GENERATOR_HOST="Visual Studio 12"
129 ) else (
130 set CMAKE_GENERATOR="Visual Studio 12"
131 )
132 )
133 ) else if /I "%1" == "RTC" (
134 echo Runtime checks enabled
135 set VS_RUNTIME_CHECKS=1
136 ) else (
137 goto continue
138 )
139 )
140
141 :: Go to next parameter
142 SHIFT
143 goto repeat
144 :continue
145
146 :: Inform the user about the default build
147 if "!CMAKE_GENERATOR!" == "Ninja" (
148 echo This script defaults to Ninja. Type "configure help" for alternative options.
149 )
150
151 :: Create directories
152 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
153 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
154 echo Creating directories in %REACTOS_OUTPUT_PATH%
155
156 if not exist %REACTOS_OUTPUT_PATH% (
157 mkdir %REACTOS_OUTPUT_PATH%
158 )
159 cd %REACTOS_OUTPUT_PATH%
160 )
161
162 if not exist host-tools (
163 mkdir host-tools
164 )
165 if not exist reactos (
166 mkdir reactos
167 )
168
169 echo Preparing host tools...
170 cd host-tools
171 if EXIST CMakeCache.txt (
172 del CMakeCache.txt /q
173 )
174 set REACTOS_BUILD_TOOLS_DIR=%CD%
175
176 :: Use x86 for ARM host tools
177 if "%ARCH%" == "arm" (
178 :: Launch new script instance for x86 host tools configuration
179 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%
180 ) else (
181 cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
182 )
183
184 cd..
185
186 echo Preparing reactos...
187 cd reactos
188 if EXIST CMakeCache.txt (
189 del CMakeCache.txt /q
190 )
191
192 if "%BUILD_ENVIRONMENT%" == "MinGW" (
193 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%"
194 ) else (
195 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%"
196 )
197
198 cd..
199
200 echo Configure script complete^^! Enter directories and execute appropriate build commands (ex: ninja, make, nmake, etc...).
201 exit /b
202
203 :cmake_notfound
204 echo Unable to find cmake, if it is installed, check your PATH variable.
205 exit /b