在shell脚本中,有arch指令可以获取到硬件构架,其中arm64的返回aarch64,x86的返回x86_64,那么在shell脚本中,就可以写如下逻辑:
get_arch=`arch`
if [[ $get_arch =~ "x86_64" ]];then
echo "this is x86"
elif [[ $get_arch =~ "aarch64" ]];then
echo "this is arm64"
fi
所以有一种方法是cmake就是利用这个shell指令自己判断
其次也可以自己手动传入硬件构架,但是这样就不是自己判断了。除此之外,cmake里面还有个变量CMAKE_HOST_SYSTEM_PROCESSOR,这个变量值就是硬件构架
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
message(STATUS "this is arm64")
else()
message(STATUS "this is not arm64")
endif()