[cmake] Add proper SSE/NEON detection

Detect actual use of SSE/NEON depending on defined symbols rather than
CMake flags.
This commit is contained in:
Armin Novak 2024-07-04 09:32:55 +02:00
parent f522bc8a90
commit b6dcefb126
No known key found for this signature in database
GPG Key ID: 2CF4A2D2D3D72105

View File

@ -62,6 +62,25 @@ list(APPEND CODEC_SRCS ${CODEC_NEON_SRCS})
include(CompilerDetect) include(CompilerDetect)
if(WITH_SSE2) 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(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
if (CODEC_SSE2_SRCS) if (CODEC_SSE2_SRCS)
set_source_files_properties(${CODEC_SSE2_SRCS} PROPERTIES COMPILE_FLAGS "-msse2" ) set_source_files_properties(${CODEC_SSE2_SRCS} PROPERTIES COMPILE_FLAGS "-msse2" )
@ -72,17 +91,18 @@ if(WITH_SSE2)
if (CODEC_SSE2_SRCS) if (CODEC_SSE2_SRCS)
set_source_files_properties(${CODEC_SSE2_SRCS} PROPERTIES COMPILE_FLAGS "/arch:SSE2" ) set_source_files_properties(${CODEC_SSE2_SRCS} PROPERTIES COMPILE_FLAGS "/arch:SSE2" )
endif() endif()
endif() endif()
endif()
endif() endif()
if(WITH_NEON) if(WITH_NEON)
check_symbol_exists("_M_AMD64" "" MSVC_ARM64) check_symbol_exists("_M_ARM64" "" MSVC_ARM64)
check_symbol_exists("__aarch64__" "" ARCH_ARM64) check_symbol_exists("__aarch64__" "" ARCH_ARM64)
if (NOT MSVC_ARM64 AND NOT ARCH_ARM64) if (MSVC_ARM64 OR ARCH_ARM64)
if (CODEC_SSE2_SRCS) if (CODEC_SSE2_SRCS)
set_source_files_properties(${CODEC_NEON_SRCS} PROPERTIES COMPILE_FLAGS "-mfpu=neon" ) set_source_files_properties(${CODEC_NEON_SRCS} PROPERTIES COMPILE_FLAGS "-mfpu=neon" )
endif() endif()
endif() endif()
endif() endif()
if (WITH_DSP_FFMPEG) if (WITH_DSP_FFMPEG)