How to detect target architecture using CMake?

后端 未结 8 1346
感情败类
感情败类 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:43

    This is a well tested way of knowing the host architecture:

    # Store in CMAKE_DEB_HOST_ARCH var the current build architecture
    execute_process(COMMAND
      dpkg-architecture
        -qDEB_HOST_ARCH
      OUTPUT_VARIABLE
        CMAKE_DEB_HOST_ARCH
      OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    

    And use that information later in CMakeLists as you need

    if(${CMAKE_DEB_HOST_ARCH} MATCHES "armhf")
      ...
    elseif(${CMAKE_DEB_HOST_ARCH} MATCHES "i386")
      ...
    else()
      ...
    endif()
    

提交回复
热议问题