summaryrefslogtreecommitdiffstats
path: root/SetFlags.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'SetFlags.cmake')
-rw-r--r--SetFlags.cmake13
1 files changed, 11 insertions, 2 deletions
diff --git a/SetFlags.cmake b/SetFlags.cmake
index 4ef8ecd2a..d3a7801ee 100644
--- a/SetFlags.cmake
+++ b/SetFlags.cmake
@@ -96,9 +96,18 @@ function(set_global_flags)
add_link_options(-m32)
endif()
+ # https://en.wikipedia.org/wiki/Uname
+ # https://gcc.gnu.org/onlinedocs/gcc/index.html
# Have the compiler generate code specifically targeted at the current machine on Linux:
- if(LINUX AND NOT NO_NATIVE_OPTIMIZATION)
- add_compile_options(-march=native)
+ if(UNIX AND NOT NO_NATIVE_OPTIMIZATION AND NOT CMAKE_CROSSCOMPILING)
+ string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} SYSTEM_PROCESSOR)
+ if (SYSTEM_PROCESSOR MATCHES "^(i386|i686|x86|amd64|mips)")
+ message(STATUS "Optimising for this machine (march=native)")
+ add_compile_options(-march=native)
+ elseif (SYSTEM_PROCESSOR MATCHES "^(arm|aarch|powerpc|ppc|sparc|alpha)")
+ message(STATUS "Optimising for this machine (mcpu=native)")
+ add_compile_options(-mcpu=native)
+ endif()
endif()
endfunction()