toolchain_x86_64.cmake
set(CMAKE_SYSTEM_NAME Darwin) # 设置操作系统为 Monterey(macOS)
set(CMAKE_SYSTEM_PROCESSOR x86_64) # 设置目标处理器架构为 x86_64
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(CMAKE_CROSSCOMPILING true)
# 设置交叉编译工具链路径
set(CMAKE_C_COMPILER /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang)
set(CMAKE_CXX_COMPILER /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
add_compile_options(-arch x86_64)
else()
add_compile_options(-arch arm64)
endif()
执行cmake时生
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain_x86_x64 path_to_source && cmake --build .
然后查看二进制arch
lipo -info path_to_binary
标签:set,CMAKE,x86,x84,mac,64,cmake,arch
From: https://www.cnblogs.com/nocanstillbb/p/17498538.html