From f529eda6c32d8c3cb8e7dabbfc84cf87215ce311 Mon Sep 17 00:00:00 2001 From: nzfeng Date: Thu, 22 Sep 2022 16:22:30 -0400 Subject: [PATCH] Edit CMakeLists.txt to handle Apple M1 architecture, which does not support the -march=native flag. --- CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e5dcb1..a512684 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,15 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STR endif() SET(CMAKE_CXX_FLAGS "${BASE_CXX_FLAGS} ${DISABLED_WARNINGS}") - SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG") + + include(CheckCXXCompilerFlag) + unset(COMPILER_SUPPORTS_MARCH_NATIVE CACHE) + CHECK_CXX_COMPILER_FLAG(-march=native COMPILER_SUPPORTS_MARCH_NATIVE) + if(COMPILER_SUPPORTS_MARCH_NATIVE) + SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG") + else() + SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -mcpu=apple-m1 -DNDEBUG") # Apple M1 + endif() elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # using Visual Studio C++