Skip to content

Commit 2e7c328

Browse files
authored
Merge pull request swiftlang#24168 from xiaobai/sink_component_arg
[CMake] Modify swift_install_in_component to support cmake install components
2 parents fd2cf65 + 3d9a289 commit 2e7c328

File tree

25 files changed

+190
-193
lines changed

25 files changed

+190
-193
lines changed

CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -998,17 +998,17 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
998998
else()
999999
set(SOURCEKIT_RUNTIME_DIR lib)
10001000
endif()
1001-
swift_install_in_component(sourcekit-inproc
1002-
FILES
1001+
swift_install_in_component(FILES
10031002
$<TARGET_FILE:dispatch>
10041003
$<TARGET_FILE:BlocksRuntime>
1005-
DESTINATION ${SOURCEKIT_RUNTIME_DIR})
1004+
DESTINATION ${SOURCEKIT_RUNTIME_DIR}
1005+
COMPONENT sourcekit-inproc)
10061006
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
1007-
swift_install_in_component(sourcekit-inproc
1008-
FILES
1007+
swift_install_in_component(FILES
10091008
$<TARGET_LINKER_FILE:dispatch>
10101009
$<TARGET_LINKER_FILE:BlocksRuntime>
1011-
DESTINATION lib)
1010+
DESTINATION lib
1011+
COMPONENT sourcekit-inproc)
10121012
endif()
10131013

10141014

@@ -1083,9 +1083,9 @@ endif()
10831083

10841084
add_subdirectory(cmake/modules)
10851085

1086-
swift_install_in_component(license
1087-
FILES "LICENSE.txt"
1088-
DESTINATION "share/swift")
1086+
swift_install_in_component(FILES "LICENSE.txt"
1087+
DESTINATION "share/swift"
1088+
COMPONENT license)
10891089

10901090
# Add a documentation target so that documentation shows up in the
10911091
# Xcode project.

apinotes/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ add_custom_target("copy_apinotes"
3131
# This is treated as an OPTIONAL target because if we don't build the SDK
3232
# overlay, the files will be missing anyway. It also allows us to build
3333
# single overlays without installing the API notes.
34-
swift_install_in_component(sdk-overlay
35-
DIRECTORY "${output_dir}"
36-
DESTINATION "lib/swift/"
37-
OPTIONAL)
34+
swift_install_in_component(DIRECTORY "${output_dir}"
35+
DESTINATION "lib/swift/"
36+
COMPONENT sdk-overlay
37+
OPTIONAL)

cmake/modules/AddSwift.cmake

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,11 +1452,11 @@ function(add_swift_host_library name)
14521452
)
14531453

14541454
if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
1455-
swift_install_in_component(dev
1456-
TARGETS ${name}
1457-
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
1458-
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
1459-
RUNTIME DESTINATION bin)
1455+
swift_install_in_component(TARGETS ${name}
1456+
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
1457+
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
1458+
RUNTIME DESTINATION bin
1459+
COMPONENT dev)
14601460
endif()
14611461

14621462
swift_is_installing_component(dev is_installing)
@@ -2018,27 +2018,27 @@ function(add_swift_target_library name)
20182018
endif()
20192019

