1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

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
This commit is contained in:
serge-sans-paille 2020-02-16 09:31:16 +01:00
parent 26e1302f3c
commit cbe51c16a5
3 changed files with 34 additions and 34 deletions

View File

@ -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)

View File

@ -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})
# 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(ARG_GEN_CONFIG)
get_property(LLVM_STATIC_EXTENSIONS GLOBAL PROPERTY LLVM_STATIC_EXTENSIONS)
else()
include(LLVMConfigExtensions)
endif()
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()
# Add static plugins to each plugin target.
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)
# 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_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()
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")

View File

@ -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)