diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -864,7 +864,7 @@ 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 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1075,7 +1075,7 @@ # 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 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -873,63 +873,62 @@ 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 --- a/llvm/cmake/modules/CMakeLists.txt +++ b/llvm/cmake/modules/CMakeLists.txt @@ -136,6 +136,7 @@ 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)