Browse Source

CMake: Fix detection and use of SSE2 compiler flag on MSVC

This is one half of the fix for #1072
rdb 5 years ago
parent
commit
3786dc2aea
2 changed files with 23 additions and 6 deletions
  1. 13 2
      dtool/LocalSetup.cmake
  2. 10 4
      panda/src/pnmimage/CMakeLists.txt

+ 13 - 2
dtool/LocalSetup.cmake

@@ -6,6 +6,7 @@
 # file based on the user's selected configure variables.
 # file based on the user's selected configure variables.
 #
 #
 
 
+include(CheckCXXCompilerFlag)
 include(CheckCXXSourceCompiles)
 include(CheckCXXSourceCompiles)
 include(CheckCSourceRuns)
 include(CheckCSourceRuns)
 include(CheckIncludeFileCXX)
 include(CheckIncludeFileCXX)
@@ -137,8 +138,18 @@ check_include_file_cxx(stdint.h PHAVE_STDINT_H)
 #set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT})
 #set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT})
 
 
 # Do we have SSE2 support?
 # Do we have SSE2 support?
-include(CheckCXXCompilerFlag)
-check_cxx_compiler_flag(-msse2 HAVE_SSE2)
+if(MSVC)
+  check_cxx_source_compiles("
+#if !defined(__SSE2__) && !defined(_M_X64) && !defined(_M_AMD64) && !defined(_M_IX86_FP)
+#error no
+#endif
+int main (int argc, char *argv[]) {
+  return 0;
+}
+" HAVE_SSE2)
+else()
+  check_cxx_compiler_flag(-msse2 HAVE_SSE2)
+endif()
 
 
 # Set LINK_ALL_STATIC if we're building everything as static libraries.
 # Set LINK_ALL_STATIC if we're building everything as static libraries.
 # Also set the library type used for "modules" appropriately.
 # Also set the library type used for "modules" appropriately.

+ 10 - 4
panda/src/pnmimage/CMakeLists.txt

@@ -32,11 +32,17 @@ set(P3PNMIMAGE_IGATEEXT
   pfmFile_ext.h
   pfmFile_ext.h
 )
 )
 
 
-if(HAVE_SSE2 AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND CMAKE_SYSTEM_PROCESSOR MATCHES "86")
+if(HAVE_SSE2 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
   # It's only necessary to do this on 32-bit x86; 64-bit makes SSE2 builtin.
   # It's only necessary to do this on 32-bit x86; 64-bit makes SSE2 builtin.
-  set_source_files_properties(convert_srgb_sse2.cxx PROPERTIES
-    SKIP_UNITY_BUILD_INCLUSION YES
-    COMPILE_FLAGS -msse2)
+  if(MSVC)
+    set_source_files_properties(convert_srgb_sse2.cxx PROPERTIES
+      SKIP_UNITY_BUILD_INCLUSION YES
+      COMPILE_FLAGS /arch:SSE2)
+  else()
+    set_source_files_properties(convert_srgb_sse2.cxx PROPERTIES
+      SKIP_UNITY_BUILD_INCLUSION YES
+      COMPILE_FLAGS -msse2)
+  endif()
 endif()
 endif()
 
 
 composite_sources(p3pnmimage P3PNMIMAGE_SOURCES)
 composite_sources(p3pnmimage P3PNMIMAGE_SOURCES)