bd1ce26cf6865cd40c0eb97ff10b813d3182a9af
[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 :: 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_VSCMD=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" == "Makefiles" (
39 set CMAKE_GENERATOR="MinGW Makefiles"
40 ) else (
41 set CMAKE_GENERATOR="Ninja"
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_VSCMD=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.00." > NUL && set BUILD_ENVIRONMENT=VS8
61 cl 2>&1 | find "15.00." > NUL && set BUILD_ENVIRONMENT=VS9
62 cl 2>&1 | find "16.00." > NUL && set BUILD_ENVIRONMENT=VS10
63 cl 2>&1 | find "17.00." > NUL && set BUILD_ENVIRONMENT=VS11
64 ::cl 2>&1 | find "18.00." > NUL && set BUILD_ENVIRONMENT=VS12
65 if not defined BUILD_ENVIRONMENT (
66 echo Error: Visual Studio version too old or version detection failed.
67 exit /b
68 )
69
70 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!-!ARCH!
71 if /I "%1" == "VSSolution" (
72 if "!BUILD_ENVIRONMENT!" == "VS8" (
73 if "!ARCH!" == "amd64" (
74 set CMAKE_GENERATOR="Visual Studio 8 2005 Win64"
75 ) else (
76 set CMAKE_GENERATOR="Visual Studio 8 2005"
77 )
78 ) else if "!BUILD_ENVIRONMENT!" == "VS9" (
79 if "!ARCH!" == "amd64" (
80 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
81 ) else (
82 set CMAKE_GENERATOR="Visual Studio 9 2008"
83 )
84 ) else if "!BUILD_ENVIRONMENT!" == "VS10" (
85 if "!ARCH!" == "amd64" (
86 set CMAKE_GENERATOR="Visual Studio 10 Win64"
87 ) else (
88 set CMAKE_GENERATOR="Visual Studio 10"
89 )
90 ) else if "!BUILD_ENVIRONMENT!" == "VS11" (
91 if "!ARCH!" == "amd64" (
92 set CMAKE_GENERATOR="Visual Studio 11 Win64"
93 ) else if "!ARCH!" == "arm" (
94 set CMAKE_GENERATOR="Visual Studio 11 ARM"
95 ) else (
96 set CMAKE_GENERATOR="Visual Studio 11"
97 )
98 )
99 ) else (
100 set USE_VSCMD=1
101 echo This script defaults to Ninja. To use Visual Studio GUI specify "VSSolution" as a parameter.
102 )
103
104 ) else if defined sdkdir (
105 echo Detected Windows SDK %TARGET_PLATFORM%-%TARGET_CPU%
106 if "%TARGET_CPU%" == "x86" (
107 set ARCH=i386
108 ) else if "%TARGET_CPU%" == "x64" (
109 set ARCH=amd64
110 )
111
112 set BUILD_ENVIRONMENT=SDK
113 set USE_VSCMD=1
114
115 ) else (
116 echo Error: Unable to detect build environment. Configure script failure.
117 exit /b
118 )
119
120 :: Checkpoint
121 if not defined ARCH (
122 echo Unknown build architecture
123 exit /b
124 )
125
126 :: Detect VS command line generator
127 if %USE_VSCMD% == 1 (
128 if /I "%1" == "CodeBlocks" (
129 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
130 ) else if /I "%1" == "Eclipse" (
131 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
132 ) else if /I "%1" == "Makefiles" (
133 set CMAKE_GENERATOR="NMake Makefiles"
134 ) else (
135 set CMAKE_GENERATOR="Ninja"
136 )
137 )
138
139 :: Create directories
140 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
141 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
142 echo Creating directories in %REACTOS_OUTPUT_PATH%
143
144 if not exist %REACTOS_OUTPUT_PATH% (
145 mkdir %REACTOS_OUTPUT_PATH%
146 )
147 cd %REACTOS_OUTPUT_PATH%
148 )
149
150 if not exist host-tools (
151 mkdir host-tools
152 )
153 if not exist reactos (
154 mkdir reactos
155 )
156
157 echo Preparing host tools...
158 cd host-tools
159 if EXIST CMakeCache.txt (
160 del CMakeCache.txt /q
161 )
162 set REACTOS_BUILD_TOOLS_DIR=%CD%
163
164 :: Use x86 for ARM host tools
165 if "%ARCH%" == "arm" (
166 :: Launch new script instance for x86 host tools configuration
167 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR%
168 ) else (
169 cmake -G %CMAKE_GENERATOR% -DARCH=%ARCH% "%REACTOS_SOURCE_DIR%"
170 )
171
172 cd..
173
174 echo Preparing reactos...
175 cd reactos
176 if EXIST CMakeCache.txt (
177 del CMakeCache.txt /q
178 )
179
180 if "%BUILD_ENVIRONMENT%" == "MinGW" (
181 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%"
182 ) else if "%BUILD_ENVIRONMENT%" == "WDK" (
183 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%"
184 ) else (
185 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" "%REACTOS_SOURCE_DIR%"
186 )
187
188 cd..
189
190 echo Configure script complete^^! Enter directories and execute appropriate build commands (ex: ninja, make, nmake, etc...).
191 exit /b
192
193 :cmake_notfound
194 echo Unable to find cmake, if it is installed, check your PATH variable.
195 exit /b