From 36abe81e9210736fb58a5c17771ed627460da814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 23 Jul 2024 15:52:22 +0300 Subject: [PATCH] cmake: Check whether SME functions can be compiled This fixes builds with top-of-tree Clang for Windows; SME functions require backing up/restoring things that Clang can't express in Windows unwind information - see https://github.com/llvm/llvm-project/issues/80009 for more context (primarily about SVE). Similar checks would also be needed for SVE and dotprod functions, if building with older toolchains. Change-Id: Iab3eeb0a125c3fac9814648288261a056bffc900 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/5729969 Reviewed-by: Justin Green Reviewed-by: Frank Barchard --- CMakeLists.txt | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f521e351..a021623dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ # Originally created for "roxlu build system" to compile libyuv on windows # Run with -DTEST=ON to build unit tests +include(CheckCSourceCompiles) + PROJECT ( YUV C CXX ) # "C" is required even for C++ projects CMAKE_MINIMUM_REQUIRED( VERSION 2.8.12 ) OPTION( UNIT_TEST "Built unit tests" OFF ) @@ -111,11 +113,28 @@ if(NOT MSVC) TARGET_COMPILE_OPTIONS(${ly_lib_name}_sve PRIVATE -march=armv9-a+sve2) LIST(APPEND ly_lib_parts $) - # Enable AArch64 SME kernels. - ADD_LIBRARY(${ly_lib_name}_sme OBJECT - ${ly_src_dir}/rotate_sme.cc) - TARGET_COMPILE_OPTIONS(${ly_lib_name}_sme PRIVATE -march=armv9-a+sme) - LIST(APPEND ly_lib_parts $) + set(OLD_CMAKE_REQURED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + set(OLD_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -march=armv9-a+sme") + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + # Check whether the compiler can compile SME functions; this fails + # with Clang for Windows. + check_c_source_compiles(" +__arm_locally_streaming void func(void) { } +int main(void) { return 0; } + " CAN_COMPILE_SME) + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQURED_FLAGS}) + set(CMAKE_TRY_COMPILE_TARGET_TYPE ${OLD_CMAKE_TRY_COMPILE_TARGET_TYPE}) + + if (CAN_COMPILE_SME) + # Enable AArch64 SME kernels. + ADD_LIBRARY(${ly_lib_name}_sme OBJECT + ${ly_src_dir}/rotate_sme.cc) + TARGET_COMPILE_OPTIONS(${ly_lib_name}_sme PRIVATE -march=armv9-a+sme) + LIST(APPEND ly_lib_parts $) + else() + ADD_DEFINITIONS(-DLIBYUV_DISABLE_SME) + endif() endif() endif()