2021-07-24 01:21:26 +00:00
|
|
|
set(OPTIMIZE_FOR_NATIVE AUTO CACHE STRING "Build with -march=native")
|
2021-07-25 03:42:30 +00:00
|
|
|
set_property(CACHE OPTIMIZE_FOR_NATIVE PROPERTY STRINGS AUTO ON OFF)
|
2021-07-24 01:21:26 +00:00
|
|
|
|
2021-07-24 01:28:10 +00:00
|
|
|
set(OPTIMIZE_FOR_NATIVE_ARCH "none")
|
2021-07-25 03:42:30 +00:00
|
|
|
if(OPTIMIZE_FOR_NATIVE STREQUAL "ON" OR (OPTIMIZE_FOR_NATIVE STREQUAL "AUTO" AND OPTIMIZE_FOR_NATIVE_DEFAULT))
|
2021-07-24 00:25:42 +00:00
|
|
|
CHECK_C_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
|
|
|
|
if(COMPILER_SUPPORTS_MARCH_NATIVE)
|
2021-07-24 01:28:10 +00:00
|
|
|
set(OPTIMIZE_FOR_NATIVE_ARCH "native")
|
|
|
|
set(OPTIMIZE_FOR_NATIVE_ON ON)
|
2021-07-24 00:25:42 +00:00
|
|
|
endif()
|
2021-07-25 03:42:30 +00:00
|
|
|
elseif(OPTIMIZE_FOR_NATIVE STREQUAL "AUTO" OR OPTIMIZE_FOR_NATIVE STREQUAL "OFF")
|
2021-07-24 00:25:42 +00:00
|
|
|
CHECK_C_COMPILER_FLAG("-march=x86-64-v2" COMPILER_SUPPORTS_MARCH_X86_64_V2)
|
|
|
|
if(COMPILER_SUPPORTS_MARCH_X86_64_V2)
|
2021-07-24 01:28:10 +00:00
|
|
|
set(OPTIMIZE_FOR_NATIVE_ARCH "x86-64-v2")
|
2021-07-24 00:25:42 +00:00
|
|
|
else()
|
|
|
|
CHECK_C_COMPILER_FLAG("-march=nehalem" COMPILER_SUPPORTS_MARCH_NEHALEM)
|
|
|
|
if(COMPILER_SUPPORTS_MARCH_NEHALEM)
|
2021-07-24 01:28:10 +00:00
|
|
|
set(OPTIMIZE_FOR_NATIVE_ARCH "nehalem")
|
2021-07-24 00:25:42 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2021-07-24 01:28:10 +00:00
|
|
|
else()
|
|
|
|
set(OPTIMIZE_FOR_NATIVE_ARCH "${OPTIMIZE_FOR_NATIVE}")
|
|
|
|
set(OPTIMIZE_FOR_NATIVE_ON ON)
|
2021-07-24 00:25:42 +00:00
|
|
|
endif()
|
2021-07-24 01:28:10 +00:00
|
|
|
|
|
|
|
if(NOT OPTIMIZE_FOR_NATIVE_ARCH STREQUAL "none")
|
|
|
|
add_compile_options("-march=${OPTIMIZE_FOR_NATIVE_ARCH}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_feature_info(OPTIMIZE_FOR_NATIVE OPTIMIZE_FOR_NATIVE_ON "Optimized for ${OPTIMIZE_FOR_NATIVE_ARCH}")
|