Synchronize with trunk r58457.
[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 :: Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
11 if /I "%1" == "arm_hosttools" (
12 echo Configuring x86 host tools for ARM cross build
13
14 :: This launches %VSINSTALLDIR%VS\vcvarsall.bat
15 call %2 x86
16
17 :: Configure host tools for x86
18 cmake -G %3 -DARCH=i386 %~dp0
19 exit
20 )
21
22 :: Get the source root directory
23 set REACTOS_SOURCE_DIR=%~dp0
24 set USE_NMAKE=0
25
26 :: Detect presence of cmake
27 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
28
29 :: Detect build environment (MinGW, VS, WDK, ...)
30 if defined ROS_ARCH (
31 echo Detected RosBE for %ROS_ARCH%
32 set BUILD_ENVIRONMENT=MinGW
33 set ARCH=%ROS_ARCH%
34 if /I "%1" == "Codeblocks" (
35 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
36 ) else if /I "%1" == "Eclipse" (
37 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
38 ) else if /I "%1" == "Ninja" (
39 set CMAKE_GENERATOR="Ninja"
40 ) else (
41 set CMAKE_GENERATOR="MinGW Makefiles"
42 )
43
44 ) else if defined DDK_TARGET_OS (
45 echo Detected DDK/WDK for %DDK_TARGET_OS%-%_BUILDARCH%%
46 set BUILD_ENVIRONMENT=WDK
47 if "%_BUILDARCH%" == "x86" (
48 set ARCH=i386
49 ) else if "%_BUILDARCH%" == "AMD64" (
50 set ARCH=amd64
51 )
52 set USE_NMAKE=1
53 set USE_WDK_HEADERS=0
54
55 ) else if defined VCINSTALLDIR (
56 :: VS command prompt does not put this in environment vars
57 cl 2>&1 | find "x86" > NUL && set ARCH=i386
58 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
59 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
60 cl 2>&1 | find "14." > NUL && set BUILD_ENVIRONMENT=VS8
61 cl 2>&1 | find "15." > NUL && set BUILD_ENVIRONMENT=VS9
62 cl 2>&1 | find "16." > NUL && set BUILD_ENVIRONMENT=VS10
63 cl 2>&1 | find "17." > NUL && set BUILD_ENVIRONMENT=VS11
64 if not defined BUILD_ENVIRONMENT (
65 echo Error: Visual Studio version too old or version detection failed.
66 exit /b
67 )
68
69 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!-!ARCH!
70 if /I "%1" == "VSSolution" (
71 if "!BUILD_ENVIRONMENT!" == "VS8" (
72 if "!ARCH!" == "amd64" (
73 set CMAKE_GENERATOR="Visual Studio 8 2005 Win64"
74 ) else (
75 set CMAKE_GENERATOR="Visual Studio 8 2005"
76 )
77 ) else if "!BUILD_ENVIRONMENT!" == "VS9" (
78 if "!ARCH!" == "amd64" (
79 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
80 ) else (
81 set CMAKE_GENERATOR="Visual Studio 9 2008"
82 )
83 ) else if "!BUILD_ENVIRONMENT!" == "VS10" (
84 if "!ARCH!" == "amd64" (
85 set CMAKE_GENERATOR="Visual Studio 10 Win64"
86 ) else (
87 set CMAKE_GENERATOR="Visual Studio 10"
88 )
89 ) else if "!BUILD_ENVIRONMENT!" == "VS11" (
90 if "!ARCH!" == "amd64" (
91 set CMAKE_GENERATOR="Visual Studio 11 Win64"
92 ) else if "!ARCH!" == "arm" (
93 set CMAKE_GENERATOR="Visual Studio 11 ARM"
94 ) else (
95 set CMAKE_GENERATOR="Visual Studio 11"
96 )
97 )
98 ) else (
99 set USE_NMAKE=1
100 echo This script defaults to nmake. To use Visual Studio GUI specify "VSSolution" as a parameter.
101 )
102
103 ) else if defined sdkdir (
104 echo Detected Windows SDK %TARGET_PLATFORM%-%TARGET_CPU%
105 if "%TARGET_CPU%" == "x86" (
106 set ARCH=i386
107 ) else if "%TARGET_CPU%" == "x64" (
108 set ARCH=amd64
109 )
110
111 set BUILD_ENVIRONMENT=SDK
112 set USE_NMAKE=1
113
114 ) else (
115 echo Error: Unable to detect build environment. Configure script failure.
116 exit /b
117 )
118
119 :: Checkpoint
120 if not defined ARCH (
121 echo Unknown build architecture
122 exit /b
123 )
124
125 :: Detect nmake generator
126 if %USE_NMAKE% == 1 (
127 if /I "%1" == "CodeBlocks" (
128 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
129 ) else if /I "%1" == "Eclipse" (
130 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
131 ) else if /I "%1" == "JOM" (
132 set CMAKE_GENERATOR="NMake Makefiles JOM"
133 ) else if /I "%1" == "Ninja" (
134 set CMAKE_GENERATOR="Ninja"
135 ) else (
136 set CMAKE_GENERATOR="NMake Makefiles"
137 )
138 )
139
140 :: Create directories
141 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
142 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
143 echo Creating directories in %REACTOS_OUTPUT_PATH%
144
145 if not exist %REACTOS_OUTPUT_PATH% (
146 mkdir %REACTOS_OUTPUT_PATH%
147 )
148 cd %REACTOS_OUTPUT_PATH%
149 )
150
151 if not exist host-tools (
152 mkdir host-tools
153 )
154 if not exist reactos (
155 mkdir reactos
156 )
157
158 echo Preparing host tools...
159 cd host-tools
160 if EXIST CMakeCache.txt (
161 del CMakeCache.txt /q
162 )
163 set REACTOS_BUILD_TOOLS_DIR=%CD%
164
165 :: Use x86 for ARM host tools
166 if "%ARCH%" == "arm" (
167 :: Launch new script instance for x86 host tools configuration
168 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR%
169 ) else (
170 cmake -G %CMAKE_GENERATOR% -DARCH=%ARCH% "%REACTOS_SOURCE_DIR%"
171 )
172
173 cd..
174
175 echo Preparing reactos...
176 cd reactos
177 if EXIST CMakeCache.txt (
178 del CMakeCache.txt /q
179 )
180
181 if "%BUILD_ENVIRONMENT%" == "MinGW" (
182 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE=0 -DPCH=0 -DCMAKE_TOOLCHAIN_FILE=toolchain-gcc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" "%REACTOS_SOURCE_DIR%"
183 ) else if "%BUILD_ENVIRONMENT%" == "WDK" (
184 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DUSE_WDK_HEADERS=%USE_WDK_HEADERS% -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" "%REACTOS_SOURCE_DIR%"
185 ) else (
186 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" "%REACTOS_SOURCE_DIR%"
187 )
188
189 cd..
190
191 echo Configure script complete! Enter directories and execute appropriate build commands(ex: make, nmake, jom, etc...).
192 exit /b
193
194 :cmake_notfound
195 echo Unable to find cmake, if it is installed, check your PATH variable.
196 exit /b