/
CMake Limitations

CMake Limitations

1. CMAKE_SYSTEM_PROCESSOR wrongly configured in emulated CMake

CMake provides a built-in flag CMAKE_SYSTEM_PROCESSOR to specify the target platform for the build.

CMAKE_SYSTEM_PROCESSOR — CMake 4.0.0-rc1 Documentation

CMAKE_SYSTEM_PROCESSOR flag is derived from environment variables PROCESSOR_ARCHITECTURE and PROCESSOR_ARCHITEW6432. And for emulated CMake, the environment variables could be set to AMD64 or IA32 and CMAKE_SYSTEM_PROCESSOR derives the wrong value.

And if your CMake project uses CMAKE_SYSTEM_PROCESSOR for platform-specific configuration it might fail.

Solution

You can use native CMake. There are no official CMake binaries for Windows Arm64 yet but can be generated from the source CMake | Build from source

2. Native arm64 toolchain with CMake

Visual Studio 2022 Preview 17 provides native Arm64 MSVC toolchain but unfortunately, CMake wouldn’t be able to use them with the visual studio generator.

CMake could be configured to generate the right Visual studio project files but MSBuild seems to be ignoring the directive in the project file

<PreferredToolArchitecture>ARM64</PreferredToolArchitecture>

Solution

You will need to use native CMake build CMake | Build from source , and pass /p:PreferredToolArchitecture=ARM64 to MSBuild through CMake.

Example

cmake --build . -- /p:PreferredToolArchitecture=ARM64

3. Specify a different target processor

Setting -DCMAKE_SYSTEM_PROCESSOR does not seems to have the expected effect, as it's still set to CMAKE_HOST_SYSTEM_PROCESSOR. The documentation does not state this explicitly, but it can be interpreted that a CMAKE_TOOLCHAIN_FILE is needed to set it: CMAKE_SYSTEM_PROCESSOR — CMake 4.0.0-rc1 Documentation.

So, instead, write a cross.cmake file:

set(CMAKE_SYSTEM_NAME "Windows") set(CMAKE_SYSTEM_PROCESSOR "ARM64")

and pass it to cmake instead:

cmake -DCMAKE_TOOLCHAIN_FILE=C:/path/to/cross.cmake

 

 

 

 

 

 

Related content

CMake
More like this
ARM64EC
More like this
Tips and tricks for porting to win-arm64
Tips and tricks for porting to win-arm64
More like this
How to install "working" Visual Studio on ARM64
How to install "working" Visual Studio on ARM64
More like this
How to setup LLVM buildbots for Windows 11 on Arm
How to setup LLVM buildbots for Windows 11 on Arm
More like this
Debug run-time DLL issue
Debug run-time DLL issue
More like this