From d3e8d7a70d3588a68748938fce50a9584cd8c1de Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Thu, 27 Apr 2023 10:25:45 -0700 Subject: [PATCH] Better support for cmake 3.26 and Windows ARM64 (#15704) ### Description In #8953 I introduced a change in our onnxruntime_mlas.cmake that it enables "ASM_MASM" cmake language for all Windows build. ```cmake enable_language(ASM_MASM) ``` Before the change, it is only enabled when onnxruntime_target_platform equals to x64. However, cmake 3.26 added a new language: ASM_MARMASM. According to cmake's manual, ASM_MASM is for Microsoft Assembler ASM_MARMASM is for Microsoft ARM Assembler. This one is new in cmake 3.26. We should choose the right one according to ${onnxruntime_target_platform}. --- cmake/CMakeLists.txt | 2 ++ cmake/adjust_global_compile_flags.cmake | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d5ab7f4b74..65c6faecd4 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -2,7 +2,9 @@ # Licensed under the MIT License. # Minimum CMake required +# TODO: actually we need cmake 3.26+ on Windows but QNN EP's build machine doesn't have it cmake_minimum_required(VERSION 3.24) + cmake_policy(SET CMP0069 NEW) set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) diff --git a/cmake/adjust_global_compile_flags.cmake b/cmake/adjust_global_compile_flags.cmake index 58a9271d26..07bcd3b0d5 100644 --- a/cmake/adjust_global_compile_flags.cmake +++ b/cmake/adjust_global_compile_flags.cmake @@ -222,7 +222,6 @@ endmacro() #Set global compile flags for all the source code(including third_party code like protobuf) #This section must be before any add_subdirectory, otherwise build may fail because /MD,/MT mismatch if (MSVC) - enable_language(ASM_MASM) if (CMAKE_GENERATOR_PLATFORM) # Multi-platform generator set(onnxruntime_target_platform ${CMAKE_GENERATOR_PLATFORM}) @@ -231,18 +230,37 @@ if (MSVC) endif() if (onnxruntime_target_platform STREQUAL "ARM64") set(onnxruntime_target_platform "ARM64") + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.26.0") + enable_language(ASM_MARMASM) + else() + enable_language(ASM_MASM) + endif() elseif (onnxruntime_target_platform STREQUAL "ARM64EC") set(onnxruntime_target_platform "ARM64EC") + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.26.0") + enable_language(ASM_MARMASM) + else() + enable_language(ASM_MASM) + endif() elseif (onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM") set(onnxruntime_target_platform "ARM") + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.26.0") + enable_language(ASM_MARMASM) + else() + enable_language(ASM_MASM) + endif() elseif (onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64") set(onnxruntime_target_platform "x64") + enable_language(ASM_MASM) elseif (onnxruntime_target_platform STREQUAL "Win32" OR onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686") set(onnxruntime_target_platform "x86") + enable_language(ASM_MASM) if (NOT onnxruntime_BUILD_WEBASSEMBLY) message("Enabling SAFESEH for x86 build") set(CMAKE_ASM_MASM_FLAGS "${CMAKE_ASM_MASM_FLAGS} /safeseh") endif() + else() + message(FATAL_ERROR "Unknown CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") endif()