Skip to content

Commit 21e3042

Browse files
committed
Non-Darwin SDKs product results in per-arch directories (CMake)
Unix (other than Darwin) and Windows do not support fat binaries. However, the build system was placing the build results in the platform/OS folder, instead of the per-architecture folder. Having two architectures side by side was impossible. After applying the above patch in the Swift compiler, non-Darwin platforms will look into the per-architecture folders, so the sibling projects need to leave the products in the right place.
1 parent 74eb084 commit 21e3042

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,24 @@ if(ENABLE_TESTING)
408408
LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
409409
endif()
410410

411+
get_swift_host_arch(SWIFT_HOST_ARCH)
412+
411413
install(FILES
412414
${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftdoc
413415
${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftmodule
414416
DESTINATION
415-
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
417+
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${CMAKE_SYSTEM_NAME}/${SWIFT_HOST_ARCH})
416418
install(FILES
417419
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}Foundation${CMAKE_SHARED_LIBRARY_SUFFIX}
418420
DESTINATION
419421
${CMAKE_INSTALL_FULL_LIBDIR})
422+
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
423+
install(FILES
424+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}Foundation${CMAKE_SHARED_LIBRARY_SUFFIX}
425+
DESTINATION
426+
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${CMAKE_SYSTEM_NAME}/${SWIFT_HOST_ARCH})
427+
endif()
420428
install(FILES
421429
${CMAKE_CURRENT_BINARY_DIR}/plutil
422430
DESTINATION
423431
${CMAKE_INSTALL_FULL_BINDIR})
424-

cmake/modules/SwiftSupport.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,35 @@ function(add_swift_executable executable)
152152
add_swift_target(${executable} ${ARGN})
153153
endfunction()
154154

155+
# Returns the current achitecture name in a variable
156+
#
157+
# Usage:
158+
# get_swift_host_arch(result_var_name)
159+
#
160+
# If the current architecture is supported by Swift, sets ${result_var_name}
161+
# with the sanitized host architecture name derived from CMAKE_SYSTEM_PROCESSOR.
162+
function(get_swift_host_arch result_var_name)
163+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
164+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
165+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
166+
set("${result_var_name}" "aarch64" PARENT_SCOPE)
167+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
168+
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
169+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
170+
set("${result_var_name}" "powerpc64le" PARENT_SCOPE)
171+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
172+
set("${result_var_name}" "s390x" PARENT_SCOPE)
173+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l")
174+
set("${result_var_name}" "armv6" PARENT_SCOPE)
175+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
176+
set("${result_var_name}" "armv7" PARENT_SCOPE)
177+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
178+
set("${result_var_name}" "x86_64" PARENT_SCOPE)
179+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
180+
set("${result_var_name}" "itanium" PARENT_SCOPE)
181+
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
182+
set("${result_var_name}" "i686" PARENT_SCOPE)
183+
else()
184+
message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}")
185+
endif()
186+
endfunction()

0 commit comments

Comments
 (0)