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 开发者_JS百科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.
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
精彩评论