[PATCH] D50548: [CMake] Don't parse target triple except for arch

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 9 19:02:26 PDT 2018


phosek created this revision.
phosek added reviewers: morehouse, rnk, echristo, beanz.
Herald added subscribers: Sanitizers, llvm-commits, dexonsmith, mehdi_amini, mgorny, srhines.

compiler-rt CMake build currently tries to parse the triple and then
put it back together, but doing so inherently tricky, and doing so
from CMake is just crazy and currently doesn't handle triples that
have more than three components. Fortunatelly, the CMake really only
needs the architecture part, which is typically the first component,
to construct variants for other architectures. This means we can keep
the rest of the triple as is and avoid the parsing altogether.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D50548

Files:
  compiler-rt/CMakeLists.txt
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake


Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake
===================================================================
--- compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -88,6 +88,23 @@
   set(${input_list} "${replaced_list}" PARENT_SCOPE)
 endfunction()
 
+function(list_sub list begin length variable)
+  set(sublist)
+  list(LENGTH ${list} list_length)
+  if(NOT ${length} EQUAL -1)
+    math(EXPR end "${begin}+${length}")
+  else()
+    math(EXPR end "${list_length}-1")
+  endif()
+  foreach(index RANGE ${begin} ${end})
+    if(index LESS list_length)
+      list(GET ${list} ${index} component)
+      list(APPEND sublist ${component})
+    endif()
+  endforeach()
+  set(${variable} "${sublist}" PARENT_SCOPE)
+endfunction()
+
 # Takes ${ARGN} and puts only supported architectures in @out_var list.
 function(filter_available_targets out_var)
   set(archs ${${out_var}})
@@ -276,11 +293,8 @@
 
   string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
   list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH)
-  list(GET TARGET_TRIPLE_LIST 1 COMPILER_RT_DEFAULT_TARGET_OS)
-  list(LENGTH TARGET_TRIPLE_LIST TARGET_TRIPLE_LIST_LENGTH)
-  if(TARGET_TRIPLE_LIST_LENGTH GREATER 2)
-    list(GET TARGET_TRIPLE_LIST 2 COMPILER_RT_DEFAULT_TARGET_ABI)
-  endif()
+  list_sub(TARGET_TRIPLE_LIST 1 -1 TARGET_TRIPLE_SUBLIST)
+  string(REPLACE ";" "-" COMPILER_RT_DEFAULT_TARGET_TRIPLE_SUFFIX "${TARGET_TRIPLE_SUBLIST}")
   # Determine if test target triple is specified explicitly, and doesn't match the
   # default.
   if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE)
@@ -321,12 +335,9 @@
 
 function(get_compiler_rt_target arch variable)
   if(ANDROID AND ${arch} STREQUAL "i386")
-    set(target "i686${COMPILER_RT_OS_SUFFIX}-${COMPILER_RT_DEFAULT_TARGET_OS}")
+    set(target "i686${COMPILER_RT_OS_SUFFIX}-${COMPILER_RT_DEFAULT_TARGET_TRIPLE_SUFFIX}")
   else()
-    set(target "${arch}-${COMPILER_RT_DEFAULT_TARGET_OS}")
-  endif()
-  if(COMPILER_RT_DEFAULT_TARGET_ABI)
-    set(target "${target}-${COMPILER_RT_DEFAULT_TARGET_ABI}")
+    set(target "${arch}-${COMPILER_RT_DEFAULT_TARGET_TRIPLE_SUFFIX}")
   endif()
   set(${variable} ${target} PARENT_SCOPE)
 endfunction()
Index: compiler-rt/CMakeLists.txt
===================================================================
--- compiler-rt/CMakeLists.txt
+++ compiler-rt/CMakeLists.txt
@@ -89,12 +89,12 @@
 endif()
 
 construct_compiler_rt_default_triple()
-if ("${COMPILER_RT_DEFAULT_TARGET_ABI}" MATCHES "hf$")
+if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE_SUFFIX}" MATCHES "hf$")
   if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^arm")
     set(COMPILER_RT_DEFAULT_TARGET_ARCH "armhf")
   endif()
 endif()
-if ("${COMPILER_RT_DEFAULT_TARGET_ABI}" MATCHES "^android")
+if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE_SUFFIX}" MATCHES "android")
   set(ANDROID 1)
 endif()
 pythonize_bool(ANDROID)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50548.160048.patch
Type: text/x-patch
Size: 2956 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180810/02e732b1/attachment-0001.bin>


More information about the llvm-commits mailing list