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