[WIN32SS] Introduce the NATIVE_REACTX define and disable some Dx calls (#6025)
[reactos.git] / configure.cmd
index d8f44af..d94501a 100755 (executable)
@@ -13,23 +13,11 @@ if /I "%1" == "/?" (
 :help
     echo Help for configure script
     echo Syntax: path\to\source\configure.cmd [script-options] [Cmake-options]
-    echo Available script-options: Codeblocks, Eclipse, Makefiles, clang, VSSolution, RTC
+    echo Available script-options: Codeblocks, Eclipse, Makefiles, clang, VSSolution
     echo Cmake-options: -DVARIABLE:TYPE=VALUE
     goto quit
 )
 
-REM Special case %1 = arm_hosttools %2 = vcvarsall.bat %3 = %CMAKE_GENERATOR%
-if /I "%1" == "arm_hosttools" (
-    echo Configuring x86 host tools for ARM cross build
-
-    REM This launches %VSINSTALLDIR%VS\vcvarsall.bat
-    call %2 x86
-
-    REM Configure host tools for x86.
-    cmake -G %3 -DARCH:STRING=i386 %~dp0
-    exit
-)
-
 REM Get the source root directory
 set REACTOS_SOURCE_DIR=%~dp0
 
@@ -45,7 +33,7 @@ if %ERRORLEVEL% == 0 (
 
 REM Set default generator
 set CMAKE_GENERATOR="Ninja"
-set CMAKE_GENERATOR_HOST=!CMAKE_GENERATOR!
+set CMAKE_ARCH=
 
 REM Detect presence of cmake
 cmd /c cmake --version 2>&1 | find "cmake version" > NUL || goto cmake_notfound
@@ -62,23 +50,18 @@ if defined ROS_ARCH (
     cl 2>&1 | find "x86" > NUL && set ARCH=i386
     cl 2>&1 | find "x64" > NUL && set ARCH=amd64
     cl 2>&1 | find "ARM" > NUL && set ARCH=arm
-    cl 2>&1 | find "16.00." > NUL && set VS_VERSION=10
-    cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
-    cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
+    cl 2>&1 | find "ARM64" > NUL && set ARCH=arm64
     cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
-    cl 2>&1 | find "19.10." > NUL && set VS_VERSION=15
-    cl 2>&1 | find "19.11." > NUL && set VS_VERSION=15
-    cl 2>&1 | find "19.12." > NUL && set VS_VERSION=15
-    cl 2>&1 | find "19.13." > NUL && set VS_VERSION=15
-    cl 2>&1 | find "19.14." > NUL && set VS_VERSION=15
-    cl 2>&1 | find "19.15." > NUL && set VS_VERSION=15
+    cl 2>&1 | findstr /R /c:"19\.1.\." > NUL && set VS_VERSION=15
+    cl 2>&1 | findstr /R /c:"19\.2.\." > NUL && set VS_VERSION=16
+    cl 2>&1 | findstr /R /c:"19\.3.\." > NUL && set VS_VERSION=17
+    cl 2>&1 | findstr /R /c:"19\.4.\." > NUL && set VS_VERSION=17
     if not defined VS_VERSION (
-        echo Error: Visual Studio version too old ^(before 10 ^(2010^)^) or version detection failed.
+        echo Error: Visual Studio version too old ^(before 14 ^(2015^)^) or version detection failed.
         goto quit
     )
     set BUILD_ENVIRONMENT=VS
     set VS_SOLUTION=0
-    set VS_RUNTIME_CHECKS=0
     echo Detected Visual Studio Environment !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
 ) else (
     echo Error: Unable to detect build environment. Configure script failure.
@@ -91,118 +74,83 @@ if not defined ARCH (
     goto quit
 )
 
-set NEW_STYLE_BUILD=1
 set USE_CLANG_CL=0
 
 REM Parse command line parameters
+set CMAKE_PARAMS=
+set REMAINING=%*
 :repeat
-    if /I "%1" == "-DNEW_STYLE_BUILD" (
-        set NEW_STYLE_BUILD=%2
-    ) else if "%BUILD_ENVIRONMENT%" == "MinGW" (
-        if /I "%1" == "Codeblocks" (
+
+    REM Extract a parameter without removing '='
+    for /f "tokens=1*" %%a in ("%REMAINING%") do (
+        set "PARAM=%%a"
+        set REMAINING=%%b
+    )
+
+    if "%BUILD_ENVIRONMENT%" == "MinGW" (
+        if /I "!PARAM!" == "Codeblocks" (
             set CMAKE_GENERATOR="CodeBlocks - MinGW Makefiles"
-        ) else if /I "%1" == "Eclipse" (
+        ) else if /I "!PARAM!" == "Eclipse" (
             set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
-        ) else if /I "%1" == "Makefiles" (
+        ) else if /I "!PARAM!" == "Makefiles" (
             set CMAKE_GENERATOR="MinGW Makefiles"
-        ) else if /I "%1" == "VSSolution" (
+        ) else if /I "!PARAM!" == "Ninja" (
+            set CMAKE_GENERATOR="Ninja"
+        ) else if /I "!PARAM!" == "VSSolution" (
             echo. && echo Error: Creation of VS Solution files is not supported in a MinGW environment.
             echo Please run this command in a [Developer] Command Prompt for Visual Studio.
             goto quit
-        ) else if /I "%1" == "RTC" (
-            echo. && echo      Warning: RTC switch is ignored outside of a Visual Studio environment. && echo.
-        ) else if /I "%1" NEQ "" (
-            echo %1| find /I "-D" > NUL
-            if %ERRORLEVEL% == 0 (
-                REM User is passing a switch to CMake
-                REM Ignore it, and ignore the next parameter that follows
-                Shift
-            ) else (
-                echo. && echo   Warning: Unrecognized switch "%1" && echo.
-            )
+        ) else if /I "!PARAM:~0,2!" == "-D" (
+            REM User is passing a switch to CMake
+            set "CMAKE_PARAMS=%CMAKE_PARAMS% !PARAM!"
         ) else (
-            goto continue
+            echo. && echo   Warning: Unrecognized switch "!PARAM!" && echo.
         )
     ) else (
-        if /I "%1" == "CodeBlocks" (
+        if /I "!PARAM!" == "CodeBlocks" (
             set CMAKE_GENERATOR="CodeBlocks - NMake Makefiles"
-        ) else if /I "%1" == "Eclipse" (
+        ) else if /I "!PARAM!" == "Eclipse" (
             set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
-        ) else if /I "%1" == "Makefiles" (
+        ) else if /I "!PARAM!" == "Makefiles" (
             set CMAKE_GENERATOR="NMake Makefiles"
-        ) else if /I "%1" == "clang" (
+        ) else if /I "!PARAM!" == "Ninja" (
+            set CMAKE_GENERATOR="Ninja"
+        ) else if /I "!PARAM!" == "clang" (
             set USE_CLANG_CL=1
-        ) else if /I "%1" == "VSSolution" (
+        ) else if /I "!PARAM!" == "VSSolution" (
             set VS_SOLUTION=1
             REM explicitly set VS version for project generator
-            if /I "%2" == "-VS_VER" (
-                set VS_VERSION=%3
-                echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
+            for /f "tokens=1*" %%a in ("%REMAINING%") do (
+                set PARAM=%%a
+                set REMAINING2=%%b
             )
-            if "!VS_VERSION!" == "10" (
-                if "!ARCH!" == "amd64" (
-                    set CMAKE_GENERATOR="Visual Studio 10 Win64"
-                ) else (
-                    set CMAKE_GENERATOR="Visual Studio 10"
-                )
-            ) else if "!VS_VERSION!" == "11" (
-                if "!ARCH!" == "amd64" (
-                    set CMAKE_GENERATOR="Visual Studio 11 Win64"
-                ) else if "!ARCH!" == "arm" (
-                    set CMAKE_GENERATOR="Visual Studio 11 ARM"
-                    set CMAKE_GENERATOR_HOST="Visual Studio 11"
-                ) else (
-                    set CMAKE_GENERATOR="Visual Studio 11"
-                )
-            ) else if "!VS_VERSION!" == "12" (
-                if "!ARCH!" == "amd64" (
-                    set CMAKE_GENERATOR="Visual Studio 12 Win64"
-                ) else if "!ARCH!" == "arm" (
-                    set CMAKE_GENERATOR="Visual Studio 12 ARM"
-                    set CMAKE_GENERATOR_HOST="Visual Studio 12"
-                ) else (
-                    set CMAKE_GENERATOR="Visual Studio 12"
-                )
-            ) else if "!VS_VERSION!" == "14" (
-                if "!ARCH!" == "amd64" (
-                    set CMAKE_GENERATOR="Visual Studio 14 Win64"
-                ) else if "!ARCH!" == "arm" (
-                    set CMAKE_GENERATOR="Visual Studio 14 ARM"
-                    set CMAKE_GENERATOR_HOST="Visual Studio 14"
-                ) else (
-                    set CMAKE_GENERATOR="Visual Studio 14"
-                )
-            ) else if "!VS_VERSION!" == "15" (
-                if "!ARCH!" == "amd64" (
-                    set CMAKE_GENERATOR="Visual Studio 15 Win64"
-                ) else if "!ARCH!" == "arm" (
-                    set CMAKE_GENERATOR="Visual Studio 15 ARM"
-                    set CMAKE_GENERATOR_HOST="Visual Studio 15"
-                ) else (
-                    set CMAKE_GENERATOR="Visual Studio 15"
+            if /I "!PARAM!" == "-VS_VER" (
+                for /f "tokens=1*" %%a in ("!REMAINING2!") do (
+                    set VS_VERSION=%%a
+                    set REMAINING=%%b
                 )
+                echo Visual Studio Environment set to !BUILD_ENVIRONMENT!!VS_VERSION!-!ARCH!
             )
-        ) else if /I "%1" == "RTC" (
-            echo Runtime checks enabled
-            set VS_RUNTIME_CHECKS=1
-        ) else if /I "%1" NEQ "" (
-            echo %1| find /I "-D" > NUL
-            if %ERRORLEVEL% == 0 (
-                REM User is passing a switch to CMake
-                REM Ignore it, and ignore the next parameter that follows
-                Shift
-            ) else (
-                echo. && echo   Warning: Unrecognized switch "%1" && echo.
+            set CMAKE_GENERATOR="Visual Studio !VS_VERSION!"
+            if "!ARCH!" == "i386" (
+                set CMAKE_ARCH=-A Win32
+            ) else if "!ARCH!" == "amd64" (
+                set CMAKE_ARCH=-A x64
+            ) else if "!ARCH!" == "arm" (
+                set CMAKE_ARCH=-A ARM
+            ) else if "!ARCH!" == "arm64" (
+                set CMAKE_ARCH=-A ARM64
             )
+        ) else if /I "!PARAM:~0,2!" == "-D" (
+            REM User is passing a switch to CMake
+            set "CMAKE_PARAMS=%CMAKE_PARAMS% !PARAM!"
         ) else (
-            goto continue
+            echo. && echo   Warning: Unrecognized switch "!PARAM!" && echo.
         )
     )
 
     REM Go to next parameter
-    SHIFT
-    goto repeat
-:continue
+    if defined REMAINING goto repeat
 
 REM Inform the user about the default build
 if "!CMAKE_GENERATOR!" == "Ninja" (
@@ -241,61 +189,19 @@ if "%VS_SOLUTION%" == "1" (
     goto quit
 )
 
-if "%NEW_STYLE_BUILD%"=="0" (
-
-    if not exist host-tools (
-        mkdir host-tools
-    )
-
-    if not exist reactos (
-        mkdir reactos
-    )
-
-    echo Preparing host tools...
-    cd host-tools
-    if EXIST CMakeCache.txt (
-        del CMakeCache.txt /q
-    )
-
-    set REACTOS_BUILD_TOOLS_DIR=!CD!
-
-    REM Use x86 for ARM host tools
-    if "%ARCH%" == "arm" (
-        REM Launch new script instance for x86 host tools configuration
-        start "Preparing host tools for ARM cross build..." /I /B /WAIT %~dp0configure.cmd arm_hosttools "%VSINSTALLDIR%VC\vcvarsall.bat" %CMAKE_GENERATOR_HOST%
-    ) else (
-        cmake -G %CMAKE_GENERATOR% -DARCH:STRING=%ARCH% "%REACTOS_SOURCE_DIR%"
-    )
-
-    cd..
-
-)
-
 echo Preparing reactos...
 
-if "%NEW_STYLE_BUILD%"=="0" (
-    cd reactos
-)
-
 if EXIST CMakeCache.txt (
     del CMakeCache.txt /q
-    del host-tools\CMakeCache.txt /q
 )
 
-if "%NEW_STYLE_BUILD%"=="0" (
-    set BUILD_TOOLS_FLAG=-DREACTOS_BUILD_TOOLS_DIR:PATH="%REACTOS_BUILD_TOOLS_DIR%"
-)
 
 if "%BUILD_ENVIRONMENT%" == "MinGW" (
-    cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
+    cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %CMAKE_PARAMS% "%REACTOS_SOURCE_DIR%"
 ) else if %USE_CLANG_CL% == 1 (
-        cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
+    cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 %CMAKE_PARAMS% "%REACTOS_SOURCE_DIR%"
 ) else (
-    cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
-)
-
-if "%NEW_STYLE_BUILD%"=="0" (
-    cd..
+    cmake -G %CMAKE_GENERATOR% %CMAKE_ARCH% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %CMAKE_PARAMS% "%REACTOS_SOURCE_DIR%"
 )
 
 if %ERRORLEVEL% NEQ 0 (