From b9c032461e7279fc11e7dfe7e92b9212d400e1f0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 29 Nov 2013 12:35:45 +0100 Subject: [PATCH] - add a CMake option to enable/disable SSE2 with Visual C++. This is necessary because since VC 2012 SSE2 is the default instruction set. --- CMakeLists.txt | 18 ++++++++++++++++-- src/CMakeLists.txt | 31 +++++++++++++++++-------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6f9fd6ad..6f07d3ada 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,13 +91,27 @@ if( MSVC ) # Disable run-time type information set( ALL_C_FLAGS "/GF /Gy /GR-" ) + if( CMAKE_SIZEOF_VOID_P MATCHES "4") + # SSE2 option (mostly to switch it off in VC2012 and later where it's the default + option (ZDOOM_USE_SSE2 "Use SSE2 instruction set") + if (ZDOOM_USE_SSE2) + set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:SSE2") + else (ZDOOM_USE_SSE2) + if (MSVC_VERSION GREATER 1699) + # On Visual C++ 2012 and later SSE2 is the default, so we need to switch it off explicitly + set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:IA32") + endif (MSVC_VERSION GREATER 1699) + endif (ZDOOM_USE_SSE2) + endif( CMAKE_SIZEOF_VOID_P MATCHES "4") + # Avoid CRT DLL dependancies in release builds, optionally generate assembly output for checking crash locations. option( ZDOOM_GENERATE_ASM "Generate assembly output." OFF ) if( ZDOOM_GENERATE_ASM ) - set( REL_C_FLAGS "/MT /Oy /FAcs" ) + set( REL_C_FLAGS "/MT /Oy /Oi /FAcs" ) else( ZDOOM_GENERATE_ASM ) - set( REL_C_FLAGS "/MT /Oy" ) + set( REL_C_FLAGS "/MT /Oy /Oi" ) endif( ZDOOM_GENERATE_ASM ) + # Debug allocations in debug builds set( DEB_C_FLAGS "/D _CRTDBG_MAP_ALLOC /MTd" ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 60cdb01f8..972e187db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -367,20 +367,23 @@ endif( NOT NO_ASM ) set( SSE_MATTERS NO ) -# SSE only matters on 32-bit targets. We check compiler flags to know if we can do it. -if( CMAKE_SIZEOF_VOID_P MATCHES "4" AND NOT CMAKE_OSX_ARCHITECTURES MATCHES ppc ) - CHECK_CXX_COMPILER_FLAG( "-msse2 -mfpmath=sse" CAN_DO_MFPMATH ) - CHECK_CXX_COMPILER_FLAG( -arch:SSE2 CAN_DO_ARCHSSE2 ) - if( CAN_DO_MFPMATH ) - set( SSE1_ENABLE "-msse -mfpmath=sse" ) - set( SSE2_ENABLE "-msse2 -mfpmath=sse" ) - set( SSE_MATTERS YES ) - elseif( CAN_DO_ARCHSSE2 ) - set( SSE1_ENABLE -arch:SSE ) - set( SSE2_ENABLE -arch:SSE2 ) - set( SSE_MATTERS YES ) - endif( CAN_DO_MFPMATH ) -endif( CMAKE_SIZEOF_VOID_P MATCHES "4" AND NOT CMAKE_OSX_ARCHITECTURES MATCHES ppc ) +# with global use of SSE 2 we do not need special handling for selected files +if (NOT ZDOOM_USE_SSE2) + # SSE only matters on 32-bit targets. We check compiler flags to know if we can do it. + if( CMAKE_SIZEOF_VOID_P MATCHES "4" AND NOT CMAKE_OSX_ARCHITECTURES MATCHES ppc ) + CHECK_CXX_COMPILER_FLAG( "-msse2 -mfpmath=sse" CAN_DO_MFPMATH ) + CHECK_CXX_COMPILER_FLAG( -arch:SSE2 CAN_DO_ARCHSSE2 ) + if( CAN_DO_MFPMATH ) + set( SSE1_ENABLE "-msse -mfpmath=sse" ) + set( SSE2_ENABLE "-msse2 -mfpmath=sse" ) + set( SSE_MATTERS YES ) + elseif( CAN_DO_ARCHSSE2 ) + set( SSE1_ENABLE -arch:SSE ) + set( SSE2_ENABLE -arch:SSE2 ) + set( SSE_MATTERS YES ) + endif( CAN_DO_MFPMATH ) + endif( CMAKE_SIZEOF_VOID_P MATCHES "4" AND NOT CMAKE_OSX_ARCHITECTURES MATCHES ppc ) +endif (NOT ZDOOM_USE_SSE2) if( SSE_MATTERS ) if( WIN32 )