[lld] [LLD] Fix llvm-driver cmake integration for LLD (PR #76305)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 23 16:28:50 PST 2023
https://github.com/aganea created https://github.com/llvm/llvm-project/pull/76305
Previously, even though LLD was linked as part of llvm-driver when using `cmake ... -DLLVM_TOOL_LLVM_DRIVER_BUILD=ON`, there were build issues when compiling incrementally. Sometimes link errors when linking LLD, other times, the `llvm.exe` would be impropely be replaced by `lld.exe`.
>From 84ea75daced82c8a248a243439445cff77ce0ad5 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <alex_toresh at yahoo.fr>
Date: Sat, 23 Dec 2023 19:06:48 -0500
Subject: [PATCH] [LLD] Fix llvm-driver cmake integration for LLD
Previously, even though LLD was linked as part of llvm-driver when using `cmake ... -DLLVM_TOOL_LLVM_DRIVER_BUILD=ON`, there were build issues when compiling incrementally. Sometimes link errors when linking LLD, other times, the `llvm.exe` would be impropely be replaced by `lld.exe`.
---
lld/cmake/modules/AddLLD.cmake | 50 +++++++++++++++++++++++-----------
lld/test/CMakeLists.txt | 1 +
lld/tools/lld/CMakeLists.txt | 11 +++++---
3 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/lld/cmake/modules/AddLLD.cmake b/lld/cmake/modules/AddLLD.cmake
index d3924f7243d403..2ee066b4153519 100644
--- a/lld/cmake/modules/AddLLD.cmake
+++ b/lld/cmake/modules/AddLLD.cmake
@@ -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()
diff --git a/lld/test/CMakeLists.txt b/lld/test/CMakeLists.txt
index 56490a7c3222a7..558da2b4421a2c 100644
--- a/lld/test/CMakeLists.txt
+++ b/lld/test/CMakeLists.txt
@@ -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(
diff --git a/lld/tools/lld/CMakeLists.txt b/lld/tools/lld/CMakeLists.txt
index 12628395680b8d..0f5daa78846bc7 100644
--- a/lld/tools/lld/CMakeLists.txt
+++ b/lld/tools/lld/CMakeLists.txt
@@ -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
@@ -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)
More information about the llvm-commits
mailing list