CheckCXXCompilerFlag: "-march=native" incorrectly detected as valid on Mac's M1
I am on Mac's new M1 processor. For the moment, clang does not support -march=native
on that processor. In particular:
$ clang++ -march=native main.cpp
clang: error: the clang compiler does not support '-march=native'
Unfortunately the check that I have for this fails to correctly detect this. In particular, this simple CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(myproject)
add_executable(${PROJECT_NAME} main.cpp)
include(CheckCXXCompilerFlag)
unset(COMPILER_SUPPORTS_MARCH_NATIVE CACHE)
CHECK_CXX_COMPILER_FLAG(-march=native COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
target_compile_options(${PROJECT_NAME} PUBLIC -march=native)
endif()
adds the -march=native
option. Indeed:
$ mkdir build
$ cd build
$ cmake ..
-- The C compiler identification is AppleClang 12.0.5.12050022
-- The CXX compiler identification is AppleClang 12.0.5.12050022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test COMPILER_SUPPORTS_MARCH_NATIVE
-- Performing Test COMPILER_SUPPORTS_MARCH_NATIVE - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/tdegeus/Downloads/build
while
$ make
[ 50%] Building CXX object CMakeFiles/myproject.dir/main.cpp.o
error: unknown target CPU 'vortex'
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[2]: *** [CMakeFiles/myproject.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/myproject.dir/all] Error 2
make: *** [all] Error 2
Note that I tried with
$ cmake --version
cmake version 3.21.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
and
$ clang++ --version
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Edited by Brad King