Debian Codegraph @

CMakeModules/FindSSE.cmake

raw
1 # Check if SSE instructions are available by the compiler and target platform (be aware of cross compilation)
2 include(CheckCCompilerFlag)
3
4 check_c_compiler_flag(-msse2 HAVE_SSE2)
5 check_c_compiler_flag(-msse3 HAVE_SSE3)
6 check_c_compiler_flag(-mssse3 HAVE_SSSE3)
7 check_c_compiler_flag(-msse4.1 HAVE_SSE4_1)
8
9 # Some compilers understand SSE flags, even when target platform doesn't support it (Clang with arm target)
10 # It is necessary try to compile actual code
11 if(HAVE_SSE2)
12 try_compile(SSE_OK "${PROJECT_BINARY_DIR}"
13 "${CMAKE_CURRENT_LIST_DIR}/TestSSE2.c"
14 COMPILE_DEFINITIONS "-msse2" )
15 if(NOT SSE_OK)
16 message(STATUS "SSE2 test compilation fails")
17 set(HAVE_SSE2 FALSE)
18 endif()
19 endif()
20
21 if(HAVE_SSE3)
22 try_compile(SSE_OK "${PROJECT_BINARY_DIR}"
23 "${CMAKE_CURRENT_LIST_DIR}/TestSSE3.c"
24 COMPILE_DEFINITIONS "-msse3" )
25 if(NOT SSE_OK)
26 message(STATUS "SSE3 test compilation fails")
27 set(HAVE_SSE3 FALSE)
28 endif()
29 endif()
30
31 if(HAVE_SSSE3)
32 try_compile(SSE_OK "${PROJECT_BINARY_DIR}"
33 "${CMAKE_CURRENT_LIST_DIR}/TestSSSE3.c"
34 COMPILE_DEFINITIONS "-mssse3" )
35 if(NOT SSE_OK)
36 message(STATUS "SSE3 test compilation fails")
37 set(HAVE_SSSE3 FALSE)
38 endif()
39 endif()
40
41 if(HAVE_SSE4_1)
42 try_compile(SSE_OK "${PROJECT_BINARY_DIR}"
43 "${CMAKE_CURRENT_LIST_DIR}/TestSSE41.c"
44 COMPILE_DEFINITIONS "-msse4.1" )
45 if(NOT SSE_OK)
46 message(STATUS "SSE4.1 test compilation fails")
47 set(HAVE_SSE4_1 FALSE)
48 endif()
49 endif()
50
51 set(SSE2_FOUND ${HAVE_SSE2} CACHE BOOL "SSE2 available on target")
52 set(SSE3_FOUND ${HAVE_SSE3} CACHE BOOL "SSE3 available on target")
53 set(SSSE3_FOUND ${HAVE_SSSE3} CACHE BOOL "SSSE3 available on target")
54 set(SSE4_1_FOUND ${HAVE_SSE4_1} CACHE BOOL "SSE4.1 available on target")
55
56 if(NOT SSE2_FOUND)
57 MESSAGE(STATUS "SSE2 is not supported on target platform.")
58 endif(NOT SSE2_FOUND)
59 if(NOT SSE3_FOUND)
60 MESSAGE(STATUS "SSE3 is not supported on target platform.")
61 endif(NOT SSE3_FOUND)
62 if(NOT SSSE3_FOUND)
63 MESSAGE(STATUS "SSSE3 is not supported on target platform.")
64 endif(NOT SSSE3_FOUND)
65 if(NOT SSE4_1_FOUND)
66 MESSAGE(STATUS "SSE4.1 is not supported on target platform.")
67 endif(NOT SSE4_1_FOUND)
68
69 mark_as_advanced(SSE2_FOUND SSE3_FOUND SSSE3_FOUND SSE4_1_FOUND)