[CMake] How to determine CPU features
Mike Jackson
mike.jackson at bluequartz.net
Fri Mar 26 21:12:00 EDT 2010
You can use the "Try_Compile()" function with a source file that has
specific SSE and MMX code. If the file compiles correctly then you
have SSE/MMX.
This is what I used:
# --------------- Begin
set (SSE_COMPILE_FLAGS "")
option(AIM_USE_SSE "Use SSE2/3 Instructions where possible." OFF)
if (AIM_USE_SSE)
if (NOT MSVC)
set(CMAKE_REQUIRED_C_FLAGS_SAVE ${CMAKE_REQUIRED_C_FLAGS})
set(CMAKE_REQUIRED_C_FLAGS ${CMAKE_REQUIRED_C_FLAGS} "-msse3")
CHECK_INCLUDE_FILE("pmmintrin.h" HAVE_SSE3_H)
set(CMAKE_REQUIRED_C_FLAGS ${CMAKE_REQUIRED_C_FLAGS_SAVE})
if (HAVE_SSE3_H)
set(HAVE_SSE2_H 1)
if (CMAKE_COMPILER_IS_GNUCC)
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
set (SSE_COMPILE_FLAGS "-msse3")
endif()
else()
set (HAVE_SSE3_H 0)
endif()
if (NOT HAVE_SSE3_H)
set(CMAKE_REQUIRED_C_FLAGS_SAVE ${CMAKE_REQUIRED_C_FLAGS})
set(CMAKE_REQUIRED_C_FLAGS ${CMAKE_REQUIRED_C_FLAGS} "-msse2")
CHECK_INCLUDE_FILE("emmintrin.h" HAVE_SSE2_H)
set(CMAKE_REQUIRED_C_FLAGS ${CMAKE_REQUIRED_C_FLAGS_SAVE})
if(HAVE_SSE2_H)
if (CMAKE_COMPILER_IS_GNUCC)
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
set (SSE_COMPILE_FLAGS "-msse2")
endif()
else()
set (HAVE_SSE2_H 0)
endif()
endif()
else()
set(CMAKE_REQUIRED_C_FLAGS_SAVE ${CMAKE_REQUIRED_C_FLAGS})
set(CMAKE_REQUIRED_C_FLAGS ${CMAKE_REQUIRED_C_FLAGS} "/arch:SSE2")
CHECK_INCLUDE_FILE("intrin.h" HAVE_INTRIN_H)
set(CMAKE_REQUIRED_C_FLAGS ${CMAKE_REQUIRED_C_FLAGS_SAVE})
if (HAVE_INTRIN_H)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
set (SSE_COMPILE_FLAGS " /arch:SSE2 ")
else()
set (HAVE_INTRIN_H 0)
endif()
endif()
endif()
#---------------- End
_________________________________________________________
Mike Jackson mike.jackson at bluequartz.net
BlueQuartz Software www.bluequartz.net
Principal Software Engineer Dayton, Ohio
On Fri, Mar 26, 2010 at 7:23 PM, Alexander Tarasov <altar at gmx.com> wrote:
> Hi All,
>
> Is there a clean way to find out if host CPU supports MMX & SSE2 extensions?
>
> As far as I know this stuff is analyzed by cmake (am I wrong?). However I've
> did not find any way this info can be used in CMakeLists.txt.
>
> Best regards,
> Alexander.
More information about the CMake
mailing list