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

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 CMakeLists.txt               |  1 +
 ConfigureChecks.cmake        | 32 ++++++--------------------------
 src/fastscale/CMakeLists.txt | 14 +-------------
 3 files changed, 8 insertions(+), 39 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0993d67..5cbbe35 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,7 @@ include( CheckCSourceCompiles )
 include( CheckIncludeFile )
 include( CheckLibraryExists )
 include( CheckSymbolExists )
+enable_language( ASM )
 
 
 ##### include our cmake modules #################
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 54a05c8..1030fef 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -245,36 +245,16 @@ if( WITH_LAME )
 endif( )
 
 
-##### check architecture
-
-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( )
-
-
 ##### check specific architecture dependant support
 
-if( ${CMAKE_ARCHITECTURE} MATCHES "i.86" )
+if( CMAKE_SYSTEM_PROCESSOR MATCHES "i.86" )
 
   # MMX support
   message( STATUS "Performing MMX support test" )
-  check_c_source_compiles( "
-    int main() {
-      #if defined(__GNUC__)
-      __asm__(\"pxor %mm0, %mm0\");
-      #else
-      #error Not gcc on x86/x86_64
-      #endif
-      return 0;
-    }"
-    HAVE_X86_MMX
-  )
+  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( )
 
 endif( )
diff --git a/src/fastscale/CMakeLists.txt b/src/fastscale/CMakeLists.txt
index 91bb8c7..b057f5d 100644
--- a/src/fastscale/CMakeLists.txt
+++ b/src/fastscale/CMakeLists.txt
@@ -24,19 +24,7 @@ link_directories(
 
 ##### fastscale (static) ########################
 
-set( fastscale_SRCS scale.cpp )
-
-if( HAVE_X86_MMX )
-  list( APPEND fastscale_SRCS asm_scale.S )
-
-  # Force to use C compiler for asm_scale.S instead of ASM
-  # because it contains mixed code - ASM with C definitions
-  set_source_files_properties( asm_scale.S PROPERTIES LANGUAGE C )
-
-  add_compile_options( -DHAVE_X86_MMX )
-endif( )
-
 tde_add_library( fastscale STATIC_PIC AUTOMOC
-  SOURCES ${fastscale_SRCS}
+  SOURCES scale.cpp asm_scale.S
   LINK tdecore-shared
 )
-- 
cgit v1.2.3