20202020
if(sdk STREQUAL WINDOWS AND CMAKE_SYSTEM_NAME STREQUAL Windows)
2021-
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
2022-
TARGETS ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH}
2023-
RUNTIME DESTINATION "bin"
2024-
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
2025-
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
2026-
PERMISSIONS ${file_permissions})
2021+
swift_install_in_component(TARGETS ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH}
2022+
RUNTIME DESTINATION "bin"
2023+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
2024+
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
2025+
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
2026+
PERMISSIONS ${file_permissions})
20272027
else()
2028-
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
2029-
FILES "${UNIVERSAL_LIBRARY_NAME}"
2030-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
2031-
PERMISSIONS ${file_permissions}
2032-
"${optional_arg}")
2028+
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
2029+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
2030+
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
2031+
PERMISSIONS ${file_permissions}
2032+
"${optional_arg}")
20332033
endif()
20342034
if(sdk STREQUAL WINDOWS)
20352035
foreach(arch ${SWIFT_SDK_WINDOWS_ARCHITECTURES})
20362036
if(TARGET ${name}-windows-${arch}_IMPLIB)
20372037
get_target_property(import_library ${name}-windows-${arch}_IMPLIB IMPORTED_LOCATION)
2038-
swift_install_in_component(${SWIFTLIB_INSTALL_IN_COMPONENT}
2039-
FILES ${import_library}
2040-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}"
2041-
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
2038+
swift_install_in_component(FILES ${import_library}
2039+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}"
2040+
COMPONENT ${SWIFTLIB_INSTALL_IN_COMPONENT}
2041+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
20422042
endif()
20432043
endforeach()
20442044
endif()
@@ -2070,14 +2070,14 @@ function(add_swift_target_library name)
20702070
OUTPUT
20712071
"${UNIVERSAL_LIBRARY_NAME}"
20722072
${THIN_INPUT_TARGETS_STATIC})
2073-
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
2074-
FILES "${UNIVERSAL_LIBRARY_NAME}"
2075-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}"
2076-
PERMISSIONS
2077-
OWNER_READ OWNER_WRITE
2078-
GROUP_READ
2079-
WORLD_READ
2080-
"${optional_arg}")
2073+
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
2074+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}"
2075+
PERMISSIONS
2076+
OWNER_READ OWNER_WRITE
2077+
GROUP_READ
2078+
WORLD_READ
2079+
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
2080+
"${optional_arg}")
20812081
endif()
20822082

20832083
# Add Swift standard library targets as dependencies to the top-level
@@ -2260,9 +2260,9 @@ function(add_swift_host_tool executable)
22602260
ARCHITECTURE ${SWIFT_HOST_VARIANT_ARCH}
22612261
${ASHT_UNPARSED_ARGUMENTS})
22622262

2263-
swift_install_in_component(${ASHT_SWIFT_COMPONENT}
2264-
TARGETS ${executable}
2265-
RUNTIME DESTINATION bin)
2263+
swift_install_in_component(TARGETS ${executable}
2264+
RUNTIME DESTINATION bin
2265+
COMPONENT ${ASHT_SWIFT_COMPONENT})
22662266

22672267
swift_is_installing_component(${ASHT_SWIFT_COMPONENT} is_installing)
22682268

cmake/modules/SwiftComponents.cmake

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,42 +127,30 @@ function(swift_is_installing_component component result_var_name)
127127
endif()
128128
endfunction()
129129

130-
# swift_install_in_component(<COMPONENT NAME>
131-
# <same parameters as install()>)
130+
# swift_install_in_component(<same parameters as install()>)
132131
#
133132
# Executes the specified installation actions if the named component is
134133
# requested to be installed.
135134
#
136135
# This function accepts the same parameters as install().
137-
function(swift_install_in_component component)
138-
precondition(component MESSAGE "Component name is required")
136+
function(swift_install_in_component)
137+
cmake_parse_arguments(
138+
ARG # prefix
139+
"" # options
140+
"COMPONENT" # single-value args
141+
"" # multi-value args
142+
${ARGN})
139143

140-
swift_is_installing_component("${component}" is_installing)
144+
precondition(ARG_COMPONENT MESSAGE "Component name is required")
145+
146+
swift_is_installing_component("${ARG_COMPONENT}" is_installing)
141147
if(NOT is_installing)
142148
return()
143149
endif()
144150

145151
install(${ARGN})
146152
endfunction()
147153

