[CSRSRV]
[reactos.git] / configure.cmd
1 @echo off
2
3 :: Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
4 if /I "%1" == "arm_hosttools" (
5 echo Configuring x86 host tools for ARM cross build
6
7 :: This launches %VSINSTALLDIR%VS\vcvarsall.bat
8 call %2 x86
9
10 :: Configure host tools for x86
11 cmake -G %3 -DARCH=i386 %~dp0
12 exit
13 )
14
15 :: Get the source root directory
16 set REACTOS_SOURCE_DIR=%~dp0
17 set USE_NMAKE=0
18
19 :: Detect presence of cmake
20 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
21
22 :: Detect build environment (MinGW, VS, WDK, ...)
23 if defined ROS_ARCH (
24 echo Detected RosBE for %ROS_ARCH%
25 set BUILD_ENVIRONMENT=MinGW
26 set ARCH=%ROS_ARCH%
27 if /I "%1" == "Codeblocks" (
28 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
29 ) else if /I "%1" == "Eclipse" (
30 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
31 ) else if /I "%1" == "Ninja" (
32 set CMAKE_GENERATOR="Ninja"
33 ) else (
34 set CMAKE_GENERATOR="MinGW Makefiles"
35 )
36
37 ) else if defined DDK_TARGET_OS (
38 echo Detected DDK/WDK for %DDK_TARGET_OS%-%_BUILDARCH%%
39 set BUILD_ENVIRONMENT=WDK
40 if "%_BUILDARCH%" == "x86" (
41 set ARCH=i386
42 ) else if "%_BUILDARCH%" == "AMD64" (
43 set ARCH=amd64
44 )
45 set USE_NMAKE=1
46 set USE_WDK_HEADERS=0
47
48 ) else if defined VCINSTALLDIR (
49 :: VS command prompt does not put this in enviroment vars
50 cl 2>&1 | find "x86" > NUL && set ARCH=i386
51 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
52 cl 2>&1 | find "ARM" > NUL && set ARCH=arm
53 cl 2>&1 | find "14." > NUL && set BUILD_ENVIRONMENT=VS8
54 cl 2>&1 | find "15." > NUL && set BUILD_ENVIRONMENT=VS9
55 cl 2>&1 | find "16." > NUL && set BUILD_ENVIRONMENT=VS10
56 cl 2>&1 | find "17." > NUL && set BUILD_ENVIRONMENT=VS11
57 if not defined BUILD_ENVIRONMENT (
58 echo Error: Visual Studio version too old or version detection failed.
59 exit /b
60 )
61
62 echo Detected Visual Studio Environment %BUILD_ENVIRONMENT%-%ARCH%
63 if /I "%1" == "VSSolution" (
64 if "%BUILD_ENVIRONMENT%" == "VS8" (
65 if "%ARCH%" == "amd64" (
66 set CMAKE_GENERATOR="Visual Studio 8 2005 Win64"
67 ) else (
68 set CMAKE_GENERATOR="Visual Studio 8 2005"
69 )
70 ) else if "%BUILD_ENVIRONMENT%" == "VS9" (
71 if "%ARCH%" == "amd64" (
72 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
73 ) else (
74 set CMAKE_GENERATOR="Visual Studio 9 2008"
75 )
76 ) else if "%BUILD_ENVIRONMENT%" == "VS10" (
77 if "%ARCH%" == "amd64" (
78 set CMAKE_GENERATOR="Visual Studio 10 Win64"
79 ) else (
80 set CMAKE_GENERATOR="Visual Studio 10"
81 )
82 ) else if "%BUILD_ENVIRONMENT%" == "VS11" (
83 if "%ARCH%" == "amd64" (
84 set CMAKE_GENERATOR="Visual Studio 11 Win64"
85 ) else if "%ARCH%" == "arm" (
86 set CMAKE_GENERATOR="Visual Studio 11 ARM"
87 ) else (
88 set CMAKE_GENERATOR="Visual Studio 11"
89 )
90 )
91 ) else (
92 set USE_NMAKE=1
93 echo This script defaults to nmake. To use Visual Studio GUI specify "VSSolution" as a parameter.
94 )
95
96 ) else if defined sdkdir (
97 echo Detected Windows SDK %TARGET_PLATFORM%-%TARGET_CPU%
98 if "%TARGET_CPU%" == "x86" (
99 set ARCH=i386
100 ) else if "%TARGET_CPU%" == "x64" (
101 set ARCH=amd64
102 )
103
104 set BUILD_ENVIRONMENT=SDK
105 set USE_NMAKE=1
106
107 ) else (
108 echo Error: Unable to detect build environment. Configure script failure.
109 exit /b
110 )
111
112 :: Checkpoint
113 if not defined ARCH (
114 echo unknown build architecture
115 exit /b
116 )
117
118 :: Detect nmake generator
119 if %USE_NMAKE% == 1 (
120 if /I "%1" == "CodeBlocks" (
121 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
122 ) else if /I "%1" == "Eclipse" (
123 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
124 ) else if /I "%1" == "JOM" (
125 set CMAKE_GENERATOR="NMake Makefiles JOM"
126 ) else if /I "%1" == "Ninja" (
127 set CMAKE_GENERATOR="Ninja"
128 ) else (
129 set CMAKE_GENERATOR="NMake Makefiles"
130 )
131 )
132
133 :: Create directories
134 set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH%
135 if "%REACTOS_SOURCE_DIR%" == "%CD%\" (
136 echo Creating directories in %REACTOS_OUTPUT_PATH%
137
138 if not exist %REACTOS_OUTPUT_PATH% (
139 mkdir %REACTOS_OUTPUT_PATH%
140 )
141 cd %REACTOS_OUTPUT_PATH%
142 )
143
144 if not exist host-tools (
145 mkdir host-tools
146 )
147 if not exist reactos (
148 mkdir reactos
149 )
150
151 echo Preparing host tools...
152 cd host-tools
153 if EXIST CMakeCache.txt (
154 del CMakeCache.txt /q
155 )
156 set REACTOS_BUILD_TOOLS_DIR=%CD%
157
158 :: Use x86 for ARM host tools
159 if "%ARCH%" == "arm" (
160 :: Launch new script instance for x86 host tools configuration
161 start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR%
162 ) else (
163 cmake -G %CMAKE_GENERATOR% -DARCH=%ARCH% "%REACTOS_SOURCE_DIR%"
164 )
165
166 cd..
167
168 echo Preparing reactos...
169 cd reactos
170 if EXIST CMakeCache.txt (
171 del CMakeCache.txt /q
172 )
173
174 if "%BUILD_ENVIRONMENT%" == "MinGW" (
175 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%"
176 ) else if "%BUILD_ENVIRONMENT%" == "WDK" (
177 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%"
178 ) else (
179 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" "%REACTOS_SOURCE_DIR%"
180 )
181
182 cd..
183
184 echo Configure script complete! Enter directories and execute appropriate build commands(ex: make, nmake, jom, etc...).
185 exit /b
186
187 :cmake_notfound
188 echo Unable to find cmake, if it is installed, check your PATH variable.
189 exit /b