Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect sse availability in CMake

In a CMakeLists.txt file, is there a way to detect the highest level of SSE available, and save it to CMAKE_CXX_FLAGS? In other words, I'd like to be able to write something like:

FindSSE()  # defines SSE_FLAGS
set(CMAKE_CXX_FLAGS ${SSE_FLAGS})

For example, if the platform supports up to SSE level 3, then FindSSE() would set SSE_FLAGS to -msse3.

like image 680
SuperElectric Avatar asked Aug 01 '11 16:08

SuperElectric


1 Answers

This might be overkill, but the OptimizeForArchitecture.cmake from vc on gitorious will provide a list of optimizations based on the architecture.

You could either use that script directly or trim it down to the code you need.

A better solution would be to make a small cmake test script that uses SSE instructions and check if each variant compiles/runs.

EDIT: More specifically, there's also FindSSE.cmake in various places, although it still uses the somewhat clunky method of parsing /proc/cpuinfo

like image 181
jkerian Avatar answered Oct 16 '22 03:10

jkerian