From 38cb348201add7d1dde05388888a34b9e48ee026 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Fri, 23 Jul 2021 18:21:26 -0700 Subject: [PATCH] [all] make OPTIMIZE_FOR_NATIVE a tristate option --- client/CMakeLists.txt | 1 + cmake/OptimizeForNative.cmake | 8 +++++--- obs/CMakeLists.txt | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 63b92d30..085bd6f7 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -8,6 +8,7 @@ include(GNUInstallDirs) include(CheckCCompilerFlag) include(FeatureSummary) +set(OPTIMIZE_FOR_NATIVE_DEFAULT ON) include(OptimizeForNative) # option(OPTIMIZE_FOR_NATIVE) find_package(PkgConfig) diff --git a/cmake/OptimizeForNative.cmake b/cmake/OptimizeForNative.cmake index a2c5f92c..c5dbf179 100644 --- a/cmake/OptimizeForNative.cmake +++ b/cmake/OptimizeForNative.cmake @@ -1,10 +1,12 @@ -option(OPTIMIZE_FOR_NATIVE "Build with -march=native" OFF) -if(OPTIMIZE_FOR_NATIVE) +set(OPTIMIZE_FOR_NATIVE AUTO CACHE STRING "Build with -march=native") +set_property(CACHE OPTIMIZE_FOR_NATIVE PROPERTY STRINGS AUTO ON OFF GENERIC) + +if(OPTIMIZE_FOR_NATIVE STREQUAL "ON" OR (OPTIMIZE_FOR_NATIVE STREQUAL "AUTO" AND OPTIMIZE_FOR_NATIVE_DEFAULT)) CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) if(COMPILER_SUPPORTS_MARCH_NATIVE) add_compile_options("-march=native") endif() -else() +elseif(OPTIMIZE_FOR_NATIVE STREQUAL "AUTO" OR OPTIMIZE_FOR_NATIVE STREQUAL "GENERIC") CHECK_C_COMPILER_FLAG("-march=x86-64-v2" COMPILER_SUPPORTS_MARCH_X86_64_V2) if(COMPILER_SUPPORTS_MARCH_X86_64_V2) add_compile_options("-march=x86-64-v2") diff --git a/obs/CMakeLists.txt b/obs/CMakeLists.txt index 64045705..4077c70f 100644 --- a/obs/CMakeLists.txt +++ b/obs/CMakeLists.txt @@ -8,6 +8,7 @@ include(GNUInstallDirs) include(CheckCCompilerFlag) include(FeatureSummary) +set(OPTIMIZE_FOR_NATIVE_DEFAULT ON) include(OptimizeForNative) # option(OPTIMIZE_FOR_NATIVE) option(ENABLE_BACKTRACE "Enable backtrace support on crash" ON)