Skip to content

Commit 87dac7d

Browse files
author
serge-sans-paille
committed
Fix standalone build interaction with compiler extension
As suggested in #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
1 parent c187364 commit 87dac7d

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

clang/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ add_subdirectory(utils/hmaptool)
864864

865865
if(CLANG_BUILT_STANDALONE)
866866
llvm_distribution_add_targets()
867-
process_llvm_pass_plugins()
867+
process_llvm_pass_plugins(NO_GEN)
868868
endif()
869869

870870
configure_file(

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -883,26 +883,28 @@ function(add_llvm_pass_plugin name)
883883

884884
endfunction(add_llvm_pass_plugin)
885885

886-
# Generate X Macro file for extension handling. It provides a
887-
# HANDLE_EXTENSION(extension_namespace, ExtensionProject) call for each extension
888-
# allowing client code to define HANDLE_EXTENSION to have a specific code be run for
889-
# each extension.
886+
# process_llvm_pass_plugins([NO_GEN])
887+
#
888+
# Correctly set lib dependencies between plugins and tools, based on tools
889+
# registered with the ENABLE_PLUGINS option.
890+
#
891+
# Unless NO_GEN option is set, also generate X Macro file for extension
892+
# handling. It provides a HANDLE_EXTENSION(extension_namespace, ExtensionProject)
893+
# call for each extension allowing client code to define
894+
# HANDLE_EXTENSION to have a specific code be run for each extension.
890895
#
891-
# Also correctly set lib dependencies between plugins and tools.
892896
function(process_llvm_pass_plugins)
897+
cmake_parse_arguments(ARG
898+
"NO_GEN" "" ""
899+
${ARGN})
900+
901+
# Add static plugins to each plugin target.
893902
get_property(LLVM_EXTENSIONS GLOBAL PROPERTY LLVM_COMPILE_EXTENSIONS)
894-
file(WRITE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "//extension handlers\n")
895903
foreach(llvm_extension ${LLVM_EXTENSIONS})
896-
string(TOLOWER ${llvm_extension} llvm_extension_lower)
897-
898904
string(TOUPPER ${llvm_extension} llvm_extension_upper)
899-
string(SUBSTRING ${llvm_extension_upper} 0 1 llvm_extension_upper_first)
900-
string(SUBSTRING ${llvm_extension_lower} 1 -1 llvm_extension_lower_tail)
901-
string(CONCAT llvm_extension_project ${llvm_extension_upper_first} ${llvm_extension_lower_tail})
905+
string(TOLOWER ${llvm_extension} llvm_extension_lower)
902906

903907
if(LLVM_${llvm_extension_upper}_LINK_INTO_TOOLS)
904-
file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension_project})\n")
905-
906908
get_property(llvm_plugin_targets GLOBAL PROPERTY LLVM_PLUGIN_TARGETS)
907909
foreach(llvm_plugin_target ${llvm_plugin_targets})
908910
set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY LINK_LIBRARIES ${llvm_extension})
@@ -911,15 +913,32 @@ function(process_llvm_pass_plugins)
911913
else()
912914
add_llvm_library(${llvm_extension_lower} MODULE obj.${llvm_extension_lower})
913915
endif()
914-
915916
endforeach()
916-
file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "#undef HANDLE_EXTENSION\n")
917917

918-
# only replace if there's an actual change
919-
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
920-
"${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp"
921-
"${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
922-
file(REMOVE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp")
918+
# Eventually generate the extension header.
919+
if(NOT ARG_NO_GEN)
920+
file(WRITE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "//extension handlers\n")
921+
foreach(llvm_extension ${LLVM_EXTENSIONS})
922+
string(TOLOWER ${llvm_extension} llvm_extension_lower)
923+
924+
string(TOUPPER ${llvm_extension} llvm_extension_upper)
925+
string(SUBSTRING ${llvm_extension_upper} 0 1 llvm_extension_upper_first)
926+
string(SUBSTRING ${llvm_extension_lower} 1 -1 llvm_extension_lower_tail)
927+
string(CONCAT llvm_extension_project ${llvm_extension_upper_first} ${llvm_extension_lower_tail})
928+
929+
if(LLVM_${llvm_extension_upper}_LINK_INTO_TOOLS)
930+
file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension_project})\n")
931+
endif()
932+
933+
endforeach()
934+
file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "#undef HANDLE_EXTENSION\n")
935+
936+
# only replace if there's an actual change
937+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
938+
"${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp"
939+
"${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
940+
file(REMOVE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp")
941+
endif()
923942
endfunction()
924943

925944
function(export_executable_symbols target)

0 commit comments

Comments
 (0)