如何在 OS X 上使用 CMake,以新的 Arm M1 为目标

How do I use CMake on OS X, target the new Arm M1

我有一些使用 cmake 的依赖项需要编译,但我不确定我是否正确地执行了此操作。我目前在我的 CFLAGS 中为 amd64 使用 -march=x86-64,这似乎可以工作,但我不确定这是否正确,因为当我尝试以新 M1 为目标时它不工作。我还应该做些什么来从命令行使用 cmake 来针对不同的体系结构吗?

export CFLAGS="-O2 -march=aarch64 -fomit-frame-pointer -fno-stack-protector -pipe"

cmake -B ${{github.workspace}}/build \
    -G "Unix Makefiles" \
    -D CMAKE_INSTALL_PREFIX=${{github.workspace}}/dist/darwin/arm64 \
    -D CMAKE_VERBOSE_MAKEFILE=ON \
    -D BUILD_SHARED_LIBS=ON \
    -D BUILD_DEMO=ON

cmake --build ${{github.workspace}}/build \
    --parallel 2 \
    --config RelWithDebInfo \
    --clean-first

cmake --install ${{github.workspace}}/build --config RelWithDebInfo

更新:我看到这个错误。

CMake Error at /usr/local/Cellar/cmake/3.18.4/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

"/Applications/Xcode_12.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

-- Configuring incomplete, errors occurred!
See also "/Users/runner/work/project/project/build/CMakeFiles/CMakeOutput.log".

error: unknown target CPU 'aarch64'
note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, x86-64
make[1]: *** [CMakeFiles/cmTC_72653.dir/testCCompiler.c.o] Error 1
make: *** [cmTC_72653/fast] Error 2

就像添加 CFLAG -target arm64-apple-macos10.5 一样简单。