1@echo off 2 3REM This is needed so as to avoid static expansion of environment variables 4REM inside if (...) conditionals. 5REM See http://stackoverflow.com/questions/305605/weird-scope-issue-in-bat-file 6REM for more explanation. 7REM Precisely needed for configuring Visual Studio Environment. 8setlocal enabledelayedexpansion 9 10REM Does the user need help? 11if /I "%1" == "help" goto help 12if /I "%1" == "/?" ( 13:help 14 echo Help for configure script 15 echo Syntax: path\to\source\configure.cmd [script-options] [Cmake-options] 16 echo Available script-options: Codeblocks, Eclipse, Makefiles, clang, VSSolution 17 echo Cmake-options: -DVARIABLE:TYPE=VALUE 18 goto quit 19) 20 21REM Get the source root directory 22set REACTOS_SOURCE_DIR=%~dp0 23 24REM Ensure there's no spaces in the source path 25echo %REACTOS_SOURCE_DIR%| find " " > NUL 26if %ERRORLEVEL% == 0 ( 27 echo. && echo Your source path contains at least one space. 28 echo This will cause problems with building. 29 echo Please rename your folders so there are no spaces in the source path, 30 echo or move your source to a different folder. 31 goto quit 32) 33 34REM Set default generator 35set CMAKE_GENERATOR="Ninja" 36set CMAKE_ARCH= 37 38REM Detect presence of cmake 39cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound 40 41REM Detect build environment (MinGW, VS, WDK, ...) 42if defined ROS_ARCH ( 43 echo Detected RosBE for %ROS_ARCH% 44 set BUILD_ENVIRONMENT=MinGW 45 set ARCH=%ROS_ARCH% 46 set MINGW_TOOCHAIN_FILE=toolchain-gcc.cmake 47 48) else if defined VCINSTALLDIR ( 49 REM VS command prompt does not put this in environment 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 "ARM64" > NUL && set ARCH=arm64 54 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14 55 cl 2>&1 | findstr /R /c:"19\.1.\." > NUL && set VS_VERSION=15 56 cl 2>&1 | findstr /R /c:"19\.2.\." > NUL && set VS_VERSION=16 57 cl 2>&1 | findstr /R /c:"19\.3.\." > NUL && set VS_VERSION=17 58 if not defined VS_VERSION ( 59 echo Error: Visual Studio version too old ^(before 14 ^(2015^)^) or version detection failed. 60 goto quit 61 ) 62 set BUILD_ENVIRONMENT=VS 63 set VS_SOLUTION=0 64 echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH! 65) else ( 66 echo Error: Unable to detect build environment. Configure script failure. 67 goto quit 68) 69 70REM Checkpoint 71if not defined ARCH ( 72 echo Unknown build architecture 73 goto quit 74) 75 76set USE_CLANG_CL=0 77 78REM Parse command line parameters 79:repeat 80 if "%BUILD_ENVIRONMENT%" == "MinGW" ( 81 if /I "%1" == "Codeblocks" ( 82 set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles" 83 ) else if /I "%1" == "Eclipse" ( 84 set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles" 85 ) else if /I "%1" == "Makefiles" ( 86 set CMAKE_GENERATOR="MinGW Makefiles" 87 ) else if /I "%1" == "VSSolution" ( 88 echo. && echo Error: Creation of VS Solution files is not supported in a MinGW environment. 89 echo Please run this command in a [Developer] Command Prompt for Visual Studio. 90 goto quit 91 ) else if /I "%1" NEQ "" ( 92 echo.%1| find /I "-D" >nul 2>&1 93 if not errorlevel 1 ( 94 REM User is passing a switch to CMake 95 REM Ignore it, and ignore the next parameter that follows 96 Shift 97 ) else ( 98 echo. && echo Warning: Unrecognized switch "%1" && echo. 99 ) 100 ) else ( 101 goto continue 102 ) 103 ) else ( 104 if /I "%1" == "CodeBlocks" ( 105 set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles" 106 ) else if /I "%1" == "Eclipse" ( 107 set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles" 108 ) else if /I "%1" == "Makefiles" ( 109 set CMAKE_GENERATOR="NMake Makefiles" 110 ) else if /I "%1" == "clang" ( 111 set USE_CLANG_CL=1 112 ) else if /I "%1" == "VSSolution" ( 113 set VS_SOLUTION=1 114 REM explicitly set VS version for project generator 115 if /I "%2" == "-VS_VER" ( 116 set VS_VERSION=%3 117 echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH! 118 ) 119 set CMAKE_GENERATOR="Visual Studio !VS_VERSION!" 120 if "!ARCH!" == "i386" ( 121 set CMAKE_ARCH=-A Win32 122 ) else if "!ARCH!" == "amd64" ( 123 set CMAKE_ARCH=-A x64 124 ) else if "!ARCH!" == "arm" ( 125 set CMAKE_ARCH=-A ARM 126 ) else if "!ARCH!" == "arm64" ( 127 set CMAKE_ARCH=-A ARM64 128 ) 129 ) else if /I "%1" NEQ "" ( 130 echo.%1| find /I "-D" >nul 2>&1 131 if not errorlevel 1 ( 132 REM User is passing a switch to CMake 133 REM Ignore it, and ignore the next parameter that follows 134 Shift 135 ) else ( 136 echo. && echo Warning: Unrecognized switch "%1" && echo. 137 ) 138 ) else ( 139 goto continue 140 ) 141 ) 142 143 REM Go to next parameter 144 SHIFT 145 goto repeat 146:continue 147 148REM Inform the user about the default build 149if "!CMAKE_GENERATOR!" == "Ninja" ( 150 echo This script defaults to Ninja. Type "configure help" for alternative options. 151) 152 153REM Create directories 154set REACTOS_OUTPUT_PATH=output-%BUILD_ENVIRONMENT%-%ARCH% 155 156if "%VS_SOLUTION%" == "1" ( 157 set REACTOS_OUTPUT_PATH=%REACTOS_OUTPUT_PATH%-sln 158) 159 160if "%REACTOS_SOURCE_DIR%" == "%CD%\" ( 161 set CD_SAME_AS_SOURCE=1 162 echo Creating directories in %REACTOS_OUTPUT_PATH% 163 164 if not exist %REACTOS_OUTPUT_PATH% ( 165 mkdir %REACTOS_OUTPUT_PATH% 166 ) 167 cd %REACTOS_OUTPUT_PATH% 168) 169 170if "%VS_SOLUTION%" == "1" ( 171 172 if exist build.ninja ( 173 echo. && echo Error: This directory has already been configured for ninja. 174 echo An output folder configured for ninja can't be reconfigured for VSSolution. 175 echo Use an empty folder or delete the contents of this folder, then try again. 176 goto quit 177 ) 178) else if exist REACTOS.sln ( 179 echo. && echo Error: This directory has already been configured for Visual Studio. 180 echo An output folder configured for VSSolution can't be reconfigured for ninja. 181 echo Use an empty folder or delete the contents of this folder, then try again. && echo. 182 goto quit 183) 184 185echo Preparing reactos... 186 187if EXIST CMakeCache.txt ( 188 del CMakeCache.txt /q 189) 190 191 192if "%BUILD_ENVIRONMENT%" == "MinGW" ( 193 cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%" 194) else if %USE_CLANG_CL% == 1 ( 195 cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 %* "%REACTOS_SOURCE_DIR%" 196) else ( 197 cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%" 198) 199 200if %ERRORLEVEL% NEQ 0 ( 201 goto quit 202) 203 204if "%CD_SAME_AS_SOURCE%" == "1" ( 205 set ENDV= from %REACTOS_OUTPUT_PATH% 206) 207 208if "%VS_SOLUTION%" == "1" ( 209 set ENDV= You can now use msbuild or open REACTOS.sln%ENDV%. 210) else ( 211 set ENDV= Execute appropriate build commands ^(ex: ninja, make, nmake, etc...^)%ENDV% 212) 213 214echo. && echo Configure script complete^^!%ENDV% 215 216goto quit 217 218:cmake_notfound 219echo Unable to find cmake, if it is installed, check your PATH variable. 220 221:quit 222endlocal 223exit /b 224