Skip to content

Commit

Permalink
fix: enable native optimization only on x64
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Mar 6, 2022
1 parent 3c3e997 commit 49f6cdc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Optimization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ macro(enable_interprocedural_optimization)
endmacro()

macro(enable_native_optimization project_name)
message(STATUS "Enabling the optimizations specific to the current build machine (less portable)")
if(MSVC)
target_compile_options(${project_name} INTERFACE /arch:native)
else()
target_compile_options(${project_name} INTERFACE -march=native)
detect_architecture(_arch)
if("${_arch}" STREQUAL "x64")
message(STATUS "Enabling the optimizations specific to the current build machine (less portable)")
if(MSVC)
# TODO It seems it only accepts the exact instruction set like AVX https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64
# target_compile_options(${project_name} INTERFACE /arch:native)
else()
target_compile_options(${project_name} INTERFACE -march=native)
endif()
endif()
endmacro()

0 comments on commit 49f6cdc

Please sign in to comment.