Compiling ARM64 ASM in Visual Studio with CMake

Hi folks,
I’m working on a cross-platform project which has some hand-written assembly to optimize performance for various CPU architectures. I’m converting this project to CMake from a proprietary build system, starting with compiling using Visual Studio on Windows. For x86 and AMD64, I’ve been able to assemble and link everything just fine, but I can’t get it to work on ARM64 (or presumably ARM32, though I haven’t tried that yet).

I’m including the ASM files in my sources as follows:

if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
    list(APPEND SOURCES
        amd64/aesasm.asm
        ...)
    set_source_files_properties(
        amd64/aesasm.asm
        ...
        PROPERTY LANGUAGE ASM_MASM)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "X86")
    # ...
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")
    list(APPEND SOURCES
        arm64/fdef_asm.asm
        ...)
    set_source_files_properties(
        arm64/fdef_asm.asm
        ...
        PROPERTY LANGUAGE ASM_MASM)

Then in my top-level CMakeLists.txt, I enable MASM using enable_language(ASM_MASM). For x86 and AMD64, CMake automatically finds ml/ml64.exe, configures the Visual Studio project correctly, and everything works.

But for ARM64, if I try the same thing, I get this error from Visual Studio when trying to compile: MSB3721: The command "echo MASM not supported on this platform. As far as I can tell, this is because Visual Studio considers ARM assembly to be a different dialect, “MARMASM”, with a different executable name for the assembler (armasm/armasm64.exe).

I tried setting enable_language(ASM_MARMASM) in my ARM64 toolchain file, but CMake does not recognize this as an ASM dialect, and gives me this error:

CMake Error: Could not find cmake module file: CMakeDetermineASM_MARMASMCompiler.cmake
CMake Error: Could not find cmake module file: F:/os/src/symcrypt/bin/CMakeFiles/3.15.3/CMakeASM_MARMASMCompiler.cmake
CMake Error at CMakeLists.txt:49 (enable_language):
No CMAKE_ASM_MARMASM_COMPILER could be found.

I also tried manually setting the assembler:

get_filename_component(VS_TOOLS_DIRECTORY ${CMAKE_LINKER} DIRECTORY)
find_file(ARM64_COMPILER "armasm64.exe" HINTS ${VS_TOOLS_DIRECTORY})
set(CMAKE_ASM_MARMASM_COMPILER ${ARM64_COMPILER})
enable_language(ASM_MARMASM)
message(STATUS "Manually set assembler to ${CMAKE_ASM_MARMASM_COMPILER}")

But this does not work either; I still get an error that No CMAKE_ASM_MARMASM_COMPILER could be found.

How can I include ARM/ARM64 assembly in my project?