bugfix [#23257] cmake tests for SSE, but SSE2 gets enabled
authorCampbell Barton <ideasman42@gmail.com>
Wed, 11 Aug 2010 08:23:48 +0000 (08:23 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 11 Aug 2010 08:23:48 +0000 (08:23 +0000)
patch from Vinay Pawar, some minor changes by me.

CMakeLists.txt
build_files/cmake/macros.cmake

index 87265e959e53e73c7b6400e85f976b556ab48b85..cb131c6e5e1cff978a523d48b5ff280be315f9f7 100644 (file)
@@ -316,12 +316,6 @@ IF(UNIX AND NOT APPLE)
 
        SET(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing -Wno-char-subscripts")
 
-       IF(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
-               SET(PLATFORM_CFLAGS " -msse -msse2 ${PLATFORM_CFLAGS}")
-               ADD_DEFINITIONS(-D__SSE__)
-               ADD_DEFINITIONS(-D__MMX__)
-       ENDIF(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
-
        SET(PLATFORM_LINKFLAGS "-pthread")
 
        # Better warnings
@@ -633,12 +627,6 @@ IF(WIN32)
                        SET(WITH_JACK OFF)
                ENDIF(WITH_JACK)
 
-               IF(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
-                       SET(PLATFORM_CFLAGS " -msse -msse2 ${PLATFORM_CFLAGS}")
-                       ADD_DEFINITIONS(-D__SSE__)
-                       ADD_DEFINITIONS(-D__MMX__)
-               ENDIF(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
-
        ENDIF(MSVC)
 
 ENDIF(WIN32)
@@ -819,12 +807,6 @@ IF(APPLE)
                SET(TIFF_LIBPATH ${TIFF}/lib)
        ENDIF(WITH_IMAGE_TIFF)
 
-       IF(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
-               SET(PLATFORM_CFLAGS " -msse -msse2 ${PLATFORM_CFLAGS}")
-               ADD_DEFINITIONS(-D__SSE__)
-               ADD_DEFINITIONS(-D__MMX__)
-       ENDIF(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
-
        SET(EXETYPE MACOSX_BUNDLE)
 
        SET(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
@@ -868,9 +850,26 @@ IF(WITH_BUILDINFO)
                ENDIF(BUILD_REV_RETURN)
        ENDIF(WIN32)
 ENDIF(WITH_BUILDINFO)
-       
 #-----------------------------------------------------------------------------
 # Common.
+
+IF(WITH_RAYOPTIMIZATION)
+       IF(CMAKE_COMPILER_IS_GNUCC)
+               IF(SUPPORT_SSE_BUILD)
+                       SET(PLATFORM_CFLAGS " -msse ${PLATFORM_CFLAGS}")
+                       ADD_DEFINITIONS(-D__SSE__)
+                       ADD_DEFINITIONS(-D__MMX__)
+               ENDIF(SUPPORT_SSE_BUILD)
+               IF(SUPPORT_SSE2_BUILD)
+                       SET(PLATFORM_CFLAGS " -msse2 ${PLATFORM_CFLAGS}")
+                       ADD_DEFINITIONS(-D__SSE2__)
+                       IF(NOT SUPPORT_SSE_BUILD) # dont double up
+                               ADD_DEFINITIONS(-D__MMX__)
+                       ENDIF(NOT SUPPORT_SSE_BUILD)
+               ENDIF(SUPPORT_SSE2_BUILD)
+       ENDIF(CMAKE_COMPILER_IS_GNUCC)
+ENDIF(WITH_RAYOPTIMIZATION)
+
 IF(WITH_IMAGE_OPENJPEG)
        set(OPENJPEG ${CMAKE_SOURCE_DIR}/extern/libopenjpeg)
        set(OPENJPEG_INC ${OPENJPEG})
index 22c090342ef7b4b8a8d74025ddc1500697c48668..0957ace301c14007a9d5963a91b8972a14c8e5f5 100644 (file)
@@ -183,19 +183,38 @@ MACRO(SETUP_LIBLINKS
 ENDMACRO(SETUP_LIBLINKS)
 
 MACRO(TEST_SSE_SUPPORT)
-       INCLUDE(CheckCXXSourceCompiles)
+       INCLUDE(CheckCSourceRuns)
 
        MESSAGE(STATUS "Detecting SSE support")
        IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
                SET(CMAKE_REQUIRED_FLAGS "-msse -msse2")
        ELSEIF(MSVC)
-               SET(CMAKE_REQUIRED_FLAGS "/arch:SSE2")
+               SET(CMAKE_REQUIRED_FLAGS "/arch:SSE2") # TODO, SSE 1 ?
        ENDIF()
 
-       CHECK_CXX_SOURCE_COMPILES("
+       CHECK_C_SOURCE_RUNS("
                #include <xmmintrin.h>
                int main() { __m128 v = _mm_setzero_ps(); return 0; }"
        SUPPORT_SSE_BUILD)
+
+       CHECK_C_SOURCE_RUNS("
+               #include <emmintrin.h>
+               int main() { __m128d v = _mm_setzero_pd(); return 0; }"
+       SUPPORT_SSE2_BUILD)
+       MESSAGE(STATUS "Detecting SSE support")
+
+       IF(SUPPORT_SSE_BUILD)
+               MESSAGE(STATUS "   ...SSE support found.")
+       ELSE(SUPPORT_SSE_BUILD)
+               MESSAGE(STATUS "   ...SSE support missing.")
+       ENDIF(SUPPORT_SSE_BUILD)
+
+       IF(SUPPORT_SSE2_BUILD)
+               MESSAGE(STATUS "   ...SSE2 support found.")
+       ELSE(SUPPORT_SSE2_BUILD)
+               MESSAGE(STATUS "   ...SSE2 support missing.")
+       ENDIF(SUPPORT_SSE2_BUILD)
+
 ENDMACRO(TEST_SSE_SUPPORT)