diff options
author | Chris Robinson <[email protected]> | 2022-03-23 23:40:54 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-03-23 23:40:54 -0700 |
commit | bdf18d60db8d339c9fa3506d3eac259f9dd244fc (patch) | |
tree | dd1118816d01757cc39e657035da0af6ca4bb088 | |
parent | 3b09b7761fe625ba157b9913243c556fbebbbbe1 (diff) |
Be more careful about checking compiler flags
Certain combinations of MSVC and CMake seem to allow all compiler flag checks
to pass, which was causing certain GCC attributes to be used on MSVC.
-rw-r--r-- | CMakeLists.txt | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ad956b10..4e3ca446 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -355,17 +355,17 @@ endif() set(SSE2_SWITCH "") -set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) if(NOT MSVC) + set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) # Yes GCC, really don't accept command line options you don't support set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror") + check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH) + if(HAVE_MSSE2_SWITCH) + set(SSE2_SWITCH "-msse2") + endif() + set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS}) + unset(OLD_REQUIRED_FLAGS) endif() -check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH) -if(HAVE_MSSE2_SWITCH) - set(SSE2_SWITCH "-msse2") -endif() -set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS}) -unset(OLD_REQUIRED_FLAGS) check_include_file(xmmintrin.h HAVE_XMMINTRIN_H) check_include_file(emmintrin.h HAVE_EMMINTRIN_H) @@ -450,7 +450,14 @@ set(FPMATH_SET "0") if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2) option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE) if(ALSOFT_ENABLE_SSE2_CODEGEN) - if(SSE2_SWITCH OR NOT MSVC) + if(MSVC) + check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2) + if(HAVE_ARCH_SSE2) + set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2") + set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS}) + set(FPMATH_SET 2) + endif() + elseif(SSE2_SWITCH) check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2) if(HAVE_MFPMATH_SSE_2) set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse) @@ -462,13 +469,6 @@ if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2) # OSs don't guarantee this on 32-bit, so externally-callable # functions need to ensure an aligned stack. set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))") - elseif(MSVC) - check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2) - if(HAVE_ARCH_SSE2) - set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2") - set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS}) - set(FPMATH_SET 2) - endif() endif() endif() endif() |