How to detect target architecture using CMake?

后端 未结 8 1420
感情败类
感情败类 2020-12-08 02:17

I\'ve done a lot of research and been unable to find an answer to this... how can I reliably find the target architecture I\'m compiling for, using CMake? Basically, the equ

8条回答
  •  不思量自难忘°
    2020-12-08 02:49

    I've a Solution for the Case where the Host and Target System are the same.

    First you need to call "uname -m" to get the "machine hardware name". Afterwards you need to cut off the trailing "Carriage Return" to get the actual Value back into the provided Variable.

    EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
    

    Now you can print out the Variable ${ARCHITECTURE}:

    message( STATUS "Architecture: ${ARCHITECTURE}" )
    

    or do some Canonisation to map, e.g. "x86_64", "amd64", ... to e.g. "64Bit". Same goes for 32Bit. With this you can execute archtecture dependend Compilation like:

    if( ${ARCHITECTURE} STREQUAL "64Bit" )
        set( BLA_LIBRARY "/opt/lib/libBla.so" )
    else()
        set( BLA_LIBRARY "/opt/lib32/libBla.so" )
    endif()
    

提交回复
热议问题