Sync with trunk r62529.
[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_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 if /I "%1" == "clang" (
41 set BUILD_ENVIRONMENT=Clang
42 set CMAKE_GENERATOR="Ninja"
43 ) else (
44 set CMAKE_GENERATOR="Ninja"
45 )
46
47 ) else if defined VCINSTALLDIR (
48 :: VS command prompt does not put this in environment vars
49 cl 2>&1 | find "x86" > NUL && set ARCH=i386
50 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
51 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
52 cl 2>&1 | find "16.00." > NUL && set BUILD_ENVIRONMENT=VS10
53 cl 2>&1 | find "17.00." > NUL && set BUILD_ENVIRONMENT=VS11
54 cl 2>&1 | find "18.00." > NUL && set BUILD_ENVIRONMENT=VS12
55 if not defined BUILD_ENVIRONMENT (
56 echo Error: Visual Studio version too old or version detection failed.
57 exit /b
58 )
59
60 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!-!ARCH!
61 if /I "%1" == "VSSolution" (
62 if "!BUILD_ENVIRONMENT!" == "VS10" (
63 if "!ARCH!" == "amd64" (
64 set CMAKE_GENERATOR="Visual Studio 10 Win64"
65 ) else (
66 set CMAKE_GENERATOR="Visual Studio 10"
67 )
68 ) else if "!BUILD_ENVIRONMENT!" == "VS11" (
69 if "!ARCH!" == "amd64" (
70 set CMAKE_GENERATOR="Visual Studio 11 Win64"
71 ) else if "!ARCH!" == "arm" (
72 set CMAKE_GENERATOR="Visual Studio 11 ARM"
73 ) else (
74 set CMAKE_GENERATOR="Visual Studio 11"
75 )
76 ) else if "!BUILD_ENVIRONMENT!" == "VS12" (
77 if "!ARCH!" == "amd64" (
78 set CMAKE_GENERATOR="Visual Studio 12 Win64"
79 ) else if "!ARCH!" == "arm" (
80 set CMAKE_GENERATOR="Visual Studio 12 ARM"
81 ) else (
82 set CMAKE_GENERATOR="Visual Studio 12"
83 )
84 )
85 ) else (
86 set USE_VSCMD=1
87 echo This script defaults to Ninja. To use Visual Studio GUI specify "VSSolution" as a parameter.
88 )
89
90 ) else (
91 echo Error: Unable to detect build environment. Configure script failure.
92 exit /b
93 )
94
95 :: Checkpoint
96 if not defined ARCH (
97 echo Unknown build architecture
98 exit /b
99 )
100
101 :: Detect VS command line generator
102 if %USE_VSCMD% == 1 (
103 if /I "%1" == "CodeBlocks" (
104 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
105 ) else if /I "%1" == "Eclipse" (
106 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
107 ) else if /I "%1" == "Makefiles" (
108 set CMAKE_GENERATOR="NMake Makefiles"
109 ) else (
110 set CMAKE_GENERATOR="Ninja"
111 )
112 )
113
114 :: Create directories
115 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
116 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
117 echo Creating directories in %REACTOS_OUTPUT_PATH%
118
119 if not exist %REACTOS_OUTPUT_PATH% (
120 mkdir %REACTOS_OUTPUT_PATH%
121 )
122 cd %REACTOS_OUTPUT_PATH%
123 )
124
125 if not exist host-tools (
126 mkdir host-tools
127 )
128 if not exist reactos (
129 mkdir reactos
130 )
131
132 echo Preparing host tools...
133 cd host-tools
134 if EXIST CMakeCache.txt (
135 del CMakeCache.txt /q
136 )
137 set REACTOS_BUILD_TOOLS_DIR=%CD%
138
139 :: Use x86 for ARM host tools
140 if "%ARCH%" == "arm" (
141 :: Launch new script instance for x86 host tools configuration
142 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR%
143 ) else (
144 cmake -G %CMAKE_GENERATOR% -DARCH=%ARCH% "%REACTOS_SOURCE_DIR%"
145 )
146
147 cd..
148
149 echo Preparing reactos...
150 cd reactos
151 if EXIST CMakeCache.txt (
152 del CMakeCache.txt /q
153 )
154
155 if "%BUILD_ENVIRONMENT%" == "MinGW" (
156 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE=0 -DCMAKE_TOOLCHAIN_FILE=toolchain-gcc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" "%REACTOS_SOURCE_DIR%"
157 ) else if "%BUILD_ENVIRONMENT%" == "Clang" (
158 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE=0 -DCMAKE_TOOLCHAIN_FILE=toolchain-clang.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" "%REACTOS_SOURCE_DIR%"
159 ) else (
160 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" "%REACTOS_SOURCE_DIR%"
161 )
162
163 cd..
164
165 echo Configure script complete^^! Enter directories and execute appropriate build commands (ex: ninja, make, nmake, etc...).
166 exit /b
167
168 :cmake_notfound
169 echo Unable to find cmake, if it is installed, check your PATH variable.
170 exit /b