From 40cd903083b1bd7fe1e9cd3ae38c5b1ae0aeb3c0 Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Wed, 12 Mar 2025 10:37:10 +0900
Subject: Improve code for detection of architecture and MMX support

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 CMakeLists.txt        |  5 ++--
 ConfigureChecks.cmake | 68 +++++++++++++++++----------------------------------
 2 files changed, 24 insertions(+), 49 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d5054b54..6e27d43a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,11 +20,8 @@ tde_set_project_version( )
 ##### general package setup #####################
 
 project( tdemultimedia )
-
 set( PACKAGE tdemultimedia )
 
-enable_testing( )
-
 
 ##### include essential cmake modules ###########
 
@@ -38,6 +35,8 @@ include( CheckCXXSourceCompiles )
 include( CheckFunctionExists )
 include( CheckLibraryExists )
 include( CheckSymbolExists )
+enable_language( ASM )
+enable_testing( )
 
 
 ##### include our cmake modules #################
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 5ffb8e27..76156fec 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -15,52 +15,28 @@ test_big_endian(WORDS_BIGENDIAN)
 
 tde_setup_largefiles( )
 
-if( NOT CMAKE_ARCHITECTURE )
-  execute_process(
-    COMMAND ${CMAKE_C_COMPILER} -dumpmachine
-    OUTPUT_VARIABLE CMAKE_ARCHITECTURE
-    ERROR_VARIABLE CMAKE_ARCHITECTURE
-    OUTPUT_STRIP_TRAILING_WHITESPACE
-    ERROR_STRIP_TRAILING_WHITESPACE )
-  set( CMAKE_ARCHITECTURE "${CMAKE_ARCHITECTURE}" CACHE INTERNAL "" FORCE )
-  message( STATUS "Detected ${CMAKE_ARCHITECTURE} target architecture" )
-endif( NOT CMAKE_ARCHITECTURE )
-
-if( ${CMAKE_ARCHITECTURE} MATCHES "i.86" )
-  if( NOT ASM_COMPILER_VERSION )
-    message( STATUS "Checking binutils version" )
-    execute_process(
-      COMMAND echo
-      COMMAND as -v
-      OUTPUT_VARIABLE ASM_VERSION
-      ERROR_VARIABLE ASM_VERSION
-    )
-    string(REGEX REPLACE ".*version ([0-9][^ \n]*).*" "\\1" ASM_COMPILER_VERSION ${ASM_VERSION} )
-    set( ASM_COMPILER_VERSION "${ASM_COMPILER_VERSION}" CACHE INTERNAL "" FORCE )
-    message( STATUS "Checking binutils version - ${ASM_COMPILER_VERSION}" )
-  endif( NOT ASM_COMPILER_VERSION )
-
-  if( NOT MMX_SUPPORT )
-    message( STATUS "Performing test MMX_SUPPORT" )
-    if( ${ASM_COMPILER_VERSION} VERSION_LESS "2.10" )
-      message( STATUS "Performing test MMX_SUPPORT - Failed" )
-    else( )
-      message( STATUS "Performing test MMX_SUPPORT - Success" )
-      set( MMX_SUPPORT 1 CACHE INTERNAL "" FORCE )
-    endif( )
-  endif( NOT MMX_SUPPORT )
-
-  check_c_source_compiles( "
-    int main() {
-      #if defined(__GNUC__) && defined(__i386__)
-      __asm__(\"movups %xmm0, (%esp)\");
-      #else
-      #error Not gcc on x86
-      #endif
-      return 0; }"
-    HAVE_X86_SSE
-  )
-endif( ${CMAKE_ARCHITECTURE} MATCHES "i.86" )
+
+##### check specific architecture dependant support
+
+if( CMAKE_SYSTEM_PROCESSOR MATCHES "i.86" )
+
+  # MMX support
+  message( STATUS "Performing MMX support test" )
+  cmake_host_system_information( RESULT HAVE_X86_MMX QUERY HAS_MMX )
+  if( HAVE_X86_MMX )
+    message( STATUS "Performing MMX support test - Success" )
+    set( CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DHAVE_X86_MMX" )
+  endif( )
+
+  # SSE support
+	message( STATUS "Performing SSE support test" )
+  cmake_host_system_information( RESULT HAVE_X86_SSE QUERY HAS_SSE )
+  if( HAVE_X86_SSE )
+		message( STATUS "Performing SSE support test - Success" )
+    set( CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -DHAVE_X86_SSE" )
+  endif( )
+
+endif( )
 
 message( STATUS "Cheking system type - ${CMAKE_SYSTEM_NAME}" )
 if( ${CMAKE_SYSTEM_NAME} MATCHES "AIX" )
-- 
cgit v1.2.3