148-
# swift_install_in_either_component(<COMPONENT1 NAME> <COMPONENT2 NAME>
149-
# <same parameters as install()>)
150-
#
151-
# Executes the specified installation actions if either one of the named
152-
# components is requested to be installed.
153-
#
154-
# This function accepts the same parameters as install().
155-
function(swift_install_in_either_component comp1 comp2)
156-
foreach(component ${comp1} ${comp2})
157-
precondition(component MESSAGE "Component name is required")
158-
swift_is_installing_component("${component}" is_installing)
159-
if(is_installing)
160-
install(${ARGN})
161-
return()
162-
endif()
163-
endforeach(component)
164-
endfunction()
165-
166154
function(swift_install_symlink_component component)
167155
cmake_parse_arguments(
168156
ARG # prefix

cmake/modules/SwiftManpage.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ function(manpage)
3838
DEPENDS "${MP_SOURCE}"
3939
ALL)
4040

41-
swift_install_in_component("${MP_INSTALL_IN_COMPONENT}"
42-
FILES "${output_file_name}"
43-
DESTINATION "share/man/man${MP_MAN_SECTION}")
41+
swift_install_in_component(FILES "${output_file_name}"
42+
DESTINATION "share/man/man${MP_MAN_SECTION}"
43+
COMPONENT "${MP_INSTALL_IN_COMPONENT}")
4444
endfunction()
4545

cmake/modules/SwiftSource.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ function(_compile_swift_files
340340
endif()
341341

342342
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
343-
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
344-
DIRECTORY "${specific_module_dir}"
345-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
346-
OPTIONAL)
343+
swift_install_in_component(DIRECTORY "${specific_module_dir}"
344+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
345+
COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT}"
346+
OPTIONAL)
347347
else()
348-
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
349-
FILES ${module_outputs}
350-
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
348+
swift_install_in_component(FILES ${module_outputs}
349+
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
350+
COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT}")
351351
endif()
352352

353353
set(line_directive_tool "${SWIFT_SOURCE_DIR}/utils/line-directive")

docs/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ if (DOXYGEN_FOUND)
6868
add_dependencies(doxygen doxygen-swift)
6969
endif()
7070

71-
swift_install_in_component(dev
72-
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
73-
DESTINATION "docs/html")
71+
swift_install_in_component(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
72+
DESTINATION "docs/html"
73+
COMPONENT dev)
7474
endif()
7575
endif()

include/swift/SwiftRemoteMirror/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ list(APPEND swift_remote_mirror_headers
44
Platform.h
55
SwiftRemoteMirror.h
66
SwiftRemoteMirrorTypes.h)
7-
swift_install_in_component("swift-remote-mirror-headers"
8-
FILES
7+
swift_install_in_component(FILES
98
${swift_remote_mirror_headers}
109
DESTINATION
11-
"include/swift/SwiftRemoteMirror")
10+
"include/swift/SwiftRemoteMirror"
11+
COMPONENT
12+
swift-remote-mirror-headers)
1213

lib/Driver/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ if(SWIFT_BUILD_STATIC_STDLIB)
5656
"${SWIFT_SOURCE_DIR}/utils/gen-static-stdlib-link-args")
5757

5858
list(APPEND static_stdlib_lnk_file_list ${swift_static_stdlib_${sdk}_args})
59-
swift_install_in_component(stdlib
60-
FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
61-
DESTINATION "lib/swift_static/${lowercase_sdk}")
59+
swift_install_in_component(FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
60+
DESTINATION "lib/swift_static/${lowercase_sdk}"
61+
COMPONENT stdlib)
6262
endif()
6363
endforeach()
6464
add_custom_target(swift_static_lnk_args ALL DEPENDS ${static_stdlib_lnk_file_list})

lib/Migrator/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ add_custom_target("symlink_migrator_data"
4343
DEPENDS "${output_dir}" "${outputs}"
4444
COMMENT "Symlinking migrator data to ${output_dir}")
4545

46-
swift_install_in_component(compiler
47-
FILES ${datafiles}
48-
DESTINATION "lib/swift/migrator")
46+
swift_install_in_component(FILES ${datafiles}
47+
DESTINATION "lib/swift/migrator"
48+
COMPONENT compiler)
4949

