[COMCTL32]
[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: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 ) else (
81 set CMAKE_GENERATOR="Visual Studio 11"
82 )
83 ) else if "!BUILD_ENVIRONMENT!" == "VS12" (
84 if "!ARCH!" == "amd64" (
85 set CMAKE_GENERATOR="Visual Studio 12 Win64"
86 ) else if "!ARCH!" == "arm" (
87 set CMAKE_GENERATOR="Visual Studio 12 ARM"
88 ) else (
89 set CMAKE_GENERATOR="Visual Studio 12"
90 )
91 )
92 ) else (
93 set USE_VSCMD=1
94 echo This script defaults to Ninja. To use Visual Studio GUI specify "VSSolution" as a parameter.
95 )
96
97 ) else (
98 echo Error: Unable to detect build environment. Configure script failure.
99 exit /b
100 )
101
102 :: Checkpoint
103 if not defined ARCH (
104 echo Unknown build architecture
105 exit /b
106 )
107
108 :: Detect VS command line generator
109 if %USE_VSCMD% == 1 (
110 if /I "%1" == "CodeBlocks" (
111 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
112 ) else if /I "%1" == "Eclipse" (
113 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
114 ) else if /I "%1" == "Makefiles" (
115 set CMAKE_GENERATOR="NMake Makefiles"
116 ) else (
117 set CMAKE_GENERATOR="Ninja"
118 )
119 )
120
121 :: Create directories
122 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
123 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
124 echo Creating directories in %REACTOS_OUTPUT_PATH%
125
126 if not exist %REACTOS_OUTPUT_PATH% (
127 mkdir %REACTOS_OUTPUT_PATH%
128 )
129 cd %REACTOS_OUTPUT_PATH%
130 )
131
132 if not exist host-tools (
133 mkdir host-tools
134 )
135 if not exist reactos (
136 mkdir reactos
137 )
138
139 echo Preparing host tools...
140 cd host-tools
141 if EXIST CMakeCache.txt (
142 del CMakeCache.txt /q
143 )
144 set REACTOS_BUILD_TOOLS_DIR=%CD%
145
146 :: Use x86 for ARM host tools
147 if "%ARCH%" == "arm" (
148 :: Launch new script instance for x86 host tools configuration
149 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR%
150 ) else (
151 cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
152 )
153
154 cd..
155
156 echo Preparing reactos...
157 cd reactos
158 if EXIST CMakeCache.txt (
159 del CMakeCache.txt /q
160 )
161
162 if "%BUILD_ENVIRONMENT%" == "MinGW" (
163 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%"
164 ) else if "%BUILD_ENVIRONMENT%" == "Clang" (
165 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%"
166 ) else (
167 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%"
168 )
169
170 cd..
171
172 echo Configure script complete^^! Enter directories and execute appropriate build commands (ex: ninja, make, nmake, etc...).
173 exit /b
174
175 :cmake_notfound
176 echo Unable to find cmake, if it is installed, check your PATH variable.
177 exit /b