Skip to content

Commit

Permalink
[CMake] Modify swift_install_in_component to support cmake install co…
Browse files Browse the repository at this point in the history
…mponents

CMake supports the notion of installation components. Right now we have some
custom code for supporting swift components. I think that for installation
purposes, it would be nice to use the CMake component system.

This should be a non-functional change. We should still only be generating
install rules for targets and files in components we want to install, and we
still use the install ninja target to install everything.
  • Loading branch information
bulbazord committed Apr 19, 2019
1 parent 84d96ad commit 3d9a289
Show file tree
Hide file tree
Showing 25 changed files with 190 additions and 193 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -998,17 +998,17 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
else()
set(SOURCEKIT_RUNTIME_DIR lib)
endif()
swift_install_in_component(sourcekit-inproc
FILES
swift_install_in_component(FILES
$<TARGET_FILE:dispatch>
$<TARGET_FILE:BlocksRuntime>
DESTINATION ${SOURCEKIT_RUNTIME_DIR})
DESTINATION ${SOURCEKIT_RUNTIME_DIR}
COMPONENT sourcekit-inproc)
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
swift_install_in_component(sourcekit-inproc
FILES
swift_install_in_component(FILES
$<TARGET_LINKER_FILE:dispatch>
$<TARGET_LINKER_FILE:BlocksRuntime>
DESTINATION lib)
DESTINATION lib
COMPONENT sourcekit-inproc)
endif()


Expand Down Expand Up @@ -1083,9 +1083,9 @@ endif()

add_subdirectory(cmake/modules)

swift_install_in_component(license
FILES "LICENSE.txt"
DESTINATION "share/swift")
swift_install_in_component(FILES "LICENSE.txt"
DESTINATION "share/swift"
COMPONENT license)

# Add a documentation target so that documentation shows up in the
# Xcode project.
Expand Down
8 changes: 4 additions & 4 deletions apinotes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ add_custom_target("copy_apinotes"
# This is treated as an OPTIONAL target because if we don't build the SDK
# overlay, the files will be missing anyway. It also allows us to build
# single overlays without installing the API notes.
swift_install_in_component(sdk-overlay
DIRECTORY "${output_dir}"
DESTINATION "lib/swift/"
OPTIONAL)
swift_install_in_component(DIRECTORY "${output_dir}"
DESTINATION "lib/swift/"
COMPONENT sdk-overlay
OPTIONAL)
62 changes: 31 additions & 31 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1452,11 +1452,11 @@ function(add_swift_host_library name)
)

if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
swift_install_in_component(dev
TARGETS ${name}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
RUNTIME DESTINATION bin)
swift_install_in_component(TARGETS ${name}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
RUNTIME DESTINATION bin
COMPONENT dev)
endif()

swift_is_installing_component(dev is_installing)
Expand Down Expand Up @@ -2018,27 +2018,27 @@ function(add_swift_target_library name)
endif()

if(sdk STREQUAL WINDOWS AND CMAKE_SYSTEM_NAME STREQUAL Windows)
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
TARGETS ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH}
RUNTIME DESTINATION "bin"
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
PERMISSIONS ${file_permissions})
swift_install_in_component(TARGETS ${name}-windows-${SWIFT_PRIMARY_VARIANT_ARCH}
RUNTIME DESTINATION "bin"
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${SWIFT_PRIMARY_VARIANT_ARCH}"
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
PERMISSIONS ${file_permissions})
else()
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
PERMISSIONS ${file_permissions}
"${optional_arg}")
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}"
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
PERMISSIONS ${file_permissions}
"${optional_arg}")
endif()
if(sdk STREQUAL WINDOWS)
foreach(arch ${SWIFT_SDK_WINDOWS_ARCHITECTURES})
if(TARGET ${name}-windows-${arch}_IMPLIB)
get_target_property(import_library ${name}-windows-${arch}_IMPLIB IMPORTED_LOCATION)
swift_install_in_component(${SWIFTLIB_INSTALL_IN_COMPONENT}
FILES ${import_library}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}"
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
swift_install_in_component(FILES ${import_library}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/${resource_dir}/${resource_dir_sdk_subdir}/${arch}"
COMPONENT ${SWIFTLIB_INSTALL_IN_COMPONENT}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endif()
endforeach()
endif()
Expand Down Expand Up @@ -2070,14 +2070,14 @@ function(add_swift_target_library name)
OUTPUT
"${UNIVERSAL_LIBRARY_NAME}"
${THIN_INPUT_TARGETS_STATIC})
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}"
PERMISSIONS
OWNER_READ OWNER_WRITE
GROUP_READ
WORLD_READ
"${optional_arg}")
swift_install_in_component(FILES "${UNIVERSAL_LIBRARY_NAME}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}"
PERMISSIONS
OWNER_READ OWNER_WRITE
GROUP_READ
WORLD_READ
COMPONENT "${SWIFTLIB_INSTALL_IN_COMPONENT}"
"${optional_arg}")
endif()

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

