diff options
author | serge-sans-paille <sguelton@redhat.com> | 2020-04-20 12:39:32 +0200 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2020-06-17 16:57:30 -0700 |
commit | 5f510e51dd4e6de5987a162f232c514a4dc8b0e3 (patch) | |
tree | f038eb3fcfc75e0c00b01ecfe021307d601b7e6f /llvm/cmake/modules | |
parent | 0c05269e0232d5eebfd835aa1401913b181031a3 (diff) | |
download | bcm5719-llvm-5f510e51dd4e6de5987a162f232c514a4dc8b0e3.tar.gz bcm5719-llvm-5f510e51dd4e6de5987a162f232c514a4dc8b0e3.zip |
Update compiler extension integration into the build system
The approach here is to create a new (empty) component, `Extensions', where all
statically compiled extensions dynamically register their dependencies. That way
we're more natively compatible with LLVMBuild and llvm-config.
Fixes: https://bugs.llvm.org/show_bug.cgi?id=44870
Differential Revision: https://reviews.llvm.org/D78192
(cherry picked from commit 8f766e382b77eef3102798b49e087d1e4804b984)
Diffstat (limited to 'llvm/cmake/modules')
-rw-r--r-- | llvm/cmake/modules/AddLLVM.cmake | 75 |
1 files changed, 60 insertions, 15 deletions
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index a8b3628fd31..37387e0fc54 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -404,7 +404,7 @@ endfunction(set_windows_version_resource_properties) # ) function(llvm_add_library name) cmake_parse_arguments(ARG - "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB;ENABLE_PLUGINS" + "MODULE;SHARED;STATIC;OBJECT;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME;NO_INSTALL_RPATH;COMPONENT_LIB" "OUTPUT_NAME;PLUGIN_TOOL;ENTITLEMENTS;BUNDLE_PATH" "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS" ${ARGN}) @@ -418,9 +418,6 @@ function(llvm_add_library name) else() llvm_process_sources(ALL_FILES ${ARG_UNPARSED_ARGUMENTS} ${ARG_ADDITIONAL_HEADERS}) endif() - if(ARG_ENABLE_PLUGINS) - set_property(GLOBAL APPEND PROPERTY LLVM_PLUGIN_TARGETS ${name}) - endif() if(ARG_MODULE) if(ARG_SHARED OR ARG_STATIC) @@ -753,7 +750,7 @@ endmacro(add_llvm_library name) macro(add_llvm_executable name) cmake_parse_arguments(ARG - "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS;ENABLE_PLUGINS" + "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH;SUPPORT_PLUGINS" "ENTITLEMENTS;BUNDLE_PATH" "DEPENDS" ${ARGN}) @@ -840,9 +837,6 @@ macro(add_llvm_executable name) # API for all shared libaries loaded by this executable. target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB}) endif() - if(ARG_ENABLE_PLUGINS) - set_property(GLOBAL APPEND PROPERTY LLVM_PLUGIN_TARGETS ${name}) - endif() llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH}) endmacro(add_llvm_executable name) @@ -915,18 +909,18 @@ function(process_llvm_pass_plugins) include(LLVMConfigExtensions) endif() - # Add static plugins to each plugin target. + # Add static plugins to the Extension component 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() + set_property(TARGET LLVMExtensions APPEND PROPERTY LINK_LIBRARIES ${llvm_extension}) + set_property(TARGET LLVMExtensions APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension}) endforeach() - # Eventually generate the extension header, and store config to a cmake file + # Eventually generate the extension headers, and store config to a cmake file # for usage in third-party configuration. if(ARG_GEN_CONFIG) + + ## Part 1: Extension header to be included whenever we need extension + # processing. set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") file(WRITE @@ -949,6 +943,57 @@ function(process_llvm_pass_plugins) "${ExtensionDef}.tmp" "${ExtensionDef}") file(REMOVE "${ExtensionDef}.tmp") + + ## Part 2: Extension header that captures each extension dependency, to be + # used by llvm-config. + set(ExtensionDeps "${LLVM_BINARY_DIR}/tools/llvm-config/ExtensionDependencies.inc") + + # Max needed to correctly size the required library array. + set(llvm_plugin_max_deps_length 0) + foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) + get_property(llvm_plugin_deps TARGET ${llvm_extension} PROPERTY LINK_LIBRARIES) + list(LENGTH llvm_plugin_deps llvm_plugin_deps_length) + if(llvm_plugin_deps_length GREATER llvm_plugin_max_deps_length) + set(llvm_plugin_max_deps_length ${llvm_plugin_deps_length}) + endif() + endforeach() + + list(LENGTH LLVM_STATIC_EXTENSIONS llvm_static_extension_count) + file(WRITE + "${ExtensionDeps}.tmp" + "#include <array>\n\ + struct ExtensionDescriptor {\n\ + const char* Name;\n\ + const char* const RequiredLibraries[1 + 1 + ${llvm_plugin_max_deps_length}];\n\ + };\n\ + std::array<ExtensionDescriptor, ${llvm_static_extension_count}> AvailableExtensions{\n") + + foreach(llvm_extension ${LLVM_STATIC_EXTENSIONS}) + get_property(llvm_plugin_deps TARGET ${llvm_extension} PROPERTY LINK_LIBRARIES) + + file(APPEND "${ExtensionDeps}.tmp" "{\"${llvm_extension}\", {") + foreach(llvm_plugin_dep ${llvm_plugin_deps}) + # Turn library dependency back to component name, if possible. + # That way llvm-config can avoid redundant dependencies. + STRING(REGEX REPLACE "^-l" "" plugin_dep_name ${llvm_plugin_dep}) + STRING(REGEX MATCH "^LLVM" is_llvm_library ${plugin_dep_name}) + if(is_llvm_library) + STRING(REGEX REPLACE "^LLVM" "" plugin_dep_name ${plugin_dep_name}) + STRING(TOLOWER ${plugin_dep_name} plugin_dep_name) + endif() + file(APPEND "${ExtensionDeps}.tmp" "\"${plugin_dep_name}\", ") + endforeach() + + # Self + mandatory trailing null, because the number of RequiredLibraries differs between extensions. + file(APPEND "${ExtensionDeps}.tmp" \"${llvm_extension}\", "nullptr}},\n") + endforeach() + file(APPEND "${ExtensionDeps}.tmp" "};\n") + + # only replace if there's an actual change + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${ExtensionDeps}.tmp" + "${ExtensionDeps}") + file(REMOVE "${ExtensionDeps}.tmp") endif() endfunction() |