Skip to content

Commit 6273877

Browse files
authored
[lld] enable installing lld headers and libraries as part of distribution (#127123)
This patch allows `lld-headers` and `lld-libraries` in `LLVM_DISTRIBUTION_COMPONENTS` to be specified and thus enable piecewise installation of `lld/**/*.h` headers and/or lld libraries (both in shared and static builds). This is similar to use cases such as `clang;clang-headers;clang-libraries`. Note when `lld-libraries` is present, `llvm-libraries` must be present as well because various lld libraries depend on various llvm libraries.
1 parent c22d84f commit 6273877

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

lld/CMakeLists.txt

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,6 @@ include_directories(BEFORE
180180
${CMAKE_CURRENT_SOURCE_DIR}/include
181181
)
182182

183-
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
184-
install(DIRECTORY include/
185-
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
186-
FILES_MATCHING
187-
PATTERN "*.h"
188-
)
189-
endif()
190-
191183
add_subdirectory(Common)
192184
add_subdirectory(tools/lld)
193185

@@ -207,4 +199,41 @@ add_subdirectory(MachO)
207199
add_subdirectory(MinGW)
208200
add_subdirectory(wasm)
209201

202+
add_custom_target(lld-headers)
203+
set_target_properties(lld-headers PROPERTIES FOLDER "Misc")
204+
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
205+
install(DIRECTORY include/lld
206+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
207+
COMPONENT lld-headers
208+
FILES_MATCHING
209+
PATTERN "*.h"
210+
)
211+
212+
if (NOT LLVM_ENABLE_IDE)
213+
add_llvm_install_targets(install-lld-headers
214+
DEPENDS lld-headers
215+
COMPONENT lld-headers)
216+
endif()
217+
endif()
218+
219+
# Custom target to install all lld libraries
220+
add_custom_target(lld-libraries)
221+
if (NOT LLVM_ENABLE_IDE)
222+
add_llvm_install_targets(install-lld-libraries
223+
DEPENDS lld-libraries
224+
COMPONENT lld-libraries)
225+
endif()
226+
227+
get_property(LLD_LIBS GLOBAL PROPERTY LLD_ALL_LIBS)
228+
if(LLD_LIBS)
229+
list(REMOVE_DUPLICATES LLD_LIBS)
230+
foreach(lib ${LLD_LIBS})
231+
add_dependencies(lld-libraries ${lib})
232+
if(NOT LLVM_ENABLE_IDE)
233+
add_dependencies(install-lld-libraries install-${lib})
234+
add_dependencies(install-lld-libraries-stripped install-${lib}-stripped)
235+
endif()
236+
endforeach()
237+
endif()
238+
210239
add_subdirectory(cmake/modules)

lld/cmake/modules/AddLLD.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ macro(add_lld_library name)
1313
llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS})
1414

1515
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
16-
get_target_export_arg(${name} LLD export_to_lldtargets)
16+
get_target_export_arg(${name} LLD export_to_lldtargets UMBRELLA lld-libraries)
1717
install(TARGETS ${name}
1818
COMPONENT ${name}
1919
${export_to_lldtargets}
2020
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
2121
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
2222
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
2323

24-
if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)
24+
if (NOT CMAKE_CONFIGURATION_TYPES)
2525
add_llvm_install_targets(install-${name}
2626
DEPENDS ${name}
2727
COMPONENT ${name})
2828
endif()
29+
set_property(GLOBAL APPEND PROPERTY LLD_ALL_LIBS ${name})
2930
set_property(GLOBAL APPEND PROPERTY LLD_EXPORTS ${name})
3031
endif()
3132
endmacro(add_lld_library)

0 commit comments

Comments
 (0)