diff --git a/backends/xnnpack/cmake/Dependencies.cmake b/backends/xnnpack/cmake/Dependencies.cmake index d02ac4a7926..fe81f63dac9 100644 --- a/backends/xnnpack/cmake/Dependencies.cmake +++ b/backends/xnnpack/cmake/Dependencies.cmake @@ -76,6 +76,15 @@ set(XNNPACK_BUILD_ALL_MICROKERNELS OFF CACHE BOOL "" ) + +# XNNPACK nests variadic macros (XNN_RETURN_IF_ERROR expands to xnn_log_error), +# which MSVC's default legacy preprocessor mis-expands. Only observable where +# XNN_LOG_LEVEL is non-zero, i.e. Debug configurations. Not applied to clang-cl, +# which sets MSVC but already has a conforming preprocessor. +if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/Zc:preprocessor) +endif() + add_subdirectory("${XNNPACK_SOURCE_DIR}") include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR}) list(APPEND xnnpack_third_party XNNPACK) diff --git a/tools/cmake/preset/llm.cmake b/tools/cmake/preset/llm.cmake index d1b8064c342..67c9d09b794 100644 --- a/tools/cmake/preset/llm.cmake +++ b/tools/cmake/preset/llm.cmake @@ -20,9 +20,11 @@ set_overridable_option(EXECUTORCH_BUILD_KERNELS_OPTIMIZED ON) set_overridable_option(EXECUTORCH_BUILD_XNNPACK ON) # Turn on the quantized and LLM kernels unless on Windows with MSVC build since -# they don't currently compile. +# they don't currently compile. MSVC is also set for clang-cl, which does +# compile them, so key off the compiler ID instead. if(NOT ((CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL - "WIN32") AND MSVC) + "WIN32") + AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") ) set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED ON) set_overridable_option(EXECUTORCH_BUILD_KERNELS_LLM ON)