5050
add_swift_host_library(swiftMigrator STATIC
5151
APIDiffMigratorPass.cpp

lib/SwiftDemangle/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ target_compile_definitions(swiftDemangle PRIVATE
66
target_link_libraries(swiftDemangle PRIVATE
77
swiftDemangling)
88

9-
swift_install_in_component(compiler
10-
TARGETS swiftDemangle
11-
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
12-
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
9+
swift_install_in_component(TARGETS swiftDemangle
10+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
11+
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
12+
COMPONENT compiler)

stdlib/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ foreach(sdk ${SWIFT_SDKS})
143143
"swift-stdlib-${platform}-${arch}"
144144
"copy-legacy-layouts-${platform}-${arch}")
145145

146-
swift_install_in_component(compiler
147-
FILES ${input}
148-
DESTINATION "lib/swift/${platform}/")
146+
swift_install_in_component(FILES ${input}
147+
DESTINATION "lib/swift/${platform}/"
148+
COMPONENT compiler)
149149
else()
150150
# Add a dummy target that does nothing so we can still depend on it
151151
# later without checking if the input files exist.

stdlib/public/Platform/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ foreach(sdk ${SWIFT_SDKS})
129129
# It is not relocatable to the target platform itself.
130130
# This affects any cross-comipled targets that use glibc.modulemap.
131131

132-
swift_install_in_component(sdk-overlay
133-
FILES "${glibc_modulemap_out}"
134-
DESTINATION "lib/swift/${arch_subdir}")
132+
swift_install_in_component(FILES "${glibc_modulemap_out}"
133+
DESTINATION "lib/swift/${arch_subdir}"
134+
COMPONENT sdk-overlay)
135135

136136
endforeach()
137137
endforeach()

stdlib/public/SwiftShims/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ add_custom_command_target(unused_var
105105
COMMENT "Symlinking Clang resource headers into ${SWIFTLIB_DIR}/clang")
106106
add_dependencies(copy_shim_headers symlink_clang_headers)
107107

108-
swift_install_in_component(stdlib
109-
FILES ${sources}
110-
DESTINATION "lib/swift/shims")
108+
swift_install_in_component(FILES ${sources}
109+
DESTINATION "lib/swift/shims"
110+
COMPONENT stdlib)
111111

112112
# Install Clang headers under the Swift library so that an installed Swift's
113113
# module importer can find the compiler headers corresponding to its Clang.
114-
swift_install_in_component(clang-builtin-headers
115-
DIRECTORY "${clang_headers_location}/"
116-
DESTINATION "lib/swift/clang"
117-
PATTERN "*.h")
114+
swift_install_in_component(DIRECTORY "${clang_headers_location}/"
115+
DESTINATION "lib/swift/clang"
116+
COMPONENT clang-builtin-headers
117+
PATTERN "*.h")
118118

119119
swift_install_symlink_component(clang-resource-dir-symlink
120120
LINK_NAME clang
@@ -126,7 +126,7 @@ swift_install_symlink_component(clang-resource-dir-symlink
126126
# should be used in conjunction with clang-resource-dir-symlink.
127127
file(TO_CMAKE_PATH "${LLVM_LIBRARY_OUTPUT_INTDIR}"
128128
_SWIFT_SHIMS_PATH_TO_CLANG_BUILD)
129-
swift_install_in_component(clang-builtin-headers-in-clang-resource-dir
130-
DIRECTORY "${_SWIFT_SHIMS_PATH_TO_CLANG_BUILD}/lib/clang"
131-
DESTINATION "lib"
132-
PATTERN "*.h")
129+
swift_install_in_component(DIRECTORY "${_SWIFT_SHIMS_PATH_TO_CLANG_BUILD}/lib/clang"
130+
DESTINATION "lib"
131+
COMPONENT clang-builtin-headers-in-clang-resource-dir
132+
PATTERN "*.h")

0 commit comments

Comments
 (0)