From 0756ec4643f6d540df05dd44e4ede676f3fad259 Mon Sep 17 00:00:00 2001 From: Mika Lindqvist Date: Thu, 21 Dec 2023 10:19:54 +0200 Subject: [PATCH] Check if compiler supports -march=native or -mcpu=native. --- CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9170ed58..b7d15699 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -252,11 +252,18 @@ endif() # Set native march/mcpu if(WITH_NATIVE_INSTRUCTIONS) if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") - if(BASEARCH_PPC_FOUND) - set(NATIVEFLAG "-mcpu=native") - else() + check_c_compiler_flag(-march=native HAVE_MARCH_NATIVE) + if(HAVE_MARCH_NATIVE) set(NATIVEFLAG "-march=native") + else() + check_c_compiler_flag(-mcpu=native HAVE_MCPU_NATIVE) + if(HAVE_MCPU_NATIVE) + set(NATIVEFLAG "-mcpu=native") + endif() endif() + # Fall through + endif() + if(NATIVEFLAG) # Apply flag to all source files and compilation checks add_compile_options(${NATIVEFLAG}) else() -- 2.47.3