[llvm-branch-commits] [llvm] 7831c48 - Fix standalone build interaction with compiler extension

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jun 17 17:36:00 PDT 2020


Author: serge-sans-paille
Date: 2020-06-17T16:57:30-07:00
New Revision: 7831c48b06678c2921f725e5e779f8ab00efedf1

URL: https://github.com/llvm/llvm-project/commit/7831c48b06678c2921f725e5e779f8ab00efedf1
DIFF: https://github.com/llvm/llvm-project/commit/7831c48b06678c2921f725e5e779f8ab00efedf1.diff

LOG: Fix standalone build interaction with compiler extension

As suggested in https://github.com/llvm/llvm-project/issues/120, don't try to
generate the extension file from clang, only do the linking step.

Fixes the regression introduced in D74464 when running cmake inside the clang
directory.

Differential Revision: https://reviews.llvm.org/D74602

(cherry picked from commit 87dac7da68ea1e0adac78c59ef1891dcf9632b67)

Added: 
    

Modified: 
    clang/CMakeLists.txt
    llvm/cmake/modules/AddLLVM.cmake

Removed: 
    


################################################################################
diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index dc1413f4b597..093c2225e525 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -864,7 +864,7 @@ add_subdirectory(utils/hmaptool)
 
 if(CLANG_BUILT_STANDALONE)
   llvm_distribution_add_targets()
-  process_llvm_pass_plugins()
+  process_llvm_pass_plugins(NO_GEN)
 endif()
 
 configure_file(

diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index fd69786544ac..01d1a326fbaf 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -894,26 +894,28 @@ function(add_llvm_pass_plugin name)
 
 endfunction(add_llvm_pass_plugin)
 
-# Generate X Macro file for extension handling. It provides a
-# HANDLE_EXTENSION(extension_namespace, ExtensionProject) call for each extension
-# allowing client code to define HANDLE_EXTENSION to have a specific code be run for
-# each extension.
+# process_llvm_pass_plugins([NO_GEN])
+#
+# Correctly set lib dependencies between plugins and tools, based on tools
+# registered with the ENABLE_PLUGINS option.
+#
+# Unless NO_GEN option is set, also generate X Macro file for extension
+# handling. It provides a HANDLE_EXTENSION(extension_namespace, ExtensionProject)
+# call for each extension allowing client code to define
+# HANDLE_EXTENSION to have a specific code be run for each extension.
 #
-# Also correctly set lib dependencies between plugins and tools.
 function(process_llvm_pass_plugins)
+  cmake_parse_arguments(ARG
+      "NO_GEN" "" ""
+    ${ARGN})
+
+  # Add static plugins to each plugin target.
   get_property(LLVM_EXTENSIONS GLOBAL PROPERTY LLVM_COMPILE_EXTENSIONS)
-  file(WRITE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "//extension handlers\n")
   foreach(llvm_extension ${LLVM_EXTENSIONS})
-    string(TOLOWER ${llvm_extension} llvm_extension_lower)
-
     string(TOUPPER ${llvm_extension} llvm_extension_upper)
-    string(SUBSTRING ${llvm_extension_upper} 0 1 llvm_extension_upper_first)
-    string(SUBSTRING ${llvm_extension_lower} 1 -1 llvm_extension_lower_tail)
-    string(CONCAT llvm_extension_project ${llvm_extension_upper_first} ${llvm_extension_lower_tail})
+    string(TOLOWER ${llvm_extension} llvm_extension_lower)
 
     if(LLVM_${llvm_extension_upper}_LINK_INTO_TOOLS)
-      file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension_project})\n")
-
       get_property(llvm_plugin_targets GLOBAL PROPERTY LLVM_PLUGIN_TARGETS)
       foreach(llvm_plugin_target ${llvm_plugin_targets})
         set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY LINK_LIBRARIES ${llvm_extension})
@@ -922,15 +924,32 @@ function(process_llvm_pass_plugins)
     else()
       add_llvm_library(${llvm_extension_lower} MODULE obj.${llvm_extension_lower})
     endif()
-
   endforeach()
-  file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "#undef HANDLE_EXTENSION\n")
 
-  # only replace if there's an actual change
-  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_
diff erent
-    "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp"
-    "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
-  file(REMOVE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp")
+  # Eventually generate the extension header.
+  if(NOT ARG_NO_GEN)
+      file(WRITE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "//extension handlers\n")
+      foreach(llvm_extension ${LLVM_EXTENSIONS})
+        string(TOLOWER ${llvm_extension} llvm_extension_lower)
+
+        string(TOUPPER ${llvm_extension} llvm_extension_upper)
+        string(SUBSTRING ${llvm_extension_upper} 0 1 llvm_extension_upper_first)
+        string(SUBSTRING ${llvm_extension_lower} 1 -1 llvm_extension_lower_tail)
+        string(CONCAT llvm_extension_project ${llvm_extension_upper_first} ${llvm_extension_lower_tail})
+
+        if(LLVM_${llvm_extension_upper}_LINK_INTO_TOOLS)
+          file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension_project})\n")
+        endif()
+
+      endforeach()
+      file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "#undef HANDLE_EXTENSION\n")
+
+      # only replace if there's an actual change
+      execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_
diff erent
+        "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp"
+        "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
+      file(REMOVE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp")
+  endif()
 endfunction()
 
 function(export_executable_symbols target)


        


More information about the llvm-branch-commits mailing list