From 7b9ed50daaab32e39e5044633c379fc9947c32a7 Mon Sep 17 00:00:00 2001 From: chrisbeall Date: Sat, 18 May 2019 15:15:27 -0700 Subject: [PATCH] Add option to toggle march=native --- CMakeLists.txt | 1 + cmake/GtsamBuildTypes.cmake | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29b31f979..ffcb5341f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -512,6 +512,7 @@ if(GTSAM_UNSTABLE_AVAILABLE) print_config_flag(${GTSAM_BUILD_UNSTABLE} "Build libgtsam_unstable ") endif() string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper) +print_config_flag(${GTSAM_BUILD_WITH_MARCH_NATIVE} "Build for native architecture ") if(NOT MSVC AND NOT XCODE_VERSION) message(STATUS " Build type : ${CMAKE_BUILD_TYPE}") message(STATUS " C compilation flags : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${cmake_build_type_toupper}}") diff --git a/cmake/GtsamBuildTypes.cmake b/cmake/GtsamBuildTypes.cmake index e9521c257..b80765298 100644 --- a/cmake/GtsamBuildTypes.cmake +++ b/cmake/GtsamBuildTypes.cmake @@ -90,6 +90,12 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") endif() endif() +option(GTSAM_BUILD_WITH_MARCH_NATIVE "Enable/Disable building with all instructions supported by native architecture (binary may not be portable!)" ON) +if(GTSAM_BUILD_WITH_MARCH_NATIVE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") +endif() + # Set up build type library postfixes if(GTSAM_BUILD_TYPE_POSTFIXES) foreach(build_type Debug Timing Profiling RelWithDebInfo MinSizeRel)