From 3c41de6382d1bfe9d2141c0ffdcf7705d30c2ad2 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 4 Jul 2024 13:25:40 +0200 Subject: [PATCH] [cmake] move intrinsic support to file Create DetectIntrinsicSupport.cmake to unify intrinsic detection and use --- cmake/DetectIntrinsicSupport.cmake | 33 ++++++++++++++++++++++++++++ libfreerdp/codec/CMakeLists.txt | 25 +++------------------ libfreerdp/primitives/CMakeLists.txt | 7 +++++- 3 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 cmake/DetectIntrinsicSupport.cmake diff --git a/cmake/DetectIntrinsicSupport.cmake b/cmake/DetectIntrinsicSupport.cmake new file mode 100644 index 000000000..ca14733c4 --- /dev/null +++ b/cmake/DetectIntrinsicSupport.cmake @@ -0,0 +1,33 @@ +include(CheckSymbolExists) + +check_symbol_exists("__i586__" "" X86_i586) +check_symbol_exists("__i686__" "" X86_i686) +check_symbol_exists("__X86__" "" X86_X86) +check_symbol_exists("_X86_" "" X86_X862) +check_symbol_exists("__I86__" "" X86_I86) +check_symbol_exists("__IA32__" "" X86_IA32) +check_symbol_exists("_M_IX86" "" X86_M_IX86) +check_symbol_exists("__amd64" "" X86_AMD64) +check_symbol_exists("__amd64__" "" X86_AMD642) +check_symbol_exists("__x86_64" "" X86_X86_64) +check_symbol_exists("__x86_64__" "" X86_X86_642) +check_symbol_exists("_M_X64" "" X86_X64) +check_symbol_exists("__ia64" "" X86_IA64) +check_symbol_exists("__ia64__" "" X86_IA642) +check_symbol_exists("_M_IA64" "" X86_M_IA64) +check_symbol_exists("_M_ARM64" "" MSVC_ARM64) +check_symbol_exists("__aarch64__" "" ARCH_ARM64) + +if (X86_i586 OR X86_i686 OR X86_X86 OR X86_X862 OR X86_I86 OR X86_IA32 OR + X86_M_IX86 OR X86_AMD64 OR X86_AMD642 OR X86_X86_64 OR X86_X86_642 OR + X86_X64 OR X86_IA64 OR X86_IA642 OR X86_M_IA64) + set(HAVE_SSE_OR_AVX ON CACHE INTERNAL "internal") +else() + set(HAVE_SSE_OR_AVX OFF CACHE INTERNAL "internal") +endif() + +if (MSVC_ARM64 OR ARCH_ARM64) + set(HAVE_NEON ON CACHE INTERNAL "internal") +else() + set(HAVE_NEON OFF CACHE INTERNAL "internal") +endif() diff --git a/libfreerdp/codec/CMakeLists.txt b/libfreerdp/codec/CMakeLists.txt index 00c12f314..4c3be5277 100644 --- a/libfreerdp/codec/CMakeLists.txt +++ b/libfreerdp/codec/CMakeLists.txt @@ -60,27 +60,11 @@ list(APPEND CODEC_SRCS ${CODEC_SSE2_SRCS}) list(APPEND CODEC_SRCS ${CODEC_NEON_SRCS}) include(CompilerDetect) +include (DetectIntrinsicSupport) if(WITH_SSE2) - check_symbol_exists("__i586__" "" X86_i586) - check_symbol_exists("__i686__" "" X86_i686) - check_symbol_exists("__X86__" "" X86_X86) - check_symbol_exists("_X86_" "" X86_X862) - check_symbol_exists("__I86__" "" X86_I86) - check_symbol_exists("__IA32__" "" X86_IA32) - check_symbol_exists("_M_IX86" "" X86_M_IX86) - check_symbol_exists("__amd64" "" X86_AMD64) - check_symbol_exists("__amd64__" "" X86_AMD642) - check_symbol_exists("__x86_64" "" X86_X86_64) - check_symbol_exists("__x86_64__" "" X86_X86_642) - check_symbol_exists("_M_X64" "" X86_X64) - check_symbol_exists("__ia64" "" X86_IA64) - check_symbol_exists("__ia64__" "" X86_IA642) - check_symbol_exists("_M_IA64" "" X86_M_IA64) - if (X86_i586 OR X86_i686 OR X86_X86 OR X86_X862 OR X86_I86 OR X86_IA32 OR - X86_M_IX86 OR X86_AMD64 OR X86_AMD642 OR X86_X86_64 OR X86_X86_642 OR - X86_X64 OR X86_IA64 OR X86_IA642 OR X86_M_IA64) + if (HAVE_SSE_OR_AVC) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) if (CODEC_SSE2_SRCS) set_source_files_properties(${CODEC_SSE2_SRCS} PROPERTIES COMPILE_FLAGS "-msse2" ) @@ -95,10 +79,7 @@ if(WITH_SSE2) endif() endif() if(WITH_NEON) - check_symbol_exists("_M_ARM64" "" MSVC_ARM64) - check_symbol_exists("__aarch64__" "" ARCH_ARM64) - - if (MSVC_ARM64 OR ARCH_ARM64) + if (HAVE_NEON) if (CODEC_SSE2_SRCS) set_source_files_properties(${CODEC_NEON_SRCS} PROPERTIES COMPILE_FLAGS "-mfpu=neon" ) endif() diff --git a/libfreerdp/primitives/CMakeLists.txt b/libfreerdp/primitives/CMakeLists.txt index 75fc8a7a9..5b9ecec2f 100644 --- a/libfreerdp/primitives/CMakeLists.txt +++ b/libfreerdp/primitives/CMakeLists.txt @@ -87,7 +87,9 @@ add_library(freerdp-primitives OBJECT ) include(CompilerDetect) +include (DetectIntrinsicSupport) if(WITH_SSE2) + if (HAVE_SSE_OR_AVX) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) if(PRIMITIVES_SSE2_SRCS) set_source_files_properties(${PRIMITIVES_SSE2_SRCS} PROPERTIES COMPILE_FLAGS "-msse2" ) @@ -111,14 +113,17 @@ if(WITH_SSE2) if(MSVC) set_source_files_properties(${PRIMITIVES_OPT_SRCS} PROPERTIES COMPILE_FLAGS "/arch:SSE2") - endif() + endif() + endif() elseif(WITH_NEON) + if (HAVE_NEON) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) if (NOT MSVC_ARM64 AND NOT ARCH_ARM64) set_source_files_properties(${PRIMITIVES_OPT_SRCS} PROPERTIES COMPILE_FLAGS "-mfpu=neon") endif() endif() # TODO: Add MSVC equivalent + endif() endif() freerdp_object_library_add(freerdp-primitives)