[cmake]
[reactos.git] / reactos / configure.cmd
1 @echo off
2
3 :: Get the source root directory
4 set REACTOS_SOURCE_DIR=%~dp0
5 set USE_NMAKE=0
6
7 :: Detect presence of cmake
8 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
9
10 :: Detect build environment (MinGW, VS, WDK, ...)
11 if defined ROS_ARCH (
12 echo Detected RosBE for %ROS_ARCH%
13 set BUILD_ENVIRONMENT=MinGW
14 set ARCH=%ROS_ARCH%
15 if /I "%1" == "Codeblocks" (
16 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
17 ) else if /I "%1" == "Eclipse" (
18 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
19 ) else (
20 set CMAKE_GENERATOR="MinGW Makefiles"
21 )
22
23 ) else if defined DDK_TARGET_OS (
24 echo Detected DDK/WDK for %DDK_TARGET_OS%-%_BUILDARCH%%
25 set BUILD_ENVIRONMENT=WDK
26 if "%_BUILDARCH%" == "x86" (
27 set ARCH=i386
28 ) else if "%_BUILDARCH%" == "AMD64" (
29 set ARCH=amd64
30 )
31 set USE_NMAKE=1
32 set USE_WDK_HEADERS=0
33
34 ) else if defined VCINSTALLDIR (
35 :: VS command prompt does not put this in enviroment vars
36 cl 2>&1 | find "x86" > NUL && set ARCH=i386
37 cl 2>&1 | find "x64" > NUL && set ARCH=amd64
38 cl 2>&1 | find "14." > NUL && set BUILD_ENVIRONMENT=VS8
39 cl 2>&1 | find "15." > NUL && set BUILD_ENVIRONMENT=VS9
40 cl 2>&1 | find "16." > NUL && set BUILD_ENVIRONMENT=VS10
41 cl 2>&1 | find "17." > NUL && set BUILD_ENVIRONMENT=VS11
42 if not defined BUILD_ENVIRONMENT (
43 echo Error: Visual Studio version too old or version detection failed.
44 exit /b
45 )
46
47 echo Detected Visual Studio Environment %BUILD_ENVIRONMENT%-%ARCH%
48 if /I "%1" == "VSSolution" (
49 if "%BUILD_ENVIRONMENT%" == "VS8" (
50 if "%ARCH%" == "amd64" (
51 set CMAKE_GENERATOR="Visual Studio 8 2005 Win64"
52 ) else (
53 set CMAKE_GENERATOR="Visual Studio 8 2005"
54 )
55 ) else if "%BUILD_ENVIRONMENT%" == "VS9" (
56 if "%ARCH%" == "amd64" (
57 set CMAKE_GENERATOR="Visual Studio 9 2008 Win64"
58 ) else (
59 set CMAKE_GENERATOR="Visual Studio 9 2008"
60 )
61 ) else if "%BUILD_ENVIRONMENT%" == "VS10" (
62 if "%ARCH%" == "amd64" (
63 set CMAKE_GENERATOR="Visual Studio 10 Win64"
64 ) else (
65 set CMAKE_GENERATOR="Visual Studio 10"
66 )
67 ) else if "%BUILD_ENVIRONMENT%" == "VS11" (
68 if "%ARCH%" == "amd64" (
69 set CMAKE_GENERATOR="Visual Studio 11 Win64"
70 ) else (
71 set CMAKE_GENERATOR="Visual Studio 11"
72 )
73 )
74 ) else (
75 set USE_NMAKE=1
76 echo This script defaults to nmake. To use Visual Studio GUI specify "VSSolution" as a parameter.
77 )
78
79 ) else if defined sdkdir (
80 echo Detected Windows SDK %TARGET_PLATFORM%-%TARGET_CPU%
81 if "%TARGET_CPU%" == "x86" (
82 set ARCH=i386
83 ) else if "%TARGET_CPU%" == "x64" (
84 set ARCH=amd64
85 )
86
87 set BUILD_ENVIRONMENT=SDK
88 set USE_NMAKE=1
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 nmake generator
102 if %USE_NMAKE% == 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" == "JOM" (
108 set CMAKE_GENERATOR="NMake Makefiles JOM"
109 ) else (
110 set CMAKE_GENERATOR="NMake Makefiles"
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 cmake -G %CMAKE_GENERATOR% -DARCH=%ARCH% %REACTOS_SOURCE_DIR%
140 cd..
141
142 echo Preparing reactos...
143 cd reactos
144 if EXIST CMakeCache.txt (
145 del CMakeCache.txt /q
146 )
147
148 if "%BUILD_ENVIRONMENT%" == "MinGW" (
149 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%
150 ) else if "%BUILD_ENVIRONMENT%" == "WDK" (
151 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%
152 ) else (
153 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE=toolchain-msvc.cmake -DARCH=%ARCH% -DREACTOS_BUILD_TOOLS_DIR:DIR="%REACTOS_BUILD_TOOLS_DIR%" %REACTOS_SOURCE_DIR%
154 )
155
156 cd..
157
158 echo Configure script complete! Enter directories and execute appropriate build commands(ex: make, nmake, jom, etc...).
159 exit /b
160
161 :cmake_notfound
162 echo Unable to find cmake, if it is installed, check your PATH variable.
163 exit /b