-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
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`.
@llvm/pr-subscribers-lld Author: Alexandre Ganea (aganea) ChangesPreviously, even though LLD was linked as part of llvm-driver when using Full diff: https://github.com/llvm/llvm-project/pull/76305.diff 3 Files Affected:
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)
|
rubber stamp. It seems that |
Thank you! |
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`.
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, thellvm.exe
would be impropely be replaced bylld.exe
.