Fix SSE 4.2 checks.

CMake has "normal" and "cache" variables, and unexpected things happen
if you have a normal and a cache variable with the same name.
Apparently, check_c_compiler_flag() currently sets its result variable
as a cache variable, and set(), by default, sets it as a normal
variable.

This means that there are two different HAVE_SSE4_2 variables, and the
top-level CMakeLists.txt looks at the cache variable when it creates
config.h; this means that if the nmmintrin.h test fails, config.h still
says we have SSE 4.2.

Instead, use separate variables for the "compiler can be made to
generate SSE 4.2 code" test and the "nmmintr.h works" test; that way we
don't have to worry about normal vs.  cache variables (and don't have to
worry about CMake changing what type of variable particular
functions/macros set).

Change-Id: I618ad402b248f35fffd822974b6a569d4e5d6398
Reviewed-on: https://code.wireshark.org/review/7073
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2015-02-11 14:19:57 -08:00
parent 0dbf741865
commit d3d0a0a802
1 changed files with 14 additions and 14 deletions

View File

@ -86,22 +86,22 @@ set(WSUTIL_FILES
# -xarch=sse4_2 flag.
#
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
set(HAVE_SSE4_2 TRUE)
set(COMPILER_CAN_HANDLE_SSE4_2 TRUE)
set(SSE4_2_FLAG "")
else()
message(STATUS "Checking for c-compiler flag: -msse4.2")
check_c_compiler_flag(-msse4.2 HAVE_SSE4_2)
if(HAVE_SSE4_2)
check_c_compiler_flag(-msse4.2 COMPILER_CAN_HANDLE_SSE4_2)
if(COMPILER_CAN_HANDLE_SSE4_2)
set(SSE4_2_FLAG "-msse4.2")
else()
message(STATUS "Checking for c-compiler flag: -xarch=sse4_2")
check_c_compiler_flag(-xarch=sse4_2 HAVE_SSE4_2)
if(HAVE_SSE4_2)
check_c_compiler_flag(-xarch=sse4_2 COMPILER_CAN_HANDLE_SSE4_2)
if(COMPILER_CAN_HANDLE_SSE4_2)
set(SSE4_2_FLAG "-xarch=sse4_2")
endif()
endif()
endif()
if(HAVE_SSE4_2)
if(COMPILER_CAN_HANDLE_SSE4_2)
#
# Make sure we have the necessary header for the SSE4.2 intrinsics
# and that we can use it.
@ -110,17 +110,17 @@ if(HAVE_SSE4_2)
#
# Does this add the SSE4.2 flags to the beginning of CFLAGS?
#
# Note that if there's a mix of "enable SSE 4.2" and"disable
# SSE 4.2" flags, this may not indicate that we can use the
# header. That's not a bug, that's a feature; the other flags
# may have been forced by the build process, e.g. in Gentoo
# Linux, and we want to check this with whatever flags will
# actually be used when building (see bug 10792).
#
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${SSE4_2_FLAG}")
check_include_file("nmmintrin.h" CAN_USE_SSE4_2)
check_include_file("nmmintrin.h" HAVE_SSE4_2)
cmake_pop_check_state()
if(NOT CAN_USE_SSE4_2)
#
# OK, it's not working for some reason, perhaps because
# ${SSE4_2_FLAG} above didn't enable SSE 4.2 support.
#
set(HAVE_SSE4_2 FALSE)
endif()
endif()
if(HAVE_SSE4_2)
set(WSUTIL_FILES ${WSUTIL_FILES} ws_mempbrk_sse42.c)