Skip to content

[LLD] Fix llvm-driver cmake integration for LLD #76305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions lld/cmake/modules/AddLLD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,48 @@ macro(add_lld_executable name)
endmacro(add_lld_executable)

macro(add_lld_tool name)
cmake_parse_arguments(ARG "DEPENDS;GENERATE_DRIVER" "" "" ${ARGN})
if (NOT LLD_BUILD_TOOLS)
set(EXCLUDE_FROM_ALL ON)
endif()
if(ARG_GENERATE_DRIVER
AND LLVM_TOOL_LLVM_DRIVER_BUILD
AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS)
)
set(get_obj_args ${ARGN})
list(FILTER get_obj_args EXCLUDE REGEX "^SUPPORT_PLUGINS$")
generate_llvm_objects(${name} ${get_obj_args})
add_custom_target(${name} DEPENDS llvm-driver)
else()
add_lld_executable(${name} ${ARGN})

add_lld_executable(${name} ${ARGN})

if (LLD_BUILD_TOOLS)
get_target_export_arg(${name} LLD export_to_lldtargets)
install(TARGETS ${name}
${export_to_lldtargets}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT ${name})

if(NOT CMAKE_CONFIGURATION_TYPES)
add_llvm_install_targets(install-${name}
DEPENDS ${name}
if (LLD_BUILD_TOOLS)
get_target_export_arg(${name} LLD export_to_lldtargets)
install(TARGETS ${name}
${export_to_lldtargets}
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT ${name})

if(NOT CMAKE_CONFIGURATION_TYPES)
add_llvm_install_targets(install-${name}
DEPENDS ${name}
COMPONENT ${name})
endif()
set_property(GLOBAL APPEND PROPERTY LLD_EXPORTS ${name})
endif()
set_property(GLOBAL APPEND PROPERTY LLD_EXPORTS ${name})
endif()
endmacro()

macro(add_lld_symlink name dest)
llvm_add_tool_symlink(LLD ${name} ${dest} ALWAYS_GENERATE)
# Always generate install targets
llvm_install_symlink(LLD ${name} ${dest} ALWAYS_GENERATE)
get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
if(LLVM_TOOL_LLVM_DRIVER_BUILD
AND ${dest} IN_LIST LLVM_DRIVER_TOOLS
AND (NOT LLVM_DISTRIBUTION_COMPONENTS OR ${dest} IN_LIST LLVM_DISTRIBUTION_COMPONENTS)
)
set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOL_ALIASES_${dest} ${name})
else()
llvm_add_tool_symlink(LLD ${name} ${dest} ALWAYS_GENERATE)
# Always generate install targets
llvm_install_symlink(LLD ${name} ${dest} ALWAYS_GENERATE)
endif()
endmacro()
1 change: 1 addition & 0 deletions lld/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ llvm_canonicalize_cmake_booleans(
LLVM_BUILD_EXAMPLES
LLVM_ENABLE_PLUGINS
LLVM_BYE_LINK_INTO_TOOLS
LLVM_TOOL_LLVM_DRIVER_BUILD
)

configure_lit_site_cfg(
Expand Down
11 changes: 7 additions & 4 deletions lld/tools/lld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ add_lld_tool(lld
export_executable_symbols_for_plugins(lld)

function(lld_target_link_libraries target type)
target_link_libraries(${target} ${type} ${ARGN})
if (TARGET obj.${target})
target_link_libraries(obj.${target} ${ARGN})
endif()

get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
if(LLVM_TOOL_LLVM_DRIVER_BUILD AND ${target} IN_LIST LLVM_DRIVER_TOOLS)
set(target llvm-driver)
endif()

target_link_libraries(${target} ${type} ${ARGN})
endfunction()

lld_target_link_libraries(lld
Expand All @@ -28,9 +34,6 @@ lld_target_link_libraries(lld
lldWasm
)

install(TARGETS lld
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

if(NOT LLD_SYMLINKS_TO_CREATE)
set(LLD_SYMLINKS_TO_CREATE
lld-link ld.lld ld64.lld wasm-ld)
Expand Down