Detect SSE building support with cmake, and moved setting the defines
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 4 Jul 2010 18:40:59 +0000 (18:40 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 4 Jul 2010 18:40:59 +0000 (18:40 +0000)
out of the render mode cmake file into the main one. Should fix PPC
compile, and hopefully not break others.

CMake/macros.cmake
CMakeLists.txt
source/blender/render/CMakeLists.txt

index 914547e168e351228ea5de8b33b4fb1b5128ec8b..17662c5c447cc10c888c0e9717e536730062c6a5 100644 (file)
@@ -181,3 +181,20 @@ MACRO(SETUP_LIBLINKS
                TARGET_LINK_LIBRARIES(${target} ${PTHREADS_LIB})
        ENDIF(WIN32)
 ENDMACRO(SETUP_LIBLINKS)
+
+MACRO(TEST_SSE_SUPPORT)
+       INCLUDE(CHECKCXXSOURCECOMPILES)
+
+       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")
+       ENDIF()
+
+       CHECK_CXX_SOURCE_COMPILES("
+               #include <xmmintrin.h>
+               int main() { __m128 v = _mm_setzero_ps(); return 0; }"
+       SUPPORT_SSE_BUILD)
+ENDMACRO(TEST_SSE_SUPPORT)
+
index 82c57c014fa95b3e84b77a3634b95baf0062f0b3..1088d95ab67c6cdf6cfd1fcacd6b3e98fffff62e 100644 (file)
@@ -59,6 +59,10 @@ SET(LIBRARY_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/lib)
 # ...but thats quite involved, make sure this matches the blender version.
 SET(BLENDER_VERSION  2.5)
 
+#-----------------------------------------------------------------------------
+# Load some macros.
+INCLUDE(CMake/macros.cmake)
+
 #-----------------------------------------------------------------------------
 # Set default config options
 
@@ -114,7 +118,7 @@ OPTION(WITH_RAYOPTIMIZATION "Enable use of SIMD (SSE) optimizations for the rayt
 OPTION(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking" OFF)
 OPTION(WITH_INSTALL       "Install accompanying scripts and language files needed to run blender" ON)
 
-IF (APPLE)
+IF(APPLE)
        OPTION(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
        OPTION(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
        OPTION(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
@@ -128,6 +132,8 @@ IF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
        MESSAGE("WARNING: WITH_PLAYER needs WITH_GAMEENGINE")
 ENDIF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
 
+TEST_SSE_SUPPORT()
+
 # disabled for now, not supported
 # OPTION(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
 
@@ -139,10 +145,6 @@ ENDIF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
 #
 # When changing any of this remember to update the notes in doc/blender-cmake.txt
 
-#-----------------------------------------------------------------------------
-# Load some macros.
-INCLUDE(CMake/macros.cmake)
-
 #-----------------------------------------------------------------------------
 #Platform specifics
 
@@ -308,9 +310,11 @@ IF(UNIX AND NOT APPLE)
 
        SET(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing -Wno-char-subscripts")
 
-       IF(WITH_RAYOPTIMIZATION)
-               SET(PLATFORM_CFLAGS " -msse ${PLATFORM_CFLAGS}")
-       ENDIF(WITH_RAYOPTIMIZATION)
+       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")
 
@@ -396,6 +400,11 @@ IF(WIN32)
                SET(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
        ENDIF(WITH_QUICKTIME)
 
+       IF(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
+               ADD_DEFINITIONS(-D__SSE__)
+               ADD_DEFINITIONS(-D__MMX__)
+       ENDIF(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
+
        IF(MSVC)
                IF(CMAKE_CL_64)
                        SET(LLIBS kernel32 user32 vfw32 winmm ws2_32 )
@@ -797,6 +806,12 @@ IF(APPLE)
                SET(TIFF_LIBPATH ${TIFF}/lib)
        ENDIF(WITH_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")
index 89bdad7c6c7a691c9714f1755e6d7542da8a60dd..9199a0a33ba87097c18a956bba547487c483ce86 100644 (file)
@@ -54,11 +54,6 @@ IF(APPLE)
        ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES "i386" OR CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
 ENDIF(APPLE)
 
-IF(WITH_RAYOPTIMIZATION)
-       ADD_DEFINITIONS(-D__SSE__)
-       ADD_DEFINITIONS(-D__MMX__)
-ENDIF(WITH_RAYOPTIMIZATION)
-
 #TODO
 #if env['OURPLATFORM']=='linux2':
 #    cflags='-pthread'