The top level CMakeLists.txt should call enable_language(ASM_MARMASM) on Windows
CMake has multiple ASM dialects. For example, ASM, ASM_MASM and ASM_MARMASM.
On Posix platforms you should use ASM, which uses an AT&T style assembly syntax that gas uses.
On Windows you need to use MASM, which has two dialects: ASM_MASM and ASM_MARMASM.
ASM_MASM is for Intel x86. ASM_MARMASM is for ARM.
You may change PROJECT(XNNPACK C CXX ASM) to:
PROJECT(XNNPACK C CXX)
if (MSVC)
if (CMAKE_VS_PLATFORM_NAME)
# Multi-platform generator
set(xnnpack_target_platform ${CMAKE_VS_PLATFORM_NAME})
else()
set(xnnpack_target_platform ${CMAKE_SYSTEM_PROCESSOR})
endif()
if (xnnpack_target_platform STREQUAL "ARM64")
set(xnnpack_target_platform "ARM64")
enable_language(ASM_MARMASM)
elseif (xnnpack_target_platform STREQUAL "ARM64EC")
enable_language(ASM_MARMASM)
elseif (xnnpack_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM")
set(xnnpack_target_platform "ARM")
enable_language(ASM_MARMASM)
elseif (xnnpack_target_platform STREQUAL "x64" OR xnnpack_target_platform STREQUAL "x86_64" OR xnnpack_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64")
set(xnnpack_target_platform "x64")
enable_language(ASM_MASM)
elseif (xnnpack_target_platform STREQUAL "Win32" OR xnnpack_target_platform STREQUAL "x86" OR xnnpack_target_platform STREQUAL "i386" OR xnnpack_target_platform STREQUAL "i686")
set(xnnpack_target_platform "x86")
enable_language(ASM_MASM)
else()
message(FATAL_ERROR "Unknown CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
else()
enable_language(ASM)
endif()
See: 1. https://cmake.org/cmake/help/latest/envvar/ASM_DIALECT.html 2. https://gitlab.kitware.com/cmake/cmake/-/issues/26617
Our expectation at the moment is a .S file is handled by clang or gcc, which internally will use gas. The code is ATT syntax and has a few directives for labels, alignment. In practice this works for all platform, including Windows, but not with Visual C
For actual Visual C, I've only used cmake on Windows with Visual C 2023 for x86. But I dont think the .S files work?
Do you have a proposal for how this would work? Is there a gas compatible marmasm? It would need to produce coeff object files I expect and the code may need ABI changes
But our simple answer is use clang for Windows. There are .cmd examples in the scripts folder. You can use cmake or bazel