From e73dc2b755d360c0049fe34d2d33fdfe4b0b8535 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Wed, 23 Jul 2025 09:53:08 -0700 Subject: [PATCH 1/6] build: Install libraries in an `arch` sub-folder This is the proper installation scheme for Swift libraries and prevents having to manually copy them in `build.ps1`. --- CMakeLists.txt | 5 ++- cmake/modules/SwiftSupport.cmake | 65 +++++++++++++++++++++++++++++++- src/swift/CMakeLists.txt | 2 - 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 711f64a4d..bb65348c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,6 +306,8 @@ add_compile_definitions($<$:HAVE_CONFIG_H>) if(ENABLE_SWIFT) + include(SwiftSupport) + if(NOT SWIFT_SYSTEM_NAME) if(APPLE) set(SWIFT_SYSTEM_NAME macosx) @@ -313,8 +315,9 @@ if(ENABLE_SWIFT) set(SWIFT_SYSTEM_NAME "$") endif() endif() + get_swift_host_arch(swift_arch) - set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}" CACHE PATH "Path where the libraries will be installed") + set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}/${swift_arch}" CACHE PATH "Path where the libraries will be installed") set(INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch") set(INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime") set(INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/os" CACHE PATH "Path where the os/ headers will be installed") diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 3da519ec5..e80d5da6e 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -1,5 +1,56 @@ include_guard() +# Returns the architecture name in a variable +# +# Usage: +# get_swift_host_arch(result_var_name) +# +# Sets ${result_var_name} with the converted architecture name derived from +# CMAKE_SYSTEM_PROCESSOR or CMAKE_HOST_SYSTEM_PROCESSOR. +function(get_swift_host_arch result_var_name) + if(CMAKE_SYSTEM_PROCESSOR) + set(cmake_arch ${CMAKE_SYSTEM_PROCESSOR}) + else() + set(cmake_arch ${CMAKE_HOST_SYSTEM_PROCESSOR}) + endif() + if("${cmake_arch}" STREQUAL "x86_64") + set("${result_var_name}" "x86_64" PARENT_SCOPE) + elseif(cmake_arch MATCHES "aarch64|ARM64|arm64") + if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET OR + "${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "") + set("${result_var_name}" "aarch64" PARENT_SCOPE) + else() + set("${result_var_name}" "arm64" PARENT_SCOPE) + endif() + elseif("${cmake_arch}" STREQUAL "ppc64") + set("${result_var_name}" "powerpc64" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "ppc64le") + set("${result_var_name}" "powerpc64le" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "s390x") + set("${result_var_name}" "s390x" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "armv6l") + set("${result_var_name}" "armv6" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "armv7-a") + set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "armv7l") + set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "amd64") + set("${result_var_name}" "amd64" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "AMD64") + set("${result_var_name}" "x86_64" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "IA64") + set("${result_var_name}" "itanium" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "x86") + set("${result_var_name}" "i686" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "i686") + set("${result_var_name}" "i686" PARENT_SCOPE) + elseif("${cmake_arch}" STREQUAL "riscv64") + set("${result_var_name}" "riscv64" PARENT_SCOPE) + else() + message(FATAL_ERROR "Unrecognized architecture: ${cmake_arch}") + endif() +endfunction() + if(NOT dispatch_MODULE_TRIPLE) set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) if(CMAKE_Swift_COMPILER_TARGET) @@ -19,12 +70,22 @@ function(install_swift_module target) if(NOT module) set(module ${target}) endif() + + if(NOT SWIFT_SYSTEM_NAME) + if(APPLE) + set(SWIFT_SYSTEM_NAME macosx) + else() + set(SWIFT_SYSTEM_NAME "$") + endif() + endif() + set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}" CACHE PATH "Path where the swift modules will be installed") + install( FILES $/${module}.swiftdoc - DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule + DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule RENAME ${dispatch_MODULE_TRIPLE}.swiftdoc) install( FILES $/${module}.swiftmodule - DESTINATION ${INSTALL_TARGET_DIR}/${module}.swiftmodule + DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule RENAME ${dispatch_MODULE_TRIPLE}.swiftmodule) endfunction() diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt index d255f2cd7..a0082fb1e 100644 --- a/src/swift/CMakeLists.txt +++ b/src/swift/CMakeLists.txt @@ -1,5 +1,3 @@ -include(SwiftSupport) - if(HAVE_OBJC) add_library(DispatchStubs STATIC DispatchStubs.m) From 5301c966363ff78ac34191dc46b549bea8c81bda Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Mon, 4 Aug 2025 11:51:36 -0700 Subject: [PATCH 2/6] Use the arch value from the compiler --- CMakeLists.txt | 3 +- cmake/modules/SwiftSupport.cmake | 71 +++++++++----------------------- 2 files changed, 21 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb65348c2..bbc4aeb36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -315,9 +315,8 @@ if(ENABLE_SWIFT) set(SWIFT_SYSTEM_NAME "$") endif() endif() - get_swift_host_arch(swift_arch) - set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}/${swift_arch}" CACHE PATH "Path where the libraries will be installed") + set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}/${dispatch_Swift_ARCH}" CACHE PATH "Path where the libraries will be installed") set(INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch") set(INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime") set(INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/os" CACHE PATH "Path where the os/ headers will be installed") diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index e80d5da6e..6c6911f63 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -1,56 +1,5 @@ include_guard() -# Returns the architecture name in a variable -# -# Usage: -# get_swift_host_arch(result_var_name) -# -# Sets ${result_var_name} with the converted architecture name derived from -# CMAKE_SYSTEM_PROCESSOR or CMAKE_HOST_SYSTEM_PROCESSOR. -function(get_swift_host_arch result_var_name) - if(CMAKE_SYSTEM_PROCESSOR) - set(cmake_arch ${CMAKE_SYSTEM_PROCESSOR}) - else() - set(cmake_arch ${CMAKE_HOST_SYSTEM_PROCESSOR}) - endif() - if("${cmake_arch}" STREQUAL "x86_64") - set("${result_var_name}" "x86_64" PARENT_SCOPE) - elseif(cmake_arch MATCHES "aarch64|ARM64|arm64") - if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET OR - "${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "") - set("${result_var_name}" "aarch64" PARENT_SCOPE) - else() - set("${result_var_name}" "arm64" PARENT_SCOPE) - endif() - elseif("${cmake_arch}" STREQUAL "ppc64") - set("${result_var_name}" "powerpc64" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "ppc64le") - set("${result_var_name}" "powerpc64le" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "s390x") - set("${result_var_name}" "s390x" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "armv6l") - set("${result_var_name}" "armv6" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "armv7-a") - set("${result_var_name}" "armv7" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "armv7l") - set("${result_var_name}" "armv7" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "amd64") - set("${result_var_name}" "amd64" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "AMD64") - set("${result_var_name}" "x86_64" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "IA64") - set("${result_var_name}" "itanium" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "x86") - set("${result_var_name}" "i686" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "i686") - set("${result_var_name}" "i686" PARENT_SCOPE) - elseif("${cmake_arch}" STREQUAL "riscv64") - set("${result_var_name}" "riscv64" PARENT_SCOPE) - else() - message(FATAL_ERROR "Unrecognized architecture: ${cmake_arch}") - endif() -endfunction() - if(NOT dispatch_MODULE_TRIPLE) set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) if(CMAKE_Swift_COMPILER_TARGET) @@ -65,6 +14,26 @@ if(NOT dispatch_MODULE_TRIPLE) message(CONFIGURE_LOG "Swift module triple: ${module_triple}") endif() +if(NOT dispatch_Swift_ARCH) + if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) + # For newer compilers, we can use the -print-target-info command to get the architecture. + set(module_arch_command "${CMAKE_Swift_COMPILER}" -print-target-info) + if(CMAKE_Swift_COMPILER_TARGET) + list(APPEND module_arch_command -target ${CMAKE_Swift_COMPILER_TARGET}) + endif() + execute_process(COMMAND ${module_arch_command} OUTPUT_VARIABLE target_info_json) + string(JSON module_arch GET "${target_info_json}" "target" "arch") + else() + # For older compilers, extract the value from `dispatch_MODULE_TRIPLE`. + string(REGEX MATCH "^[^-]+" module_arch "${dispatch_MODULE_TRIPLE}") + endif() + + set(dispatch_Swift_ARCH "${module_arch}" CACHE STRING "Arch folder name used to install libraries") + mark_as_advanced(dispatch_Swift_ARCH) + + message(CONFIGURE_LOG "Swift arch: ${dispatch_Swift_ARCH}") +endif() + function(install_swift_module target) get_target_property(module ${target} Swift_MODULE_NAME) if(NOT module) From 3eff559e84288e3601437a79a19c7739a6f94bf6 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Tue, 5 Aug 2025 11:37:24 -0700 Subject: [PATCH 3/6] Get the platform name from the compiler This also refactors the code so we only do a single call to the Swift compiler to gather the target info JSON. --- CMakeLists.txt | 10 +------ cmake/modules/SwiftSupport.cmake | 51 ++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbc4aeb36..56af381e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,15 +308,7 @@ add_compile_definitions($<$:HAVE_CONFIG_H>) if(ENABLE_SWIFT) include(SwiftSupport) - if(NOT SWIFT_SYSTEM_NAME) - if(APPLE) - set(SWIFT_SYSTEM_NAME macosx) - else() - set(SWIFT_SYSTEM_NAME "$") - endif() - endif() - - set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}/${dispatch_Swift_ARCH}" CACHE PATH "Path where the libraries will be installed") + set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${dispatch_Swift_PLATFORM}/${dispatch_Swift_ARCH}" CACHE PATH "Path where the libraries will be installed") set(INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch") set(INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime") set(INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/os" CACHE PATH "Path where the os/ headers will be installed") diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 6c6911f63..67a891879 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -1,60 +1,67 @@ include_guard() -if(NOT dispatch_MODULE_TRIPLE) +if(NOT dispatch_Swift_MODULE_TRIPLE OR NOT dispatch_Swift_ARCH OR NOT dispatch_Swift_SYSTEM) + # Get the target information from the Swift compiler. set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) if(CMAKE_Swift_COMPILER_TARGET) list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET}) endif() execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json) +endif() +if(NOT dispatch_Swift_MODULE_TRIPLE) string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple") - set(dispatch_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files") - mark_as_advanced(dispatch_MODULE_TRIPLE) - + set(dispatch_Swift_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files") + mark_as_advanced(dispatch_Swift_MODULE_TRIPLE) message(CONFIGURE_LOG "Swift module triple: ${module_triple}") endif() if(NOT dispatch_Swift_ARCH) if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) # For newer compilers, we can use the -print-target-info command to get the architecture. - set(module_arch_command "${CMAKE_Swift_COMPILER}" -print-target-info) - if(CMAKE_Swift_COMPILER_TARGET) - list(APPEND module_arch_command -target ${CMAKE_Swift_COMPILER_TARGET}) - endif() - execute_process(COMMAND ${module_arch_command} OUTPUT_VARIABLE target_info_json) string(JSON module_arch GET "${target_info_json}" "target" "arch") else() - # For older compilers, extract the value from `dispatch_MODULE_TRIPLE`. - string(REGEX MATCH "^[^-]+" module_arch "${dispatch_MODULE_TRIPLE}") + # For older compilers, extract the value from `dispatch_Swift_MODULE_TRIPLE`. + string(REGEX MATCH "^[^-]+" module_arch "${dispatch_Swift_MODULE_TRIPLE}") endif() set(dispatch_Swift_ARCH "${module_arch}" CACHE STRING "Arch folder name used to install libraries") mark_as_advanced(dispatch_Swift_ARCH) - message(CONFIGURE_LOG "Swift arch: ${dispatch_Swift_ARCH}") endif() +if(NOT dispatch_Swift_PLATFORM) + if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) + # For newer compilers, we can use the -print-target-info command to get the platform. + string(JSON swift_platform GET "${target_info_json}" "target" "platform") + else() + # For older compilers, compile the value from `CMAKE_SYSTEM_NAME`. + if(APPLE) + set(swift_platform macosx) + else() + set(swift_platform "$") + endif() + endif() + + set(dispatch_Swift_PLATFORM "${swift_platform}" CACHE STRING "Platform folder name used to install libraries") + mark_as_advanced(dispatch_Swift_PLATFORM) + message(CONFIGURE_LOG "Swift platform: ${dispatch_Swift_PLATFORM}") +endif() + function(install_swift_module target) get_target_property(module ${target} Swift_MODULE_NAME) if(NOT module) set(module ${target}) endif() - if(NOT SWIFT_SYSTEM_NAME) - if(APPLE) - set(SWIFT_SYSTEM_NAME macosx) - else() - set(SWIFT_SYSTEM_NAME "$") - endif() - endif() - set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}" CACHE PATH "Path where the swift modules will be installed") + set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${dispatch_Swift_PLATFORM}" CACHE PATH "Path where the swift modules will be installed") install( FILES $/${module}.swiftdoc DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule - RENAME ${dispatch_MODULE_TRIPLE}.swiftdoc) + RENAME ${dispatch_Swift_MODULE_TRIPLE}.swiftdoc) install( FILES $/${module}.swiftmodule DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule - RENAME ${dispatch_MODULE_TRIPLE}.swiftmodule) + RENAME ${dispatch_Swift_MODULE_TRIPLE}.swiftmodule) endfunction() From a0def02d741bdcffc3eb07091f4058f979df7221 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Tue, 5 Aug 2025 16:54:11 -0700 Subject: [PATCH 4/6] Use the right variable name --- cmake/modules/SwiftSupport.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 67a891879..4704758f7 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -1,6 +1,6 @@ include_guard() -if(NOT dispatch_Swift_MODULE_TRIPLE OR NOT dispatch_Swift_ARCH OR NOT dispatch_Swift_SYSTEM) +if(NOT dispatch_Swift_MODULE_TRIPLE OR NOT dispatch_Swift_ARCH OR NOT dispatch_Swift_PLATFORM) # Get the target information from the Swift compiler. set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) if(CMAKE_Swift_COMPILER_TARGET) From f51e4816218e04e4dc37eb9fa56bce7ee00e2c36 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Wed, 6 Aug 2025 09:55:55 -0700 Subject: [PATCH 5/6] Rename `dispatch_Swift_*` to `dispatch_*` --- CMakeLists.txt | 2 +- cmake/modules/SwiftSupport.cmake | 34 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56af381e8..38cc7c547 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,7 @@ add_compile_definitions($<$:HAVE_CONFIG_H>) if(ENABLE_SWIFT) include(SwiftSupport) - set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${dispatch_Swift_PLATFORM}/${dispatch_Swift_ARCH}" CACHE PATH "Path where the libraries will be installed") + set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${dispatch_PLATFORM}/${dispatch_ARCH}" CACHE PATH "Path where the libraries will be installed") set(INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch") set(INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime") set(INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/os" CACHE PATH "Path where the os/ headers will be installed") diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 4704758f7..697d98516 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -1,6 +1,6 @@ include_guard() -if(NOT dispatch_Swift_MODULE_TRIPLE OR NOT dispatch_Swift_ARCH OR NOT dispatch_Swift_PLATFORM) +if(NOT dispatch_MODULE_TRIPLE OR NOT dispatch_ARCH OR NOT dispatch_PLATFORM) # Get the target information from the Swift compiler. set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info) if(CMAKE_Swift_COMPILER_TARGET) @@ -9,28 +9,28 @@ if(NOT dispatch_Swift_MODULE_TRIPLE OR NOT dispatch_Swift_ARCH OR NOT dispatch_S execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json) endif() -if(NOT dispatch_Swift_MODULE_TRIPLE) +if(NOT dispatch_MODULE_TRIPLE) string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple") - set(dispatch_Swift_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files") - mark_as_advanced(dispatch_Swift_MODULE_TRIPLE) + set(dispatch_MODULE_TRIPLE "${module_triple}" CACHE STRING "Triple used to install swiftmodule files") + mark_as_advanced(dispatch_MODULE_TRIPLE) message(CONFIGURE_LOG "Swift module triple: ${module_triple}") endif() -if(NOT dispatch_Swift_ARCH) +if(NOT dispatch_ARCH) if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) # For newer compilers, we can use the -print-target-info command to get the architecture. string(JSON module_arch GET "${target_info_json}" "target" "arch") else() - # For older compilers, extract the value from `dispatch_Swift_MODULE_TRIPLE`. - string(REGEX MATCH "^[^-]+" module_arch "${dispatch_Swift_MODULE_TRIPLE}") + # For older compilers, extract the value from `dispatch_MODULE_TRIPLE`. + string(REGEX MATCH "^[^-]+" module_arch "${dispatch_MODULE_TRIPLE}") endif() - set(dispatch_Swift_ARCH "${module_arch}" CACHE STRING "Arch folder name used to install libraries") - mark_as_advanced(dispatch_Swift_ARCH) - message(CONFIGURE_LOG "Swift arch: ${dispatch_Swift_ARCH}") + set(dispatch_ARCH "${module_arch}" CACHE STRING "Arch folder name used to install libraries") + mark_as_advanced(dispatch_ARCH) + message(CONFIGURE_LOG "Swift arch: ${dispatch_ARCH}") endif() -if(NOT dispatch_Swift_PLATFORM) +if(NOT dispatch_PLATFORM) if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2) # For newer compilers, we can use the -print-target-info command to get the platform. string(JSON swift_platform GET "${target_info_json}" "target" "platform") @@ -43,9 +43,9 @@ if(NOT dispatch_Swift_PLATFORM) endif() endif() - set(dispatch_Swift_PLATFORM "${swift_platform}" CACHE STRING "Platform folder name used to install libraries") - mark_as_advanced(dispatch_Swift_PLATFORM) - message(CONFIGURE_LOG "Swift platform: ${dispatch_Swift_PLATFORM}") + set(dispatch_PLATFORM "${swift_platform}" CACHE STRING "Platform folder name used to install libraries") + mark_as_advanced(dispatch_PLATFORM) + message(CONFIGURE_LOG "Swift platform: ${dispatch_PLATFORM}") endif() function(install_swift_module target) @@ -54,14 +54,14 @@ function(install_swift_module target) set(module ${target}) endif() - set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${dispatch_Swift_PLATFORM}" CACHE PATH "Path where the swift modules will be installed") + set(INSTALL_SWIFT_MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${dispatch_PLATFORM}" CACHE PATH "Path where the swift modules will be installed") install( FILES $/${module}.swiftdoc DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule - RENAME ${dispatch_Swift_MODULE_TRIPLE}.swiftdoc) + RENAME ${dispatch_MODULE_TRIPLE}.swiftdoc) install( FILES $/${module}.swiftmodule DESTINATION ${INSTALL_SWIFT_MODULE_DIR}/${module}.swiftmodule - RENAME ${dispatch_Swift_MODULE_TRIPLE}.swiftmodule) + RENAME ${dispatch_MODULE_TRIPLE}.swiftmodule) endfunction() From 0fcef7dca474b6c20a4caacf6d284da90ccb691b Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Wed, 6 Aug 2025 13:28:56 -0700 Subject: [PATCH 6/6] Add option to install into an arch-subdir --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38cc7c547..c34b0de6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,8 +307,9 @@ add_compile_definitions($<$:HAVE_CONFIG_H>) if(ENABLE_SWIFT) include(SwiftSupport) + option(dispatch_INSTALL_ARCH_SUBDIR "Install libraries under an architecture subdirectory" NO) - set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${dispatch_PLATFORM}/${dispatch_ARCH}" CACHE PATH "Path where the libraries will be installed") + set(INSTALL_TARGET_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/${dispatch_PLATFORM}$<$:/${dispatch_ARCH}>" CACHE PATH "Path where the libraries will be installed") set(INSTALL_DISPATCH_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/dispatch" CACHE PATH "Path where the headers will be installed for libdispatch") set(INSTALL_BLOCK_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/Block" CACHE PATH "Path where the headers will be installed for the blocks runtime") set(INSTALL_OS_HEADERS_DIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>/os" CACHE PATH "Path where the os/ headers will be installed")