[PATCH] D109837: cmake: Deprecate config.guess

Tom Stellard via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 15 09:40:57 PDT 2021


tstellar created this revision.
tstellar added reviewers: MaskRay, mgorny, echristo.
tstellar requested review of this revision.
Herald added a project: LLVM.

We are unable to update config.guess to a newer version since its
license is different than the license we use for llvm.  Therefore, any
new host triple detection code needs to be done using CMake.  Rather than have
some triple detection in CMake and some in config.guess, I think it
would be better to start to move all triple detection code into
CMake.

This patch takes a step in that direction by changing the default from
using config.guess to using a simple check that relies on the host compiler
to determine the host triple.

Users may restore the previous behavior of relying on config.guess by
setting the CMake variable LLVM_USE_CONFIG_GUESS=ON


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109837

Files:
  llvm/CMakeLists.txt
  llvm/cmake/modules/GetHostTriple.cmake


Index: llvm/cmake/modules/GetHostTriple.cmake
===================================================================
--- llvm/cmake/modules/GetHostTriple.cmake
+++ llvm/cmake/modules/GetHostTriple.cmake
@@ -44,7 +44,7 @@
   else( MSVC )
     if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows AND NOT MSYS)
       message(WARNING "unable to determine host target triple")
-    else()
+    elseif(LLVM_USE_CONFIG_GUESS)
       set(config_guess ${LLVM_MAIN_SRC_DIR}/cmake/config.guess)
       execute_process(COMMAND sh ${config_guess}
         RESULT_VARIABLE TT_RV
@@ -54,6 +54,23 @@
         message(FATAL_ERROR "Failed to execute ${config_guess}")
       endif( NOT TT_RV EQUAL 0 )
       set( value ${TT_OUT} )
+    elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
+      execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v
+        RESULT_VARIABLE TT_RV
+        ERROR_VARIABLE TT_OUT
+        ERROR_STRIP_TRAILING_WHITESPACE)
+      if( NOT TT_RV EQUAL 0 )
+        message(FATAL_ERROR "Failed to execute ${CMAKE_CXX_COMPILER} for triple detection")
+      endif( NOT TT_RV EQUAL 0 )
+      string(REGEX MATCH "Target: ([^\r\n]+)[\r\n]" value "${TT_OUT}")
+      if (NOT "${CMAKE_MATCH_1}" STREQUAL "")
+        set(value ${CMAKE_MATCH_1})
+      else()
+        message(FATAL_ERROR "Unable to determine host triple.  Please file a bug.  "
+                             "You may work around this for now configuring with "
+                             "-DLLVM_USE_CONFIG_GUESS=ON, however, this option "
+                             "will be removed in the future")
+      endif()
     endif()
   endif( MSVC )
   set( ${var} ${value} PARENT_SCOPE )
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -475,6 +475,9 @@
 set(LLVM_CODESIGNING_IDENTITY "" CACHE STRING
   "Sign executables and dylibs with the given identity or skip if empty (Darwin Only)")
 
+option(LLVM_USE_CONFIG_GUESS
+   "(deprecated) Use config.guess to determine host architecture.  This option will be removed in the future." OFF)
+
 # If enabled, verify we are on a platform that supports oprofile.
 if( LLVM_USE_OPROFILE )
   if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109837.372734.patch
Type: text/x-patch
Size: 2276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210915/726c001f/attachment.bin>


More information about the llvm-commits mailing list