Skip to content

Commit 7831c48

Browse files
serge-sans-pailletstellar
serge-sans-paille
authored andcommitted
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 (cherry picked from commit 87dac7d)
1 parent f149195 commit 7831c48

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
@@ -894,26 +894,28 @@ function(add_llvm_pass_plugin name)
894894

895895
endfunction(add_llvm_pass_plugin)
896896

897-
# Generate X Macro file for extension handling. It provides a
898-
# HANDLE_EXTENSION(extension_namespace, ExtensionProject) call for each extension
899-
# allowing client code to define HANDLE_EXTENSION to have a specific code be run for
900-
# each extension.
897+
# process_llvm_pass_plugins([NO_GEN])
898+
#
899+
# Correctly set lib dependencies between plugins and tools, based on tools
900+
# registered with the ENABLE_PLUGINS option.
901+
#
902+
# Unless NO_GEN option is set, also generate X Macro file for extension
903+
# handling. It provides a HANDLE_EXTENSION(extension_namespace, ExtensionProject)
904+
# call for each extension allowing client code to define
905+
# HANDLE_EXTENSION to have a specific code be run for each extension.
901906
#
902-
# Also correctly set lib dependencies between plugins and tools.
903907
function(process_llvm_pass_plugins)
908+
cmake_parse_arguments(ARG
909+
"NO_GEN" "" ""
910+
${ARGN})
911+
912+
# Add static plugins to each plugin target.
904913
get_property(LLVM_EXTENSIONS GLOBAL PROPERTY LLVM_COMPILE_EXTENSIONS)
905-
file(WRITE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "//extension handlers\n")
906914
foreach(llvm_extension ${LLVM_EXTENSIONS})
907-
string(TOLOWER ${llvm_extension} llvm_extension_lower)
908-
909915
string(TOUPPER ${llvm_extension} llvm_extension_upper)
910-
string(SUBSTRING ${llvm_extension_upper} 0 1 llvm_extension_upper_first)
911-
string(SUBSTRING ${llvm_extension_lower} 1 -1 llvm_extension_lower_tail)
912-
string(CONCAT llvm_extension_project ${llvm_extension_upper_first} ${llvm_extension_lower_tail})
916+
string(TOLOWER ${llvm_extension} llvm_extension_lower)
913917

914918
if(LLVM_${llvm_extension_upper}_LINK_INTO_TOOLS)
915-
file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension_project})\n")
916-
917919
get_property(llvm_plugin_targets GLOBAL PROPERTY LLVM_PLUGIN_TARGETS)
918920
foreach(llvm_plugin_target ${llvm_plugin_targets})
919921
set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY LINK_LIBRARIES ${llvm_extension})
@@ -922,15 +924,32 @@ function(process_llvm_pass_plugins)
922924
else()
923925
add_llvm_library(${llvm_extension_lower} MODULE obj.${llvm_extension_lower})
924926
endif()
925-
926927
endforeach()
927-
file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "#undef HANDLE_EXTENSION\n")
928928

929-
# only replace if there's an actual change
930-
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
931-
"${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp"
932-
"${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
933-
file(REMOVE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp")
929+
# Eventually generate the extension header.
930+
if(NOT ARG_NO_GEN)
931+
file(WRITE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "//extension handlers\n")
932+
foreach(llvm_extension ${LLVM_EXTENSIONS})
933+
string(TOLOWER ${llvm_extension} llvm_extension_lower)
934+
935+
string(TOUPPER ${llvm_extension} llvm_extension_upper)
936+
string(SUBSTRING ${llvm_extension_upper} 0 1 llvm_extension_upper_first)
937+
string(SUBSTRING ${llvm_extension_lower} 1 -1 llvm_extension_lower_tail)
938+
string(CONCAT llvm_extension_project ${llvm_extension_upper_first} ${llvm_extension_lower_tail})
939+
940+
if(LLVM_${llvm_extension_upper}_LINK_INTO_TOOLS)
941+
file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension_project})\n")
942+
endif()
943+
944+
endforeach()
945+
file(APPEND "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "#undef HANDLE_EXTENSION\n")
946+
947+
# only replace if there's an actual change
948+
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
949+
"${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp"
950+
"${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def")
951+
file(REMOVE "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def.tmp")
952+
endif()
934953
endfunction()
935954

936955
function(export_executable_symbols target)

0 commit comments

Comments
 (0)