diff --git a/build_files/windows/configure_msbuild.cmd b/build_files/windows/configure_msbuild.cmd index c26a98ee1b4..330fc4b5dcc 100644 --- a/build_files/windows/configure_msbuild.cmd +++ b/build_files/windows/configure_msbuild.cmd @@ -8,7 +8,22 @@ if "%BUILD_WITH_SCCACHE%"=="1" ( ) if "%WITH_CLANG%"=="1" ( + REM We want to use an external manifest with Clang set CLANG_CMAKE_ARGS=-T"ClangCl" -DWITH_WINDOWS_EXTERNAL_MANIFEST=ON + + REM Create the build directory, so that we can create the Directory.build.props file + if NOT EXIST %BUILD_DIR%\nul ( + mkdir %BUILD_DIR% + ) + + REM This is required as per https://learn.microsoft.com/en-us/cpp/build/clang-support-msbuild?view=msvc-170#custom_llvm_location + REM Which allows any copy of LLVM to be used, not just the one that ships with VS + echo ^ >> %BUILD_DIR%\Directory.build.props + echo ^ >> %BUILD_DIR%\Directory.build.props + echo ^%LLVM_DIR%^ >> %BUILD_DIR%\Directory.build.props + echo ^%CLANG_VERSION%^ >> %BUILD_DIR%\Directory.build.props + echo ^ >> %BUILD_DIR%\Directory.build.props + echo ^ >> %BUILD_DIR%\Directory.build.props ) if "%WITH_ASAN%"=="1" ( diff --git a/build_files/windows/configure_ninja.cmd b/build_files/windows/configure_ninja.cmd index 98d469ab1da..a0cde8ccc0e 100644 --- a/build_files/windows/configure_ninja.cmd +++ b/build_files/windows/configure_ninja.cmd @@ -14,28 +14,10 @@ if "%BUILD_WITH_SCCACHE%"=="1" ( ) if "%WITH_CLANG%" == "1" ( -set LLVM_DIR= + REM We want to use an external manifest with Clang set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -DWITH_WINDOWS_EXTERNAL_MANIFEST=On - for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\LLVM\LLVM" /ve 2^>nul`) DO set LLVM_DIR=%%C - if DEFINED LLVM_DIR ( - if NOT "%verbose%" == "" ( - echo LLVM Detected at "%LLVM_DIR%" - ) - goto DetectionComplete - ) - REM Check 32 bits - for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\LLVM\LLVM" /ve 2^>nul`) DO set LLVM_DIR=%%C - if DEFINED LLVM_DIR ( - if NOT "%verbose%" == "" ( - echo LLVM Detected at "%LLVM_DIR%" - ) - goto DetectionComplete - ) - echo LLVM not found - exit /b 1 - -:DetectionComplete + REM We can assume that we have a working copy via find_llvm.cmd set CC=%LLVM_DIR%\bin\clang-cl set CXX=%LLVM_DIR%\bin\clang-cl set CFLAGS=-m64 diff --git a/build_files/windows/detect_msvc_vswhere.cmd b/build_files/windows/detect_msvc_vswhere.cmd index 52f765c20c4..081f1ce9bdb 100644 --- a/build_files/windows/detect_msvc_vswhere.cmd +++ b/build_files/windows/detect_msvc_vswhere.cmd @@ -13,11 +13,16 @@ if not exist "%vs_where%" ( goto FAIL ) -if NOT "%verbose%" == "" ( - echo "%vs_where%" -latest %VSWHERE_ARGS% -version ^[%BUILD_VS_VER%.0^,%BUILD_VS_VER%.99^) -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 - ) +if "%BUILD_ARCH%" == "arm64" ( + set VSWHERE_ARCH=ARM64 +) else ( + set VSWHERE_ARCH=x86.x64 +) -for /f "usebackq tokens=1* delims=: " %%i in (`"%vs_where%" -latest -version ^[%BUILD_VS_VER%.0^,%BUILD_VS_VER%.99^) %VSWHERE_ARGS% -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64`) do ( +if NOT "%verbose%" == "" ( + echo "%vs_where%" -latest %VSWHERE_ARGS% -version ^[%BUILD_VS_VER%.0^,%BUILD_VS_VER%.99^) -requires Microsoft.VisualStudio.Component.VC.Tools.%VSWHERE_ARCH% +) +for /f "usebackq tokens=1* delims=: " %%i in (`"%vs_where%" -latest -version ^[%BUILD_VS_VER%.0^,%BUILD_VS_VER%.99^) %VSWHERE_ARGS% -requires Microsoft.VisualStudio.Component.VC.Tools.%VSWHERE_ARCH%`) do ( if /i "%%i"=="installationPath" set VS_InstallDir=%%j ) @@ -38,6 +43,34 @@ if "%VS_InstallDir%"=="" ( ) ) +rem If we are using Clang + MSBuild, check to make sure the clang tools are installed +if "%WITH_CLANG%" == "1" ( + if NOT "%BUILD_WITH_NINJA%" == "1" ( + if NOT "%verbose%" == "" ( + echo "%vs_where%" -latest %VSWHERE_ARGS% -version ^[%BUILD_VS_VER%.0^,%BUILD_VS_VER%.99^) -requires Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset + ) + + for /f "usebackq tokens=1* delims=: " %%i in (`"%vs_where%" -latest -version ^[%BUILD_VS_VER%.0^,%BUILD_VS_VER%.99^) %VSWHERE_ARGS% -requires Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset`) do ( + if /i "%%i"=="installationName" set VSWhere_ClangFound=%%j + ) + ) +) + +REM This needs to be in a seperate block, due to no delayed expansion (which breaks other things if enabled) +if "%WITH_CLANG%" == "1" ( + if NOT "%BUILD_WITH_NINJA%" == "1" ( + if "%VSWhere_ClangFound%"=="" ( + echo. + echo Clang was specified whilst using the Visual Studio CMake generator, but the Clang Toolset was not found in Visual Studio. + echo. + echo Check the "MSBuild support for LLVM (clang-cl) toolset" component has been installed. + echo. + echo Alternatively use the Ninja generator via the "ninja" switch when calling make.bat + goto FAIL + ) + ) +) + set VCVARS=%VS_InstallDir%\VC\Auxiliary\Build\vcvarsall.bat if exist "%VCVARS%" ( if NOT "%verbose%" == "" ( diff --git a/build_files/windows/find_llvm.cmd b/build_files/windows/find_llvm.cmd new file mode 100644 index 00000000000..f00ca7bb7c7 --- /dev/null +++ b/build_files/windows/find_llvm.cmd @@ -0,0 +1,57 @@ +REM Find a copy of LLVM on the system +set LLVM_DIR= + +REM First, we try and find the copy on the PATH (unless already specified, in which case we use that) +if "%LLVM_EXE%" == "" ( + for %%X in (clang-cl.exe) do (set "LLVM_EXE=%%~$PATH:X") +) else ( + echo LLVM EXE manually specified, using that +) + +if NOT "%LLVM_EXE%" == "" ( + REM We have found LLVM on the path + for %%X in ("%LLVM_EXE%\..\..") do set "LLVM_DIR=%%~fX" + if NOT "%verbose%" == "" ( + echo LLVM detected via path + ) + goto detect_llvm_done +) + +REM If that fails, we try and get it from the registry +REM Check 64-bit path +for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\LLVM\LLVM" /ve 2^>nul`) DO set LLVM_DIR=%%C +if NOT "%LLVM_DIR%" == "" ( + if NOT "%verbose%" == "" ( + echo LLVM Detected via 64-bit registry + ) + goto detect_llvm_done +) + +REM Check 32-bit path +for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\LLVM\LLVM" /ve 2^>nul`) DO set LLVM_DIR=%%C +if NOT "%LLVM_DIR%" == "" ( + if NOT "%verbose%" == "" ( + echo LLVM Detected via 32-bit registry + ) + goto detect_llvm_done +) + +rem No copy has been found, so error out +if "%LLVM_DIR%" == "" ( + echo LLVM not found on the path, or in the registry. Please verify your installation. + goto ERR +) + +:detect_llvm_done +for /F "usebackq tokens=3" %%X in (`CALL "%LLVM_DIR%\bin\clang-cl.exe" --version ^| findstr "clang version"`) do set CLANG_VERSION=%%X + +if NOT "%verbose%" == "" ( + echo Using Clang/LLVM + echo Version : %CLANG_VERSION% + echo Location : "%LLVM_DIR%" +) + +:EOF +exit /b 0 +:ERR +exit /b 1 \ No newline at end of file diff --git a/build_files/windows/parse_arguments.cmd b/build_files/windows/parse_arguments.cmd index cdf7eb1d661..1c00dd471ca 100644 --- a/build_files/windows/parse_arguments.cmd +++ b/build_files/windows/parse_arguments.cmd @@ -115,6 +115,8 @@ if NOT "%1" == "" ( ) else if "%1" == "doc_py" ( set DOC_PY=1 goto EOF + ) else if "%1" == "msvc" ( + set WITH_MSVC=1 ) else ( echo Command "%1" unknown, aborting! goto ERR diff --git a/build_files/windows/show_help.cmd b/build_files/windows/show_help.cmd index 6ad1adb8c1b..83c3fd61fa5 100644 --- a/build_files/windows/show_help.cmd +++ b/build_files/windows/show_help.cmd @@ -29,6 +29,8 @@ echo - 2019b ^(build with visual studio 2019 Build Tools^) echo - 2022 ^(build with visual studio 2022^) echo - 2022pre ^(build with visual studio 2022 pre-release^) echo - 2022b ^(build with visual studio 2022 Build Tools^) +echo - clang ^(enable building with clang - default on ARM64^) +echo - msvc ^(enable building with msvc - default on x64, unsupported on ARM64^) echo. echo Documentation Targets ^(Not associated with building^) @@ -37,7 +39,6 @@ echo - doc_py ^(Generate sphinx python api docs^) echo. echo Experimental options echo - with_gpu_tests ^(enable both the render and draw gpu test suites including EEVEE, Workbench, Grease Pencil, draw manager and GPU backends^) -echo - clang ^(enable building with clang^) echo - asan ^(enable asan^) echo - ninja ^(enable building with ninja instead of msbuild^) echo. diff --git a/make.bat b/make.bat index b59a94d4860..b04df6b9c0d 100644 --- a/make.bat +++ b/make.bat @@ -47,6 +47,18 @@ if "%LICENSE%" == "1" ( call "%BLENDER_DIR%\build_files\windows\detect_architecture.cmd" if errorlevel 1 goto EOF +REM Enforce the default compiler to be clang on ARM64 +if "%BUILD_ARCH%" == "arm64" ( + if not "%WITH_CLANG%" == "1" ( + if "%WITH_MSVC%" == "1" ( + echo WARNING, MSVC compilation on Windows ARM64 is unsupported, and errors may occur. + ) else ( + echo Windows ARM64 builds with clang by default, enabling. If you wish to use MSVC ^(unsupported^), please use the msvc switch. + set WITH_CLANG=1 + ) + ) +) + if "%BUILD_VS_YEAR%" == "" ( call "%BLENDER_DIR%\build_files\windows\autodetect_msvc.cmd" if errorlevel 1 ( @@ -98,6 +110,14 @@ if "%CMAKE%" == "" ( exit /b 1 ) +if "%WITH_CLANG%" == "1" ( + call "%BLENDER_DIR%\build_files\windows\find_llvm.cmd" + if errorlevel 1 ( + echo LLVM/Clang not found ^(try with the 'verbose' switch for more information^) + goto EOF + ) +) + echo Building blender with VS%BUILD_VS_YEAR% for %BUILD_ARCH% in %BUILD_DIR% call "%BLENDER_DIR%\build_files\windows\check_libraries.cmd"