swift_install_in_component(${ASHT_SWIFT_COMPONENT}
TARGETS ${executable}
RUNTIME DESTINATION bin)
swift_install_in_component(TARGETS ${executable}
RUNTIME DESTINATION bin
COMPONENT ${ASHT_SWIFT_COMPONENT})

swift_is_installing_component(${ASHT_SWIFT_COMPONENT} is_installing)

Expand Down
34 changes: 11 additions & 23 deletions cmake/modules/SwiftComponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,42 +127,30 @@ function(swift_is_installing_component component result_var_name)
endif()
endfunction()

# swift_install_in_component(<COMPONENT NAME>
# <same parameters as install()>)
# swift_install_in_component(<same parameters as install()>)
#
# Executes the specified installation actions if the named component is
# requested to be installed.
#
# This function accepts the same parameters as install().
function(swift_install_in_component component)
precondition(component MESSAGE "Component name is required")
function(swift_install_in_component)
cmake_parse_arguments(
ARG # prefix
"" # options
"COMPONENT" # single-value args
"" # multi-value args
${ARGN})

swift_is_installing_component("${component}" is_installing)
precondition(ARG_COMPONENT MESSAGE "Component name is required")

swift_is_installing_component("${ARG_COMPONENT}" is_installing)
if(NOT is_installing)
return()
endif()

install(${ARGN})
endfunction()

# swift_install_in_either_component(<COMPONENT1 NAME> <COMPONENT2 NAME>
# <same parameters as install()>)
#
# Executes the specified installation actions if either one of the named
# components is requested to be installed.
#
# This function accepts the same parameters as install().
function(swift_install_in_either_component comp1 comp2)
foreach(component ${comp1} ${comp2})
precondition(component MESSAGE "Component name is required")
swift_is_installing_component("${component}" is_installing)
if(is_installing)
install(${ARGN})
return()
endif()
endforeach(component)
endfunction()

function(swift_install_symlink_component component)
cmake_parse_arguments(
ARG # prefix
Expand Down
6 changes: 3 additions & 3 deletions cmake/modules/SwiftManpage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function(manpage)
DEPENDS "${MP_SOURCE}"
ALL)

swift_install_in_component("${MP_INSTALL_IN_COMPONENT}"
FILES "${output_file_name}"
DESTINATION "share/man/man${MP_MAN_SECTION}")
swift_install_in_component(FILES "${output_file_name}"
DESTINATION "share/man/man${MP_MAN_SECTION}"
COMPONENT "${MP_INSTALL_IN_COMPONENT}")
endfunction()

14 changes: 7 additions & 7 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ function(_compile_swift_files
endif()

if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
DIRECTORY "${specific_module_dir}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
OPTIONAL)
swift_install_in_component(DIRECTORY "${specific_module_dir}"
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT}"
OPTIONAL)
else()
swift_install_in_component("${SWIFTFILE_INSTALL_IN_COMPONENT}"
FILES ${module_outputs}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}")
swift_install_in_component(FILES ${module_outputs}
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT}")
endif()

set(line_directive_tool "${SWIFT_SOURCE_DIR}/utils/line-directive")
Expand Down
6 changes: 3 additions & 3 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ if (DOXYGEN_FOUND)
add_dependencies(doxygen doxygen-swift)
endif()

swift_install_in_component(dev
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
DESTINATION "docs/html")
swift_install_in_component(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
DESTINATION "docs/html"
COMPONENT dev)
endif()
endif()
7 changes: 4 additions & 3 deletions include/swift/SwiftRemoteMirror/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ list(APPEND swift_remote_mirror_headers
Platform.h
SwiftRemoteMirror.h
SwiftRemoteMirrorTypes.h)
swift_install_in_component("swift-remote-mirror-headers"
FILES
swift_install_in_component(FILES
${swift_remote_mirror_headers}
DESTINATION
"include/swift/SwiftRemoteMirror")
"include/swift/SwiftRemoteMirror"
COMPONENT
swift-remote-mirror-headers)

