build: add option to specify native -march= flag with VPP_BUILD_NATIVE_ARCH 62/39462/2
authorDamjan Marion <damarion@cisco.com>
Thu, 31 Aug 2023 15:00:16 +0000 (17:00 +0200)
committerOle Tr�an <otroan@employees.org>
Wed, 6 Sep 2023 18:57:54 +0000 (18:57 +0000)
Type: improvement
Change-Id: I98eeba1ad2f9ed0531a7c615e0e70e535f24f813
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/cmake/cpu.cmake

index b54155d..69f83c9 100644 (file)
@@ -59,13 +59,6 @@ endif()
 
 option(VPP_BUILD_NATIVE_ONLY "Build only for native CPU." OFF)
 
-if(VPP_BUILD_NATIVE_ONLY)
-  check_c_compiler_flag("-march=native" compiler_flag_march_native)
-  if(NOT compiler_flag_march_native)
-    message(FATAL_ERROR "Native-only build not supported by compiler")
-  endif()
-endif()
-
 macro(add_vpp_march_variant v)
   cmake_parse_arguments(ARG
     "OFF"
@@ -112,7 +105,14 @@ macro(add_vpp_march_variant v)
 endmacro()
 
 if(VPP_BUILD_NATIVE_ONLY)
-  set(VPP_DEFAULT_MARCH_FLAGS -march=native)
+  set(VPP_BUILD_NATIVE_ARCH "native" CACHE STRING "native CPU -march= value.")
+  set(VPP_DEFAULT_MARCH_FLAGS -march=${VPP_BUILD_NATIVE_ARCH})
+  if(VPP_BUILD_NATIVE_ONLY)
+    check_c_compiler_flag(${VPP_DEFAULT_MARCH_FLAGS} compiler_flag_march)
+    if(NOT compiler_flag_march)
+      message(FATAL_ERROR "Native-only build with ${VPP_DEFAULT_MARCH_FLAGS} is not supported by compiler")
+    endif()
+  endif()
   set(MARCH_VARIANTS_NAMES "native-only")
 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
   set(VPP_DEFAULT_MARCH_FLAGS -march=corei7 -mtune=corei7-avx)