From 3786dc2aeaaf09479e12a590ab426a770f18fdb5 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 20 Dec 2020 18:35:17 +0100 Subject: [PATCH] CMake: Fix detection and use of SSE2 compiler flag on MSVC This is one half of the fix for #1072 --- dtool/LocalSetup.cmake | 15 +++++++++++++-- panda/src/pnmimage/CMakeLists.txt | 14 ++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/dtool/LocalSetup.cmake b/dtool/LocalSetup.cmake index 627fe4c3c9..97b7bcce9a 100644 --- a/dtool/LocalSetup.cmake +++ b/dtool/LocalSetup.cmake @@ -6,6 +6,7 @@ # file based on the user's selected configure variables. # +include(CheckCXXCompilerFlag) include(CheckCXXSourceCompiles) include(CheckCSourceRuns) include(CheckIncludeFileCXX) @@ -137,8 +138,18 @@ check_include_file_cxx(stdint.h PHAVE_STDINT_H) #set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT}) # 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. # Also set the library type used for "modules" appropriately. diff --git a/panda/src/pnmimage/CMakeLists.txt b/panda/src/pnmimage/CMakeLists.txt index 8c6e17abac..9991f25f70 100644 --- a/panda/src/pnmimage/CMakeLists.txt +++ b/panda/src/pnmimage/CMakeLists.txt @@ -32,11 +32,17 @@ set(P3PNMIMAGE_IGATEEXT 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. - 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() composite_sources(p3pnmimage P3PNMIMAGE_SOURCES)