[clang] 3a0f6e6 - Fix compiler extension in standalone mode

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 19 22:22:27 PST 2020


Author: serge-sans-paille
Date: 2020-02-20T07:19:04+01:00
New Revision: 3a0f6e699bb6d96dc62dce6faef20ac26cf103fd

URL: https://github.com/llvm/llvm-project/commit/3a0f6e699bb6d96dc62dce6faef20ac26cf103fd
DIFF: https://github.com/llvm/llvm-project/commit/3a0f6e699bb6d96dc62dce6faef20ac26cf103fd.diff

LOG: Fix compiler extension in standalone mode

Use a dedicated cmake file to store the extension configured within LLVM. That
way, a standalone build of clang can load this cmake file and get all the
configured standalone extensions.

This patch is related to https://reviews.llvm.org/D74602

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 093c2225e525..dc1413f4b597 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(NO_GEN)
+  process_llvm_pass_plugins()
 endif()
 
 configure_file(

diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index fa6e418ac06f..5133139d6ce3 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1075,7 +1075,7 @@ endif()
 # after all targets are created.
 include(LLVMDistributionSupport)
 llvm_distribution_add_targets()
-process_llvm_pass_plugins()
+process_llvm_pass_plugins(GEN_CONFIG)
 
 # This allows us to deploy the Universal CRT DLLs by passing -DCMAKE_INSTALL_UCRT_LIBRARIES=ON to CMake
 if (MSVC AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_INSTALL_UCRT_LIBRARIES)

diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 408423ba1887..f66a8ccdb469 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -878,63 +878,62 @@ function(add_llvm_pass_plugin name)
     if (TARGET intrinsics_gen)
       add_dependencies(obj.${name} intrinsics_gen)
     endif()
-    message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})")
-    set_property(GLOBAL APPEND PROPERTY LLVM_COMPILE_EXTENSIONS ${name})
+    set_property(GLOBAL APPEND PROPERTY LLVM_STATIC_EXTENSIONS ${name})
   elseif(NOT ARG_NO_MODULE)
     add_llvm_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
   else()
     add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS})
   endif()
+  message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})")
 
 endfunction(add_llvm_pass_plugin)
 
-# process_llvm_pass_plugins([NO_GEN])
+# process_llvm_pass_plugins([GEN_CONFIG])
 #
 # 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
+# if GEN_CONFIG 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.
 #
 function(process_llvm_pass_plugins)
   cmake_parse_arguments(ARG
-      "NO_GEN" "" ""
+      "GEN_CONFIG" "" ""
     ${ARGN})
 
+  if(ARG_GEN_CONFIG)
+      get_property(LLVM_STATIC_EXTENSIONS GLOBAL PROPERTY LLVM_STATIC_EXTENSIONS)
+  else()
+      include(LLVMConfigExtensions)
+  endif()
+
   # Add static plugins to each plugin target.
-  get_property(LLVM_EXTENSIONS GLOBAL PROPERTY LLVM_COMPILE_EXTENSIONS)
-  foreach(llvm_extension ${LLVM_EXTENSIONS})
-    string(TOUPPER ${llvm_extension} llvm_extension_upper)
-    string(TOLOWER ${llvm_extension} llvm_extension_lower)
-
-    if(LLVM_${llvm_extension_upper}_LINK_INTO_TOOLS)
-      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})
-        set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension})
-      endforeach()
-    else()
-      add_llvm_library(${llvm_extension_lower} MODULE obj.${llvm_extension_lower})
-    endif()
+  foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS})
+    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})
+      set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension})
+    endforeach()
   endforeach()
 
-  # 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()
+  # Eventually generate the extension header, and store config to a cmake file
+  # for usage in third-party configuration.
+  if(ARG_GEN_CONFIG)
+      set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
+      set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
+      file(WRITE
+          "${llvm_cmake_builddir}/LLVMConfigExtensions.cmake"
+          "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})")
+      install(FILES
+          ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake
+          DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
+          COMPONENT cmake-exports)
 
+      file(WRITE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "//extension handlers\n")
+      foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS})
+        file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension})\n")
       endforeach()
       file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "#undef HANDLE_EXTENSION\n")
 

diff  --git a/llvm/cmake/modules/CMakeLists.txt b/llvm/cmake/modules/CMakeLists.txt
index 9cf22b436fa7..af757d6199a8 100644
--- a/llvm/cmake/modules/CMakeLists.txt
+++ b/llvm/cmake/modules/CMakeLists.txt
@@ -136,6 +136,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
     FILES_MATCHING PATTERN *.cmake
     PATTERN .svn EXCLUDE
     PATTERN LLVMConfig.cmake EXCLUDE
+    PATTERN LLVMConfigExtensions.cmake EXCLUDE
     PATTERN LLVMConfigVersion.cmake EXCLUDE
     PATTERN LLVM-Config.cmake EXCLUDE
     PATTERN GetHostTriple.cmake EXCLUDE)


        


More information about the cfe-commits mailing list