6 changes: 3 additions & 3 deletions lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ if(SWIFT_BUILD_STATIC_STDLIB)
"${SWIFT_SOURCE_DIR}/utils/gen-static-stdlib-link-args")

list(APPEND static_stdlib_lnk_file_list ${swift_static_stdlib_${sdk}_args})
swift_install_in_component(stdlib
FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
DESTINATION "lib/swift_static/${lowercase_sdk}")
swift_install_in_component(FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
DESTINATION "lib/swift_static/${lowercase_sdk}"
COMPONENT stdlib)
endif()
endforeach()
add_custom_target(swift_static_lnk_args ALL DEPENDS ${static_stdlib_lnk_file_list})
Expand Down
6 changes: 3 additions & 3 deletions lib/Migrator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ add_custom_target("symlink_migrator_data"
DEPENDS "${output_dir}" "${outputs}"
COMMENT "Symlinking migrator data to ${output_dir}")

swift_install_in_component(compiler
FILES ${datafiles}
DESTINATION "lib/swift/migrator")
swift_install_in_component(FILES ${datafiles}
DESTINATION "lib/swift/migrator"
COMPONENT compiler)

add_swift_host_library(swiftMigrator STATIC
APIDiffMigratorPass.cpp
Expand Down
8 changes: 4 additions & 4 deletions lib/SwiftDemangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target_compile_definitions(swiftDemangle PRIVATE
target_link_libraries(swiftDemangle PRIVATE
swiftDemangling)

swift_install_in_component(compiler
TARGETS swiftDemangle
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")
swift_install_in_component(TARGETS swiftDemangle
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
COMPONENT compiler)
6 changes: 3 additions & 3 deletions stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ foreach(sdk ${SWIFT_SDKS})
"swift-stdlib-${platform}-${arch}"
"copy-legacy-layouts-${platform}-${arch}")

swift_install_in_component(compiler
FILES ${input}
DESTINATION "lib/swift/${platform}/")
swift_install_in_component(FILES ${input}
DESTINATION "lib/swift/${platform}/"
COMPONENT compiler)
else()
# Add a dummy target that does nothing so we can still depend on it
# later without checking if the input files exist.
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ foreach(sdk ${SWIFT_SDKS})
# It is not relocatable to the target platform itself.
# This affects any cross-comipled targets that use glibc.modulemap.

swift_install_in_component(sdk-overlay
FILES "${glibc_modulemap_out}"
DESTINATION "lib/swift/${arch_subdir}")
swift_install_in_component(FILES "${glibc_modulemap_out}"
DESTINATION "lib/swift/${arch_subdir}"
COMPONENT sdk-overlay)

endforeach()
endforeach()
Expand Down
22 changes: 11 additions & 11 deletions stdlib/public/SwiftShims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ add_custom_command_target(unused_var
COMMENT "Symlinking Clang resource headers into ${SWIFTLIB_DIR}/clang")
add_dependencies(copy_shim_headers symlink_clang_headers)

swift_install_in_component(stdlib
FILES ${sources}
DESTINATION "lib/swift/shims")
swift_install_in_component(FILES ${sources}
DESTINATION "lib/swift/shims"
COMPONENT stdlib)

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

swift_install_symlink_component(clang-resource-dir-symlink
LINK_NAME clang
Expand All @@ -126,7 +126,7 @@ swift_install_symlink_component(clang-resource-dir-symlink
# should be used in conjunction with clang-resource-dir-symlink.
file(TO_CMAKE_PATH "${LLVM_LIBRARY_OUTPUT_INTDIR}"
_SWIFT_SHIMS_PATH_TO_CLANG_BUILD)
swift_install_in_component(clang-builtin-headers-in-clang-resource-dir
DIRECTORY "${_SWIFT_SHIMS_PATH_TO_CLANG_BUILD}/lib/clang"
DESTINATION "lib"
PATTERN "*.h")
swift_install_in_component(DIRECTORY "${_SWIFT_SHIMS_PATH_TO_CLANG_BUILD}/lib/clang"
DESTINATION "lib"
COMPONENT clang-builtin-headers-in-clang-resource-dir
PATTERN "*.h")
Loading

0 comments on commit 3d9a289

Please sign in to comment.