Compilation and cross-compilation.
Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile "$env:TEMP/vs_BuildTools.exe"
When installing onto an ARM device, this will include ARM64 build tools as well as x86 and x64 1. Note that you'll need to explicitly specify ARM64 build tools ("Microsoft.VisualStudio.Component.VC.Tools.ARM64" 2) to enable cross-compilation targeting ARM64 AND to build natively on ARM64.
& "$env:TEMP/vs_BuildTools.exe" --passive --wait --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --add Microsoft.VisualStudio.Component.VC.Tools.ARM64
Visual Studio Build Tools includes cmake, but it's not put into the PATH.
$env:PATH += ";${Env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin"
Install to \vcpkg
for convenience.
git clone https://github.com/Microsoft/vcpkg.git /vcpkg
\vcpkg\bootstrap-vcpkg.bat
cmake.exe -B build -S . -D CMAKE_TOOLCHAIN_FILE='/vcpkg/scripts/buildsystems/vcpkg.cmake'
cmake.exe --build build --parallel --config Debug
build\Debug\helloworld.exe
Important: VCPKG manifest mode doesn't work if build path includes a backslash. So don't use something like -B build\ARM64
!
Specify platform name using -A ARM64
. Could also use CMAKE_GENERATOR_PLATFORM
or CMAKE_VS_PLATFORM_NAME
cmake.exe -B build_ARM64 -S . -D CMAKE_TOOLCHAIN_FILE='/vcpkg/scripts/buildsystems/vcpkg.cmake' -A ARM64
cmake.exe --build build_ARM64 --parallel --config Debug
On ARM device:
$dumpbin = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\bin\Hostarm64\x64\dumpbin.exe"
On x64 device:
$dumpbin = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\bin\Hostx64\x64\dumpbin.exe"
& $dumpbin /HEADERS build_ARM64\Debug\helloworld.exe | Select-String 'machine' -SimpleMatch
cmake - Cross compiling for x64_arm with MSVC tools on Windows - Stack Overflow
Cross Compiling With CMake — Mastering CMake
Cross-compiling under Visual Studio (#18225) · Issues · CMake - CMake · GitLab
Footnotes
-
See the Component Directory ↩