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