[CMake] How to determine CPU features

Richard Wackerbarth richard at NFSNet.org
Fri Mar 26 21:53:54 EDT 2010


This suggestion addresses the potential that the TARGET environment might be able to utilize the feature.
Just because I can compile code for a hypothetical target machine, there is no guarantee that the actual target machine will have the necessary features.

I recognize that most compilations have been done in a configuration where the HOST and TARGET machines are the same machine. However, that is, in reality, a special case.

Richard

On Mar 26, 2010, at 8:12 PM, Mike Jackson wrote:

> 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.
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list