[PATCH 2/2] perform compile test to select -march or -mcpu for clang
authorAndreas Beckmann <anbe@debian.org>
Wed, 16 Jan 2019 21:37:17 +0000 (21:37 +0000)
committerAndreas Beckmann <anbe@debian.org>
Mon, 4 Feb 2019 23:39:59 +0000 (23:39 +0000)
Gbp-Pq: Name find-clang-march-mcpu-flag.patch

cmake/LLVM.cmake

index 16edc2bd5ce6da2512cf8df177970ed2a6ac9166..3b511a0107e3ffee42a7a8cd23352a2eabeb4f16 100644 (file)
@@ -502,15 +502,6 @@ if(NOT DEFINED LINK_WITH_CLANG)
 
 endif()
 
-####################################################################
-#X86 has -march and -mcpu reversed, for clang
-
-if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "(powerpc|armv7|aarch64)")
-  set(CLANG_MARCH_FLAG "-mcpu=")
-else()
-  set(CLANG_MARCH_FLAG "-march=")
-endif()
-
 ####################################################################
 
 macro(CHECK_ALIGNOF TYPE TYPEDEF OUT_VAR)
@@ -715,6 +706,26 @@ else()
 endif()
 
 
+####################################################################
+# Some architectures have -march and -mcpu reversed
+
+if(NOT DEFINED ${CLANG_MARCH_FLAG})
+  message(STATUS "Checking clang -march vs. -mcpu flag")
+  custom_try_compile_clang_silent("" "return 0;" RES ${CLANG_TARGET_OPTION}${LLC_TRIPLE} -march=${LLC_HOST_CPU})
+  if(NOT RES)
+    set(CLANG_MARCH_FLAG "-march=")
+  else()
+    custom_try_compile_clang_silent("" "return 0;" RES ${CLANG_TARGET_OPTION}${LLC_TRIPLE} -mcpu=${LLC_HOST_CPU})
+    if(NOT RES)
+      set(CLANG_MARCH_FLAG "-mcpu=")
+    else()
+      message(FATAL_ERROR "Could not determine whether to use -march or -mcpu with clang")
+    endif()
+  endif()
+
+  set(CLANG_MARCH_FLAG ${CLANG_MARCH_FLAG} CACHE INTERNAL "Clang option used to specify the target cpu")
+endif()
+
 ####################################################################
 
 # This tests that we can actually link to the llvm libraries.