From 9957665f92fe10dff36c70a7db53496ae22fefff Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 15 Jan 2021 23:27:56 +0800 Subject: [PATCH] Fix compilation error on Apple Silicon --- CMakeLists.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a93e06f4e..9ac9ab59f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,23 @@ set (fasttext_VERSION_MINOR 1) include_directories(fasttext) -set(CMAKE_CXX_FLAGS " -pthread -std=c++11 -funroll-loops -O3 -march=native") +if(APPLE) + # on macOS "uname -m" returns the architecture (x86_64 or arm64) + execute_process( + COMMAND uname -m + RESULT_VARIABLE result + OUTPUT_VARIABLE FASTTEXT_OSX_NATIVE_ARCHITECTURE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + if(FASTTEXT_OSX_NATIVE_ARCHITECTURE STREQUAL "arm64") + set(CMAKE_CXX_FLAGS " -pthread -std=c++11 -funroll-loops -O3") + else() + set(CMAKE_CXX_FLAGS " -pthread -std=c++11 -funroll-loops -O3 -march=native") + endif() +else() + set(CMAKE_CXX_FLAGS " -pthread -std=c++11 -funroll-loops -O3 -march=native") +endif() set(HEADER_FILES src/args.h